8 changed files with 228 additions and 5 deletions
@ -0,0 +1,9 @@ |
|||
package com.epmet.dataaggre.dto.epmettduck.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class PermissionValidateResultDTO { |
|||
private Boolean permitted; |
|||
private String accessKey; |
|||
} |
@ -0,0 +1,9 @@ |
|||
package com.epmet.dataaggre.service; |
|||
|
|||
import com.epmet.dataaggre.dto.epmettduck.result.PermissionValidateResultDTO; |
|||
|
|||
public interface QuestionnaireService { |
|||
PermissionValidateResultDTO resiPermissionValidate(String projectKey, String userId, String gridId); |
|||
|
|||
PermissionValidateResultDTO govPermissionValidate(String projectKey, String staffId, String customerId); |
|||
} |
@ -0,0 +1,128 @@ |
|||
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.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 org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
@Service |
|||
public class QuestionnaireServiceImpl implements QuestionnaireService, ResultDataResolver { |
|||
|
|||
@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 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)); |
|||
} |
|||
|
|||
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<String> rangeList = prPublishRangeService.getRangeOrgList(projectKey); |
|||
PermissionValidateResultDTO r = new PermissionValidateResultDTO(); |
|||
for (String range : rangeList) { |
|||
if (gridIdPath.contains(range)) { |
|||
r.setPermitted(true); |
|||
r.setAccessKey(generateQuestionnaireAccessKey(userId, projectKey)); |
|||
return r; |
|||
} |
|||
} |
|||
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) { |
|||
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(); |
|||
|
|||
List<IdAndNameDTO> gridList = staffInfo.getGridList(); |
|||
for (IdAndNameDTO gridIdAndName : gridList) { |
|||
|
|||
} |
|||
|
|||
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(), "【调查问卷】获取网格信息失败");
|
|||
//}
|
|||
} |
Loading…
Reference in new issue