feat(能源): 定时任务分类

master
黄锦贤 12 hours ago
parent da8ff569af
commit 190e09a857

@ -24,15 +24,6 @@ public interface RemoteEnergyService {
@PostMapping("/buildInfo/removeDatasource")
public R removeDatasource(@RequestBody DataSourcePropertyDTO dataSourceProperty);
@PostMapping(value = "/record/dnbInstant/getNhEnergy")
public R SyncNhEnergy();
@PostMapping(value = "/record/dnbInstant/getNhEnergyDetail")
public R SyncNhEnergyDetail(@RequestHeader Map<String, String> header);
@PostMapping(value = "/record/dnbInstant/fixWwEnergyData")
public R syncFixWwEnergyData(@RequestBody Map<String, String> map, @RequestHeader Map<String, String> header);
@PostMapping(value = "/report/dayDnb/genDailyEnergyData")
public AjaxResult genDalyEnergyData(@RequestBody Map<String, String> map, @RequestHeader Map<String, String> header);
}

@ -30,21 +30,6 @@ public class RemoteEnergyFallbackFactory implements FallbackFactory<RemoteEnergy
return R.fail("mes数据源删除失败:" + throwable.getMessage());
}
@Override
public R SyncNhEnergy() {
return R.fail("同步整点数据失败:" + throwable.getMessage());
}
@Override
public R SyncNhEnergyDetail(Map<String, String> header) {
return R.fail("同步电表实时数据失败:" + throwable.getMessage());
}
@Override
public R syncFixWwEnergyData(Map<String ,String> map, Map<String,String> header) {
return R.fail("修正威伟电表数据失败:" + throwable.getMessage());
}
@Override
public AjaxResult genDalyEnergyData(Map<String, String> map, Map<String, String> header) {
return AjaxResult.error("生成日报表数据失败:" + throwable.getMessage());

@ -190,27 +190,6 @@ public class RecordDnbInstantController extends BaseController {
return AjaxResult.success(recordDnbInstantService.voltageCurrentCurve(baseDnbInstant));
}
/**
*
**/
@PostMapping("/getNhEnergyDetail")
@ResponseBody
public AjaxResult getNhEnergyDetail() {
recordDnbInstantService.getNhEnergyDetail();
return AjaxResult.success();
}
/**
*
**/
@PostMapping("/getNhEnergy")
@ResponseBody
public AjaxResult getNhEnergy() {
recordDnbInstantService.getNhEnergy();
return AjaxResult.success();
}
/**
*
**/
@ -221,14 +200,4 @@ public class RecordDnbInstantController extends BaseController {
ExcelUtil<RecordDnbInstant> util = new ExcelUtil<RecordDnbInstant>(RecordDnbInstant.class);
util.exportExcel(response, list, "导出");
}
/**
*
**/
@PostMapping("/fixWwEnergyData")
@ResponseBody
public AjaxResult fixWwEnergyData(@RequestBody Map<String, String> params) {
recordDnbInstantService.fixWwEnergyData(params);
return AjaxResult.success();
}
}

@ -88,11 +88,5 @@ public interface IRecordDnbInstantService {
List<RecordDnbInstant> voltageCurrentCurve(RecordDnbInstant baseDnbInstant);
void getNhEnergyDetail();
void getNhEnergy();
List<RecordDnbInstant> testGetNhEnergyDetail(Map<String,String> params);
void fixWwEnergyData(Map<String,String> params);
}

@ -253,155 +253,6 @@ public class RecordDnbInstantServiceImpl implements IRecordDnbInstantService {
return recordDnbInstantMapper.selectRecordDnbInstantList(dnbInstant);
}
@Override
@DS("#header.poolName")
public void getNhEnergyDetail() {
Map<String, String> params = new HashMap<>();
params.put("dateType", "mi15");
Date nowTime = DateUtils.getNowDate();
String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addMinutes(nowTime, -20));
String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addMinutes(nowTime, -10));
params.put("startTime", startTime);
params.put("endTime", endTime);
// params.put("startTime","2025-07-30 13:40:00");
// params.put("endTime","2025-07-30 13:50:00");
params.put("valueType", "SJZ");
/**
* /
* **/
AjaxResult voltageRes = remoteOpenService.getVoltageCurrent(params);
List<RecordDnbInstant> list = new ArrayList<>();
if (voltageRes.isSuccess()) {
JSONObject resData = JSONObject.parseObject(JSON.toJSONString(voltageRes.get(AjaxResult.DATA_TAG)));
JSONArray array = JSONArray.parseArray(resData.get("Data").toString());
for (int i = 0; i < array.size(); i++) {
RecordDnbInstant instant = new RecordDnbInstant();
instant.setVA(getSafeBigDecimal(array.getJSONObject(i), "ADY"));
instant.setVB(getSafeBigDecimal(array.getJSONObject(i), "BDY"));
instant.setVC(getSafeBigDecimal(array.getJSONObject(i), "CDY"));
instant.setIA(getSafeBigDecimal(array.getJSONObject(i), "ADL"));
instant.setIB(getSafeBigDecimal(array.getJSONObject(i), "BDL"));
instant.setIC(getSafeBigDecimal(array.getJSONObject(i), "CDL"));
instant.setMonitorId(array.getJSONObject(i).getString("Address"));
instant.setRecordTime(nowTime);
instant.setCollectTime(DateUtils.dateTime("yyyy-MM-dd HH:mm", array.getJSONObject(i).getString("ReadingDate")));
list.add(instant);
}
}
/**
*
* **/
AjaxResult electricPowerRes = remoteOpenService.getElectricPower(params);
if (electricPowerRes.isSuccess()) {
JSONObject resData = JSONObject.parseObject(JSON.toJSONString(electricPowerRes.get(AjaxResult.DATA_TAG)));
JSONArray array = JSONArray.parseArray(resData.get("Data").toString());
for (int i = 0; i < array.size(); i++) {
for (RecordDnbInstant item : list) {
String address = array.getJSONObject(i).getString("Address");
if (address.equals(item.getMonitorId())) {
item.setGlys(getSafeBigDecimal(array.getJSONObject(i), "GLYS"));
item.setActivePower(getSafeBigDecimal(array.getJSONObject(i), "YGGL"));
item.setReactivePower(getSafeBigDecimal(array.getJSONObject(i), "WGGL"));
}
}
}
}
/**
*
* **/
AjaxResult electricQuantityRes = remoteOpenService.getElectricQuantity(params);
if (electricQuantityRes.isSuccess()) {
JSONObject resData = JSONObject.parseObject(JSON.toJSONString(electricQuantityRes.get(AjaxResult.DATA_TAG)));
JSONArray array = JSONArray.parseArray(resData.get("Data").toString());
for (int i = 0; i < array.size(); i++) {
for (RecordDnbInstant item : list) {
String address = array.getJSONObject(i).getString("Address");
if (address.equals(item.getMonitorId())) {
item.setZxyg(getSafeBigDecimal(array.getJSONObject(i), "ZYGDNSZ"));
item.setReactivePower(getSafeBigDecimal(array.getJSONObject(i), "ZYGDN"));
}
}
}
}
for (RecordDnbInstant item : list) {
BaseMonitorInfo temp = new BaseMonitorInfo();
temp.setAddressCode(item.getMonitorId());
List<BaseMonitorInfo> baseList = baseMonitorInfoMapper.selectBaseMonitorInfoList(temp);
for (BaseMonitorInfo base : baseList) {
item.setMonitorId(base.getMonitorId());
recordDnbInstantMapper.insertRecordDnbInstant(item);
}
}
}
@Override
public void getNhEnergy() {
Map<String, String> params = new HashMap<>();
params.put("dateType", "mi15");
//获取当前时间的前后5分钟
Date nowDate = DateUtils.getNowDate();
//取整点数据
String nowDateStr = DateUtils.parseDateToStr("yyyy-MM-dd HH", nowDate) + ":00:00";
String startTime = DateUtils.parseDateToStr("yyyy-MM-dd HH", DateUtils.addHours(nowDate, -1)) + ":00:00";
params.put("startTime", startTime);
params.put("endTime", nowDateStr);
params.put("valueType", "SJZ");
/**
*
* **/
List<ReportPointDnb> list = new ArrayList<>();
AjaxResult electricQuantityRes = remoteOpenService.getElectricQuantity(params);
if (electricQuantityRes.isSuccess()) {
JSONObject resData = JSONObject.parseObject(JSON.toJSONString(electricQuantityRes.get(AjaxResult.DATA_TAG)));
JSONArray array = JSONArray.parseArray(resData.get("Data").toString());
//根据Address分类
List<String> addressList = new ArrayList<>();
for (int i = 0; i < array.size(); i++) {
addressList.add(array.getJSONObject(i).getString("Address"));
}
//addressList去重
addressList = addressList.stream().distinct().collect(Collectors.toList());
DynamicDataSourceContextHolder.push("ds_1000");
try {
for (String address : addressList) {
ReportPointDnb dnb = new ReportPointDnb();
BigDecimal electricQuantity = BigDecimal.ZERO;
for (int i = 0; i < array.size(); i++) {
if (address.equals(array.getJSONObject(i).getString("Address"))) {
electricQuantity = electricQuantity.add(getSafeBigDecimal(array.getJSONObject(i), "ZYGDN"));
}
}
dnb.setMeterValue(array.getJSONObject(0).getBigDecimal("ZYGDNSZ"));
dnb.setExpend(electricQuantity);
dnb.setMonitorId(address);
dnb.setBeginTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime));
dnb.setEndTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, nowDateStr));
dnb.setRecordTime(new Date());
dnb.setPointTime(removeLeadingZeros(DateUtils.parseDateToStr("HH", DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime))));
BaseMonitorInfo temp = new BaseMonitorInfo();
temp.setConnCode(dnb.getMonitorId());
List<BaseMonitorInfo> BaseList = baseMonitorInfoMapper.selectBaseMonitorInfoList(temp);
for (BaseMonitorInfo base : BaseList) {
dnb.setMonitorId(base.getMonitorId());
reportPointDnbMapper.insertReportPointDnb(dnb);
}
}
} finally {
DynamicDataSourceContextHolder.poll();
}
}
}
/**
* 0
**/
@ -480,19 +331,4 @@ public class RecordDnbInstantServiceImpl implements IRecordDnbInstantService {
return list;
}
@Override
@DS("#header.poolName")
public void fixWwEnergyData(Map<String, String> params) {
//获取威伟电表
BaseMonitorInfo query = new BaseMonitorInfo();
query.setElectricityMeterType("2");
List<BaseMonitorInfo> list = baseMonitorInfoMapper.selectBaseMonitorInfoList(query);
for (BaseMonitorInfo info : list) {
params.put("monitorId", info.getMonitorId());
reportPointDnbMapper.fixWwEnergyData(params);
}
}
}

@ -95,8 +95,6 @@ public interface ReportPointDnbMapper {
List<Map<String, String>> datePointDnbGroupList(ReportPointDnb lineDnb);
Integer fixWwEnergyData(@Param("params") Map<String,String> params);
int batchInsertReportPointDnb(@Param("list") List<ReportPointDnb> list);
/**

@ -534,46 +534,6 @@
order by ert.pointTime asc
</select>
<select id="fixWwEnergyData" resultType="Integer" parameterType="java.util.Map" >
UPDATE a
SET expend = b.expend
FROM report_point_dnb a
INNER JOIN (
SELECT objId, expend
FROM (
SELECT
a.objId,
(a.meter_value - ISNULL( LAG ( a.meter_value, 1 ) OVER ( PARTITION BY a.monitor_id ORDER BY a.record_time ), 0 )) * ISNULL(b.ct, 1) AS expend,
ROW_NUMBER ( ) OVER ( ORDER BY a.record_time ) AS row_num
FROM report_point_dnb a
LEFT JOIN base_monitor_info b ON a.monitor_id = b.monitor_id
WHERE DATEPART( MINUTE, a.record_time ) = 0
AND DATEPART( SECOND, a.record_time ) = 0
<if test="params.beginDate != null and params.beginDate != ''">
AND CONVERT ( VARCHAR, a.record_time, 23 ) >= #{params.beginDate}
AND CONVERT ( VARCHAR, a.record_time, 23 ) <![CDATA[ <= ]]> #{params.endDate}
</if>
<if test="params.beginDate == null || params.beginDate == ''">
AND CONVERT ( VARCHAR, a.record_time, 23 ) >= CONVERT(varchar, DATEADD(day, -2, GETDATE()), 23)
</if>
AND a.monitor_id = #{params.monitorId}
) n
WHERE row_num != 1
) b ON a.objid = b.objId
WHERE a.objid IN (
SELECT objId
FROM report_point_dnb
WHERE monitor_id = #{params.monitorId}
<if test="params.beginDate != null and params.beginDate != ''">
AND CONVERT ( VARCHAR, record_time, 23 ) >= #{params.beginDate}
AND CONVERT ( VARCHAR, record_time, 23 ) <![CDATA[ <= ]]> #{params.endDate}
</if>
<if test="params.beginDate == null || params.beginDate == ''">
AND CONVERT ( VARCHAR, record_time, 23 ) >= CONVERT(varchar, DATEADD(day, -2, GETDATE()), 23)
</if>
)
</select>
<select id="listAllReportPointDnbByTime" resultMap="ReportPointDnbResult">
select * from report_point_dnb rt
<where>

@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.op.common.security.annotation.EnableCustomConfig;
import com.op.common.security.annotation.EnableRyFeignClients;
import com.op.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
*

@ -0,0 +1,51 @@
package com.op.job.task;
import com.op.common.core.utils.StringUtils;
import com.op.job.util.MultiDbFeignExecutor;
import com.op.system.api.RemoteEnergyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
/**
* Description:
*
* @author : huangjinxian
* @version : 1.0
* @since : 2026/6/24
*/
@SuppressWarnings({"JavadocDeclaration", "unused", "SpellCheckingInspection", "SpringJavaInjectionPointsAutowiringInspection"})
@Component("EnergyTask")
@Slf4j
@RequiredArgsConstructor
public class EnergyTask {
final MultiDbFeignExecutor multiDbFeignExecutor;
final RemoteEnergyService remoteEnergyService;
/**
*
*
* @param beginDate
* @param endDate
* @auther huangjinxian
* @version 1.0
*/
public void genDalyEnergyData(String beginDate, String endDate) {
log.info("------ 生成软控电表日报数据 start:{} ------", System.currentTimeMillis());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate last = LocalDate.now().plusDays(-7);
LocalDate now = LocalDate.now();
multiDbFeignExecutor.execute("genDalyEnergyData", dbHeader -> {
Map<String, String> map = new HashMap<>();
map.put("beginDate", (StringUtils.isNotEmpty(beginDate) ? beginDate : last.format(formatter)) + " 00:00:00");
map.put("endDate", (StringUtils.isNotEmpty(endDate) ? endDate : now.format(formatter)) + " 23:59:59");
remoteEnergyService.genDalyEnergyData(map, dbHeader);
});
log.info("------ 生成软控电表日报数据 end:{} ------", System.currentTimeMillis());
}
}

@ -44,8 +44,6 @@ public class RyTask {
private RemoteUserService remoteUserService;
@Autowired
private RemoteWmsService remoteWmsService;
@Autowired
private RemoteEnergyService remoteEnergyService;
@Autowired
private MultiDbFeignExecutor multiDbFeignExecutor;
@ -303,28 +301,6 @@ public class RyTask {
remoteMesService.updateEquRunTime();
}
/**********同步电整点数据*********/
public void SyncNhEnergy() {
logger.info("++同步电整点数据+开始++getNhEnergy+++++");
remoteEnergyService.SyncNhEnergy();
}
/**********同步电实时数据*********/
public void SyncNhEnergyDetail() {
logger.info("++同步电实时数据+开始++getNhEnergyDetail+++++");
multiDbFeignExecutor.execute("syncFixWwEnergyData", dbHeader -> {
try {
//每个数据库线程休眠1到5秒防止威伟电表接口限流
int randomMills = ThreadLocalRandom.current().nextInt(1000, 5001);
Thread.sleep(randomMills);
remoteEnergyService.SyncNhEnergyDetail(dbHeader);
} catch (Exception e) {
log.info("任务执行出错");
}
});
}
/**********同步新hr系统的出勤记录*********/
public void syncHrAttendance() {
logger.info("+++开始同步新hr系统的出勤记录++syncHrAttendance+++++");
@ -344,43 +320,5 @@ public class RyTask {
logger.info("+++留样复检任务提醒++syncSendSampleCheckRemind+++++");
remoteQualityService.syncSendSampleCheckRemind();
}
/**********修正威伟电表数据(有参)*********/
public void syncFixWwEnergyData(String beginDate, String endDate) {
logger.info("+++修正威伟电表数据(有参)++syncFixWwEnergyData+++++");
multiDbFeignExecutor.execute("syncFixWwEnergyData", dbHeader -> {
Map<String, String> map = new HashMap<>();
map.put("beginDate", beginDate);
map.put("endDate", endDate);
remoteEnergyService.syncFixWwEnergyData(map, dbHeader);
});
}
/**
* ()
**/
public void syncFixWwEnergyData() {
logger.info("+++修正威伟电表数据(无参)++syncFixWwEnergyData+++++");
multiDbFeignExecutor.execute("syncFixWwEnergyData", dbHeader -> {
Map<String, String> map = new HashMap<>();
map.put("beginDate", "");
map.put("endDate", "");
remoteEnergyService.syncFixWwEnergyData(map, dbHeader);
});
}
public void genDalyEnergyData(String beginDate, String endDate) {
logger.info("------ 生成软控电表日报数据 start:{} ------", System.currentTimeMillis());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate last = LocalDate.now().plusDays(-7);
LocalDate now = LocalDate.now();
multiDbFeignExecutor.execute("genDalyEnergyData", dbHeader -> {
Map<String, String> map = new HashMap<>();
map.put("beginDate", (StringUtils.isNotEmpty(beginDate) ? beginDate : last.format(formatter)) + " 00:00:00");
map.put("endDate", (StringUtils.isNotEmpty(endDate) ? endDate : now.format(formatter)) + " 23:59:59");
remoteEnergyService.genDalyEnergyData(map, dbHeader);
});
logger.info("------ 生成软控电表日报数据 end:{} ------", System.currentTimeMillis());
}
}

Loading…
Cancel
Save