|
|
@ -0,0 +1,193 @@ |
|
|
|
package com.epmet.dataaggre.service.impl; |
|
|
|
|
|
|
|
import com.epmet.commons.tools.constant.AppClientConstant; |
|
|
|
import com.epmet.commons.tools.constant.ServiceConstant; |
|
|
|
import com.epmet.commons.tools.dto.form.IdAndNameDTO; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.feign.ResultDataResolver; |
|
|
|
import com.epmet.commons.tools.redis.RedisKeys; |
|
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dataaggre.dto.epmettduck.result.PermissionValidateResultDTO; |
|
|
|
import com.epmet.dataaggre.entity.epmettduck.PrPublishRangeEntity; |
|
|
|
import com.epmet.dataaggre.entity.epmettduck.PrUserProjectEntity; |
|
|
|
import com.epmet.dataaggre.service.QuestionnaireService; |
|
|
|
import com.epmet.dataaggre.service.epmettduck.PrPublishRangeService; |
|
|
|
import com.epmet.dataaggre.service.epmettduck.PrUserProjectService; |
|
|
|
import com.epmet.dto.CustomerGridDTO; |
|
|
|
import com.epmet.dto.form.CustomerGridFormDTO; |
|
|
|
import com.epmet.feign.GovOrgOpenFeignClient; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class QuestionnaireServiceImpl implements QuestionnaireService, ResultDataResolver { |
|
|
|
|
|
|
|
/** 调查问卷有效期 15min */ |
|
|
|
public static final long QUESTIONNAIRE_EXPIRE_SECONDS = 15 * 60; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PrUserProjectService prUserProjectService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PrPublishRangeService prPublishRangeService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private GovOrgOpenFeignClient govOrgOpenFeignClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CustomerStaffRedis customerStaffRedis; |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 居民端调查问卷权限校验 |
|
|
|
* |
|
|
|
* @param projectKey |
|
|
|
* @param userId |
|
|
|
* @param gridId |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2021.09.23 17:45:25 |
|
|
|
*/ |
|
|
|
public PermissionValidateResultDTO resiPermissionValidate(String projectKey, String userId, String gridId) { |
|
|
|
|
|
|
|
PrUserProjectEntity project = prUserProjectService.getProjectEntityBykey(projectKey); |
|
|
|
if (project == null || !AppClientConstant.APP_RESI.equals(project.getClient())) { |
|
|
|
// 工作端只能看到发布到居民端的
|
|
|
|
log.warn("【调查问卷】居民端无法查看发布到工作端的调查问卷,staffId:{}, projectKey:{}", userId, projectKey); |
|
|
|
return generateValidateResult(userId, projectKey, false); |
|
|
|
} |
|
|
|
|
|
|
|
CustomerGridFormDTO form = new CustomerGridFormDTO(); |
|
|
|
form.setGridId(gridId); |
|
|
|
Result<CustomerGridDTO> gridInfoResult = govOrgOpenFeignClient.getGridBaseInfoByGridId(form); |
|
|
|
CustomerGridDTO gridInfo = getResultDataOrThrowsException(gridInfoResult, ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "【调查问卷】校验访问权限,查询网格信息失败"); |
|
|
|
// 网格父级ID列表:网格ID(拼接起来,冒号分割)
|
|
|
|
String gridIdPath = gridInfo.getPids().concat(":").concat(gridInfo.getId()); |
|
|
|
List<PrPublishRangeEntity> publishRangeEntity = prPublishRangeService.getPublishRangeEntity(projectKey); |
|
|
|
PermissionValidateResultDTO r = new PermissionValidateResultDTO(); |
|
|
|
for (PrPublishRangeEntity rangeEntity : publishRangeEntity) { |
|
|
|
if (gridIdPath.contains(rangeEntity.getOrgIds())) { |
|
|
|
return generateValidateResult(userId, projectKey, true); |
|
|
|
} |
|
|
|
} |
|
|
|
r.setPermitted(false); |
|
|
|
return r; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PermissionValidateResultDTO govPermissionValidate(String projectKey, String staffId, String customerId) { |
|
|
|
PrUserProjectEntity project = prUserProjectService.getProjectEntityBykey(projectKey); |
|
|
|
if (project == null || !"gov".equals(project.getClient())) { |
|
|
|
// 工作端只能看到发布到工作端的
|
|
|
|
log.warn("【调查问卷】工作端无法查看发布到居民端的调查问卷,staffId:{}, projectKey:{}", staffId, projectKey); |
|
|
|
return generateValidateResult(staffId, projectKey, false); |
|
|
|
} |
|
|
|
|
|
|
|
List<String> gridRangeOrgIds = new ArrayList<>(); |
|
|
|
List<String> agencyRangeOrgIds = new ArrayList<>(); |
|
|
|
List<String> deptRangeOrgIds = new ArrayList<>(); |
|
|
|
|
|
|
|
// 将发布范围分别放到3个不同的列表中
|
|
|
|
List<PrPublishRangeEntity> publishRangeEntitys = prPublishRangeService.getPublishRangeEntity(projectKey); |
|
|
|
publishRangeEntitys.forEach(rangeEntity -> { |
|
|
|
if ("grid".equals(rangeEntity.getOrgType())) { |
|
|
|
gridRangeOrgIds.add(rangeEntity.getOrgIds()); |
|
|
|
} else if ("agency".equals(rangeEntity.getOrgType())) { |
|
|
|
agencyRangeOrgIds.add(rangeEntity.getOrgIds()); |
|
|
|
} else if ("dept".equals(rangeEntity.getOrgType())) { |
|
|
|
deptRangeOrgIds.add(rangeEntity.getOrgIds()); |
|
|
|
} else { |
|
|
|
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), String.format("【调查问卷】未知的发布范围类型:%s", rangeEntity.getOrgType())); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
CustomerStaffInfoCacheResult staffInfo = customerStaffRedis.getStaffInfo(customerId, staffId); |
|
|
|
PermissionValidateResultDTO r = null; |
|
|
|
//if ("agency".equals(staffInfo.getFromOrgType())) {
|
|
|
|
// // 来自agency
|
|
|
|
//
|
|
|
|
//} else if ("grid".equals(staffInfo.getFromOrgType())) {
|
|
|
|
// List<IdAndNameDTO> belongGridList = staffInfo.getGridList();
|
|
|
|
//
|
|
|
|
//} else if ("dept".equals(staffInfo.getFromOrgType())) {
|
|
|
|
//
|
|
|
|
//}
|
|
|
|
|
|
|
|
String agencyId = staffInfo.getAgencyId(); |
|
|
|
String agencyPIds = staffInfo.getAgencyPIds(); |
|
|
|
|
|
|
|
// 网格范围内的权限判断
|
|
|
|
List<IdAndNameDTO> staffGridList = staffInfo.getGridList(); |
|
|
|
for (IdAndNameDTO gridIdAndName : staffGridList) { |
|
|
|
// 工作人员所属的 父orgId路径:网格id
|
|
|
|
String staffGridIdPath = (StringUtils.isEmpty(agencyPIds) ? "" : agencyPIds.concat(":")).concat(agencyId).concat(":").concat(gridIdAndName.getId()); |
|
|
|
for (String gridRangeOrgId : gridRangeOrgIds) { |
|
|
|
if (staffGridIdPath.contains(gridRangeOrgId)) { |
|
|
|
r = generateValidateResult(staffId, projectKey, true); |
|
|
|
return r; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// dept范围内的权限判断
|
|
|
|
List<IdAndNameDTO> staffDeptList = staffInfo.getDeptList(); |
|
|
|
for (IdAndNameDTO deptIdAndName : staffDeptList) { |
|
|
|
// 工作人员所属的 父orgId路径:网格id
|
|
|
|
String staffDeptIdPath = (StringUtils.isEmpty(agencyPIds) ? "" : agencyPIds.concat(":")).concat(agencyId).concat(":").concat(deptIdAndName.getId()); |
|
|
|
for (String deptRangeOrgIdPath : deptRangeOrgIds) { |
|
|
|
if (staffDeptIdPath.contains(deptRangeOrgIdPath)) { |
|
|
|
r = generateValidateResult(staffId, projectKey, true); |
|
|
|
return r; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// agency范围内的权限判断
|
|
|
|
String staffAgencyIdPath = (StringUtils.isEmpty(agencyPIds) ? "" : agencyPIds.concat(":")).concat(agencyId); |
|
|
|
for (String agencyRangeOrgId : agencyRangeOrgIds) { |
|
|
|
if (staffAgencyIdPath.contains(agencyRangeOrgId)) { |
|
|
|
r = generateValidateResult(staffId, projectKey, true); |
|
|
|
return r; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 如果上述范围中都不能判断通过,那么返回一个不通过的结果给到前端
|
|
|
|
r = generateValidateResult(staffId, projectKey, false); |
|
|
|
return r; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 生成权限允许的返回结果 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param projectKey |
|
|
|
* @param permitted 是否允许访问 |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2021.09.23 23:19:17 |
|
|
|
*/ |
|
|
|
private PermissionValidateResultDTO generateValidateResult(String userId, String projectKey, Boolean permitted) { |
|
|
|
PermissionValidateResultDTO d = new PermissionValidateResultDTO(); |
|
|
|
d.setPermitted(permitted); |
|
|
|
if (permitted) { |
|
|
|
String accessKey = UUID.randomUUID().toString().replace("-", ""); |
|
|
|
redisUtils.set(RedisKeys.getQuestionnaireAccessKey(userId, projectKey), accessKey, QUESTIONNAIRE_EXPIRE_SECONDS); |
|
|
|
d.setAccessKey(accessKey); |
|
|
|
} |
|
|
|
return d; |
|
|
|
} |
|
|
|
|
|
|
|
} |