|
|
@ -3,6 +3,7 @@ package com.epmet.service.evaluationindex.indexcoll.impl; |
|
|
|
import com.epmet.commons.dynamic.datasource.annotation.DataSource; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.redis.RedisKeys; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.constant.DataSourceConstant; |
|
|
|
import com.epmet.constant.OrgTypeConstant; |
|
|
@ -27,6 +28,8 @@ import com.epmet.service.evaluationindex.indexcoll.FactIndexCollectService; |
|
|
|
import com.google.common.cache.Cache; |
|
|
|
import com.google.common.cache.CacheBuilder; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.redisson.api.RLock; |
|
|
|
import org.redisson.api.RedissonClient; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -38,6 +41,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -84,6 +88,8 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { |
|
|
|
private ScreenCustomerDeptDao screenCustomerDeptDao; |
|
|
|
@Autowired |
|
|
|
private ScreenCustomerAgencyDao screenCustomerAgencyDao; |
|
|
|
@Autowired |
|
|
|
private RedissonClient redissonClient; |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@ -199,11 +205,21 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void insertScreenIndexDataMonthlyAndYearly(String monthId, String customerId) { |
|
|
|
if (NumConstant.SIX != monthId.length()) { |
|
|
|
throw new RuntimeException("入参monthId格式不正确:monthId =" + monthId); |
|
|
|
} |
|
|
|
RLock lock = redissonClient.getLock(RedisKeys.getScreenIndexDataLockKey()); |
|
|
|
try { |
|
|
|
AtomicInteger tryTimes = new AtomicInteger(0); |
|
|
|
boolean lockFlag = false; |
|
|
|
do { |
|
|
|
lockFlag = lock.tryLock(1, 10, TimeUnit.MINUTES); |
|
|
|
} while (!lockFlag && tryTimes.addAndGet(1) < 3); |
|
|
|
if (!lockFlag) { |
|
|
|
log.error("插入大屏指数方法获取锁失败"); |
|
|
|
return; |
|
|
|
} |
|
|
|
allParentIds.cleanUp(); |
|
|
|
// 根据网格类型,删除 指数-指数数据(每月数值)表中 匹配的数据
|
|
|
|
this.batchDelIndexDataMonthly(customerId, monthId, OrgTypeConstant.GRID); |
|
|
@ -227,6 +243,14 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { |
|
|
|
// 根据年,汇总今年各项得到,计算平均值后 插入年表 screen_index_data_yearly
|
|
|
|
this.insertIndexDataYear(monthId, customerId); |
|
|
|
allParentIds.invalidateAll(); |
|
|
|
} catch (InterruptedException inter) { |
|
|
|
log.error("插入计算指标数据异常", inter); |
|
|
|
} finally { |
|
|
|
//判断是否是当前线程 持有锁
|
|
|
|
if (lock.isHeldByCurrentThread()) { |
|
|
|
lock.unlock(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|