|
@ -12,8 +12,11 @@ import com.epmet.commons.tools.constant.StrConstant; |
|
|
import com.epmet.commons.tools.dto.form.DingTextBriefNessFormDTO; |
|
|
import com.epmet.commons.tools.dto.form.DingTextBriefNessFormDTO; |
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
|
|
import com.epmet.commons.tools.redis.RedisKeys; |
|
|
|
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; |
|
|
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; |
|
@ -60,6 +63,7 @@ import java.io.OutputStream; |
|
|
import java.text.NumberFormat; |
|
|
import java.text.NumberFormat; |
|
|
import java.text.SimpleDateFormat; |
|
|
import java.text.SimpleDateFormat; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -95,6 +99,10 @@ public class GovOrgServiceImpl implements GovOrgService { |
|
|
private EvaluationIndexService evaluationIndexService; |
|
|
private EvaluationIndexService evaluationIndexService; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private IcBuildingDao icBuildingDao; |
|
|
private IcBuildingDao icBuildingDao; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private ExecutorService executorService; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param staffId |
|
|
* @param staffId |
|
@ -583,12 +591,34 @@ public class GovOrgServiceImpl implements GovOrgService { |
|
|
@Override |
|
|
@Override |
|
|
public List<OrgTreeResultDTO> getAgencyTree(TokenDto tokenDto, SubOrgFormDTO formDTO) { |
|
|
public List<OrgTreeResultDTO> getAgencyTree(TokenDto tokenDto, SubOrgFormDTO formDTO) { |
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); |
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); |
|
|
|
|
|
if (staffInfo == null || StringUtils.isBlank(staffInfo.getAgencyId())){ |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"工作人员所属组织不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
//组织缓存key
|
|
|
|
|
|
String treeCacheKey = RedisKeys.getOrgTreeCacheKey(formDTO.getAgencyId()).concat(StrConstant.COLON).concat(formDTO.getClient()); |
|
|
|
|
|
Long expiryTime = redisUtils.getTTL(treeCacheKey); |
|
|
|
|
|
List<OrgTreeResultDTO> orgTreeResultDTOS = (List<OrgTreeResultDTO>) redisUtils.get(treeCacheKey); |
|
|
|
|
|
String agencyId = staffInfo.getAgencyId(); |
|
|
|
|
|
String client = formDTO.getClient(); |
|
|
|
|
|
//如果接近过期或已经过期且缓存数据不为空 则异步查询
|
|
|
|
|
|
if ((expiryTime == null || expiryTime <= NumConstant.ONE_THOUSAND) && CollectionUtils.isNotEmpty(orgTreeResultDTOS)) { |
|
|
|
|
|
executorService.submit(() -> { |
|
|
|
|
|
List<OrgTreeResultDTO> list = buildTempOrgTree(agencyId, client); |
|
|
|
|
|
redisUtils.set(treeCacheKey, list, RedisUtils.HOUR_FOUR_EXPIRE); |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
orgTreeResultDTOS = buildTempOrgTree(staffInfo.getAgencyId(), formDTO.getClient()); |
|
|
|
|
|
redisUtils.set(treeCacheKey, orgTreeResultDTOS, RedisUtils.HOUR_FOUR_EXPIRE); |
|
|
|
|
|
} |
|
|
|
|
|
return orgTreeResultDTOS; |
|
|
|
|
|
} |
|
|
|
|
|
private List<OrgTreeResultDTO> buildTempOrgTree(String agencyId, String client){ |
|
|
List<OrgTreeResultDTO> list = new ArrayList<>(); |
|
|
List<OrgTreeResultDTO> list = new ArrayList<>(); |
|
|
if ("resi".equals(formDTO.getClient())) { |
|
|
if ("resi".equals(client)) { |
|
|
list.add(customerAgencyDao.getResiOrgTree(staffInfo.getAgencyId())); |
|
|
list.add(customerAgencyDao.getResiOrgTree(agencyId)); |
|
|
return list; |
|
|
return list; |
|
|
} |
|
|
} |
|
|
list.add(customerAgencyDao.getOrgTree(staffInfo.getAgencyId())); |
|
|
list.add(customerAgencyDao.getOrgTree(agencyId)); |
|
|
return list; |
|
|
return list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|