|
|
|
|
@ -4,13 +4,16 @@ |
|
|
|
|
package org.springblade.desk.quality.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import jakarta.annotation.Resource; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.Data; |
|
|
|
|
import lombok.EqualsAndHashCode; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.desk.basic.constant.BaseCol; |
|
|
|
|
import org.springblade.desk.quality.excel.IotHardnessExcel; |
|
|
|
|
import org.springblade.desk.quality.mapper.IotHardnessMapper; |
|
|
|
|
import org.springblade.desk.quality.pojo.entity.IotHardness; |
|
|
|
|
@ -18,8 +21,11 @@ import org.springblade.desk.quality.pojo.vo.IotHardnessVO; |
|
|
|
|
import org.springblade.desk.quality.service.IIotHardnessService; |
|
|
|
|
import org.springblade.system.feign.IDictClient; |
|
|
|
|
import org.springblade.system.feign.IUserClient; |
|
|
|
|
import org.springframework.context.annotation.Lazy; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -33,21 +39,30 @@ import java.util.List; |
|
|
|
|
@AllArgsConstructor |
|
|
|
|
@EqualsAndHashCode(callSuper = true) |
|
|
|
|
@Slf4j |
|
|
|
|
public class IotHardnessServiceImpl extends BaseServiceImpl<IotHardnessMapper, IotHardness> implements IIotHardnessService { |
|
|
|
|
public class IotHardnessServiceImpl extends BaseServiceImpl<IotHardnessMapper, IotHardness> |
|
|
|
|
implements IIotHardnessService { |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private IotHardnessMapper mapper; |
|
|
|
|
|
|
|
|
|
// @Lazy
|
|
|
|
|
// @Resource
|
|
|
|
|
// private IIotHardnessService self;
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private IUserClient userClient; |
|
|
|
|
@Resource |
|
|
|
|
private IDictClient dictClient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public IPage<IotHardnessVO> selectIotHardnessPage(IPage<IotHardnessVO> page, IotHardnessVO iotHardness) { |
|
|
|
|
return page.setRecords(baseMapper.selectIotHardnessPage(page, iotHardness)); |
|
|
|
|
return page.setRecords(mapper.selectIotHardnessPage(page, iotHardness)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<IotHardnessExcel> exportIotHardness(Wrapper<IotHardness> queryWrapper) { |
|
|
|
|
List<IotHardnessExcel> iotHardnessList = baseMapper.exportIotHardness(queryWrapper); |
|
|
|
|
List<IotHardnessExcel> iotHardnessList = mapper.exportIotHardness(queryWrapper); |
|
|
|
|
//iotHardnessList.forEach(iotHardness -> {
|
|
|
|
|
// iotHardness.setTypeName(DictCache.getValue(DictEnum.YES_NO, IotHardness.getType()));
|
|
|
|
|
//});
|
|
|
|
|
@ -58,4 +73,57 @@ public class IotHardnessServiceImpl extends BaseServiceImpl<IotHardnessMapper, I |
|
|
|
|
public void setVOValue(IotHardnessVO vo) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static final Integer BATCH_SIZE = 1000; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 物理删除历史数据 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Integer deleteHistory() { |
|
|
|
|
LocalDateTime day7ago = LocalDateTime.now().minusDays(7); |
|
|
|
|
QueryWrapper<IotHardness> qw = new QueryWrapper<>(); |
|
|
|
|
qw.lt(BaseCol.CREATE_TIME, day7ago); |
|
|
|
|
qw.select(BaseCol.ID); |
|
|
|
|
List<IotHardness> list = mapper.selectList(qw); |
|
|
|
|
if (list.isEmpty()) { |
|
|
|
|
log.info("没有超过七天的删除数据。"); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
int totalDeleted = 0; |
|
|
|
|
int currentPage = 1; |
|
|
|
|
while (true) { |
|
|
|
|
IPage<IotHardness> page = new Page<>(currentPage, BATCH_SIZE); |
|
|
|
|
IPage<IotHardness> resultPage = mapper.selectPage(page, qw); |
|
|
|
|
List<IotHardness> currentBatch = resultPage.getRecords(); |
|
|
|
|
if (currentBatch.isEmpty()) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
List<Long> ids = list.stream() |
|
|
|
|
.map(IotHardness::getId) |
|
|
|
|
.toList(); |
|
|
|
|
// int deletedCount = self.deleteHistoryOneBatch(ids);
|
|
|
|
|
// totalDeleted = totalDeleted + deletedCount;
|
|
|
|
|
// currentPage = currentPage + 1;
|
|
|
|
|
} |
|
|
|
|
return totalDeleted; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 分批独立事务。 |
|
|
|
|
* |
|
|
|
|
* @param ids |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public Integer deleteHistoryOneBatch(List<Long> ids) { |
|
|
|
|
return mapper.deleteByIds(ids); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void testDeleteDemo() { |
|
|
|
|
mapper.deleteAbsoluteById(1L); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|