|
|
@ -12,6 +12,7 @@ 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; |
|
|
@ -19,15 +20,22 @@ 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; |
|
|
|
|
|
|
@ -55,10 +63,11 @@ public class QuestionnaireServiceImpl implements QuestionnaireService, ResultDat |
|
|
|
*/ |
|
|
|
public PermissionValidateResultDTO resiPermissionValidate(String projectKey, String userId, String gridId) { |
|
|
|
|
|
|
|
PrUserProjectEntity projectEntity = prUserProjectService.getProjectEntityBykey(projectKey); |
|
|
|
if (!AppClientConstant.APP_RESI.equals(projectEntity.getClient())) { |
|
|
|
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), |
|
|
|
String.format("【调查问卷详情权限校验】该调查问卷发布端为[%s],当前用户为[%s]", projectEntity.getClient(), AppClientConstant.APP_RESI)); |
|
|
|
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(); |
|
|
@ -67,36 +76,44 @@ public class QuestionnaireServiceImpl implements QuestionnaireService, ResultDat |
|
|
|
CustomerGridDTO gridInfo = getResultDataOrThrowsException(gridInfoResult, ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "【调查问卷】校验访问权限,查询网格信息失败"); |
|
|
|
// 网格父级ID列表:网格ID(拼接起来,冒号分割)
|
|
|
|
String gridIdPath = gridInfo.getPids().concat(":").concat(gridInfo.getId()); |
|
|
|
List<String> rangeList = prPublishRangeService.getRangeOrgList(projectKey); |
|
|
|
List<PrPublishRangeEntity> publishRangeEntity = prPublishRangeService.getPublishRangeEntity(projectKey); |
|
|
|
PermissionValidateResultDTO r = new PermissionValidateResultDTO(); |
|
|
|
for (String range : rangeList) { |
|
|
|
if (gridIdPath.contains(range)) { |
|
|
|
r.setPermitted(true); |
|
|
|
r.setAccessKey(generateQuestionnaireAccessKey(userId, projectKey)); |
|
|
|
return r; |
|
|
|
for (PrPublishRangeEntity rangeEntity : publishRangeEntity) { |
|
|
|
if (gridIdPath.contains(rangeEntity.getOrgIds())) { |
|
|
|
return generateValidateResult(userId, projectKey, true); |
|
|
|
} |
|
|
|
} |
|
|
|
r.setPermitted(false); |
|
|
|
return r; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 生成调查问卷accessKey |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param qKey |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2021.09.23 17:43:50 |
|
|
|
*/ |
|
|
|
private String generateQuestionnaireAccessKey(String userId, String qKey) { |
|
|
|
String accessKey = UUID.randomUUID().toString(); |
|
|
|
redisUtils.set(RedisKeys.getQuestionnaireAccessKey(userId, qKey), accessKey); |
|
|
|
return accessKey; |
|
|
|
} |
|
|
|
|
|
|
|
@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())) {
|
|
|
@ -110,19 +127,67 @@ public class QuestionnaireServiceImpl implements QuestionnaireService, ResultDat |
|
|
|
//}
|
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<IdAndNameDTO> gridList = staffInfo.getGridList(); |
|
|
|
for (IdAndNameDTO gridIdAndName : gridList) { |
|
|
|
// 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; |
|
|
|
} |
|
|
|
|
|
|
|
//private CustomerGridDTO getGridInfoById(String gridId) {
|
|
|
|
// CustomerGridFormDTO gridInfoForm = new CustomerGridFormDTO();
|
|
|
|
// gridInfoForm.setGridId(gridId);
|
|
|
|
// Result<CustomerGridDTO> result = govOrgOpenFeignClient.getGridBaseInfoByGridId(gridInfoForm);
|
|
|
|
// return getResultDataOrThrowsException(result, ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "【调查问卷】获取网格信息失败");
|
|
|
|
//}
|
|
|
|
/** |
|
|
|
* @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; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|