feat(biz): 实现楼宇数据定时同步功能
- 新增阿里巴巴楼宇数据定时任务类 AlibabaBuildingJob - 实现楼宇数据批量保存接口 saveBatch - 添加楼宇实体状态字段及对应逻辑处理 - 完善楼宇数据转换器 LcBuildingEntityConvert - 提供根据楼宇编号查询方法 selectByBuildingId - 设置分页参数默认值以适应大数据量场景 - 增加租户任务注解支持多租户环境执行 - 日志记录保存结果和数据条数信息
This commit is contained in:
@@ -34,11 +34,11 @@ public interface LcBuildingEntityConvert {
|
||||
LcBuildingEntity convert(PowerEnvBuildingItemDTO bean);
|
||||
|
||||
/**
|
||||
* 将 LcBuildingEntity 列表转换为 PowerEnvBuildingItemDTO 列表
|
||||
* 将 PowerEnvBuildingItemDTO 列表转换为 LcBuildingEntity 列表
|
||||
*
|
||||
* @param list 实体对象列表
|
||||
* @return DTO对象列表
|
||||
* @param list DTO对象列表
|
||||
* @return 列表
|
||||
*/
|
||||
List<PowerEnvBuildingItemDTO> convertList(List<LcBuildingEntity> list);
|
||||
List<LcBuildingEntity> convertList(List<PowerEnvBuildingItemDTO> list);
|
||||
|
||||
}
|
||||
@@ -18,13 +18,13 @@ public class PowerEnvBuildingParamsDTO {
|
||||
* 每页数量
|
||||
*/
|
||||
@Schema(description = "每页数量")
|
||||
private String pageSize;
|
||||
private String pageSize = "1000";
|
||||
|
||||
/**
|
||||
* 页码
|
||||
*/
|
||||
@Schema(description = "页码")
|
||||
private String page;
|
||||
private String page = "1";
|
||||
|
||||
/**
|
||||
* 园区编号
|
||||
|
||||
@@ -46,4 +46,9 @@ public class LcBuildingEntity extends BaseTenantEntity {
|
||||
*/
|
||||
private String campusName;
|
||||
|
||||
/**
|
||||
* 状态(0:停用,1:启用)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
package com.jeelowcode.module.biz.job;
|
||||
|
||||
import com.jeelowcode.module.biz.convert.LcBuildingEntityConvert;
|
||||
import com.jeelowcode.module.biz.dto.PowerEnvBuildingItemDTO;
|
||||
import com.jeelowcode.module.biz.dto.PowerEnvBuildingParamsDTO;
|
||||
import com.jeelowcode.module.biz.dto.PowerEnvPageDataDTO;
|
||||
import com.jeelowcode.module.biz.entity.LcBuildingEntity;
|
||||
import com.jeelowcode.module.biz.service.IBizHttpClientService;
|
||||
import com.jeelowcode.module.biz.service.ILcBuildingService;
|
||||
import com.jeelowcode.tool.framework.quartz.core.handler.JobHandler;
|
||||
import com.jeelowcode.tool.framework.tenant.core.job.TenantJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备指标数据定时任务
|
||||
*
|
||||
@@ -15,10 +26,31 @@ import org.springframework.stereotype.Component;
|
||||
@ConditionalOnProperty(name = "jeelowcode.powerenv.baseurl")
|
||||
public class AlibabaBuildingJob implements JobHandler {
|
||||
|
||||
/**
|
||||
* 动环设备服务
|
||||
*/
|
||||
@Resource
|
||||
private ILcBuildingService buildingService;
|
||||
|
||||
/**
|
||||
* 动环设备服务
|
||||
*/
|
||||
@Resource
|
||||
private IBizHttpClientService httpClientService;
|
||||
|
||||
@Override
|
||||
@TenantJob
|
||||
public String execute(String param) throws Exception {
|
||||
return "";
|
||||
// 分页接口,但是pageSize默认设置1000,应该不会超过1000,所以这里就不分页了
|
||||
PowerEnvPageDataDTO<PowerEnvBuildingItemDTO> pageData =
|
||||
httpClientService.listBuilding(new PowerEnvBuildingParamsDTO());
|
||||
// 转化数据
|
||||
List<LcBuildingEntity> list = LcBuildingEntityConvert.INSTANCE.convertList(pageData.getItems());
|
||||
// 批量保存数据
|
||||
int result = buildingService.saveBatch(list);
|
||||
log.info("保存楼宇数据结果:{}", result);
|
||||
log.info("保存楼宇数据结果:{}", result == list.size());
|
||||
return "保存楼宇数据结果:" + result + ",楼宇数据大小:" + list.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.jeelowcode.module.biz.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.jeelowcode.module.biz.entity.LcBuildingEntity;
|
||||
import com.jeelowcode.tool.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
@@ -12,4 +13,15 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface LcBuildingMapper extends BaseMapper<LcBuildingEntity> {
|
||||
|
||||
/**
|
||||
* 根据楼宇编号查询楼宇信息
|
||||
*
|
||||
* @param buildingId 楼宇编号
|
||||
* @return 楼宇信息实体对象,如果未找到则返回null
|
||||
*/
|
||||
default LcBuildingEntity selectByBuildingId(String buildingId) {
|
||||
return selectOne(new LambdaQueryWrapperX<LcBuildingEntity>()
|
||||
.eq(LcBuildingEntity::getBuildingId, buildingId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.jeelowcode.module.biz.service;
|
||||
|
||||
import com.jeelowcode.module.biz.entity.LcBuildingEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 楼宇点位信息服务接口
|
||||
*
|
||||
@@ -7,4 +11,12 @@ package com.jeelowcode.module.biz.service;
|
||||
*/
|
||||
public interface ILcBuildingService {
|
||||
|
||||
/**
|
||||
* 批量保存
|
||||
*
|
||||
* @param list 数据列表
|
||||
* @return 影响行数
|
||||
*/
|
||||
int saveBatch(List<LcBuildingEntity> list);
|
||||
|
||||
}
|
||||
@@ -1,9 +1,17 @@
|
||||
package com.jeelowcode.module.biz.service.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.jeelowcode.module.biz.entity.LcBuildingEntity;
|
||||
import com.jeelowcode.module.biz.mapper.LcBuildingMapper;
|
||||
import com.jeelowcode.module.biz.service.ILcBuildingService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 楼宇点位信息服务实现类
|
||||
*
|
||||
@@ -13,4 +21,21 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class LcBuildingServiceImpl implements ILcBuildingService {
|
||||
|
||||
@Resource
|
||||
private LcBuildingMapper baseMapper;
|
||||
|
||||
@Override
|
||||
public int saveBatch(List<LcBuildingEntity> list) {
|
||||
return list.parallelStream().map(building -> {
|
||||
if (StrUtil.isEmpty(building.getBuildingId())) return 0;
|
||||
LcBuildingEntity buildingEntity =
|
||||
baseMapper.selectByBuildingId(building.getBuildingId());
|
||||
return Optional.ofNullable(buildingEntity)
|
||||
.map(entity -> {
|
||||
building.setId(entity.getId());
|
||||
return baseMapper.updateById(building);
|
||||
}).orElseGet(() -> baseMapper.insert(building));
|
||||
}).mapToInt(Convert::toInt).sum();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user