Authored by ken.hu

u

... ... @@ -5,21 +5,16 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.yoho.core.rest.annotation.ServiceDesc;
import com.yoho.service.model.resource.request.ResourcesRequestBody;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.resource.request.ResourcesRequest;
import com.yohoufo.resource.service.IResourcesService;
@RestController
@RequestMapping(value = "/resources")
@ServiceDesc(serviceName = "resources")
public class ResourcesController {
private static final Logger logger = LoggerFactory.getLogger(ResourcesController.class);
... ... @@ -28,30 +23,20 @@ public class ResourcesController {
private IResourcesService resourcesService;
/**
* 根据内容码,获取单个内容个体
*
* <p>根据contentCode返回资源结果</p>
*
* @param contentCode
* @param clientType
* @return
* @date: Created on 2018年9月18日 上午10:36:49
*/
@RequestMapping(value = "/get", method = RequestMethod.POST)
public @ResponseBody ApiResponse get(@RequestBody ResourcesRequestBody request) {
logger.info("Get resources by content code[{}] and client type [{}].", request.getContentCode(),
request.getClientType());
List<Object> data = resourcesService.get(request);
logger.info("Get resources by content code[{}] and client type [{}] success.", request.getContentCode(),
request.getClientType());
return new ApiResponse.ApiResponseBuilder().data(data).code(200).message("resources data").build();
}
@RequestMapping(params = "method=ufo.resource.get")
public ApiResponse payment(@RequestParam(name = "contentCode") String contentCode,
@ResponseBody
public ApiResponse getResource(@RequestParam(name = "contentCode") String contentCode,
@RequestParam(name = "clientType") String clientType) {
ResourcesRequestBody request = new ResourcesRequestBody();
request.setClientType(clientType);
request.setContentCode(contentCode);
logger.info("Get resources by content code[{}] and client type [{}].", request.getContentCode(),
request.getClientType());
logger.info("Get resources by content code[{}] and client type [{}].", contentCode, clientType);
ResourcesRequest request = ResourcesRequest.builder().clientType(clientType).contentCode(contentCode).build();
List<Object> data = resourcesService.get(request);
logger.info("Get resources by content code[{}] and client type [{}] success.", request.getContentCode(),
request.getClientType());
... ...
package com.yohoufo.resource.request;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ResourcesRequest {
private String contentCode;
private String clientType;
}
... ...
... ... @@ -2,7 +2,7 @@ package com.yohoufo.resource.service;
import java.util.List;
import com.yoho.service.model.resource.request.ResourcesRequestBody;
import com.yohoufo.resource.request.ResourcesRequest;
public interface IResourcesService {
... ... @@ -12,6 +12,6 @@ public interface IResourcesService {
* @param request
* @return
*/
List<Object> get(ResourcesRequestBody request);
List<Object> get(ResourcesRequest request);
}
... ...
... ... @@ -25,7 +25,7 @@ import com.google.common.collect.Lists;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.resource.request.ResourcesRequestBody;
import com.yohoufo.resource.request.ResourcesRequest;
import com.yohoufo.common.cache.CacheEnum;
import com.yohoufo.common.redis.NoSyncGracefulRedisTemplate;
import com.yohoufo.common.utils.Constant;
... ... @@ -67,7 +67,7 @@ public class ResourcesServiceImpl implements IResourcesService {
private AsyncTaskExecutor resourceAsyncTaskExecutor;
@Override
public List<Object> get(ResourcesRequestBody request) {
public List<Object> get(ResourcesRequest request) {
log.info("Begin find all resource content data by content code is {},client type is {}.", request.getContentCode(), request.getClientType());
//(1)请求数据验证
validateRequestForGet(request);
... ... @@ -83,7 +83,7 @@ public class ResourcesServiceImpl implements IResourcesService {
resourcesRedisCache.setEx(cacheKey, list, CacheEnum.RESOURCE_GET.getCacheTime()); return list;
}
private void validateRequestForGet(ResourcesRequestBody request) {
private void validateRequestForGet(ResourcesRequest request) {
if (StringUtils.isEmpty(request.getContentCode())) {
log.warn("Content code is empty.");
throw new ServiceException(ServiceError.RESOURCES_CONTENT_CODE_IS_EMPTY);
... ... @@ -95,21 +95,6 @@ public class ResourcesServiceImpl implements IResourcesService {
}
private void validateRequestForHome(ResourcesRequestBody request) {
if (StringUtils.isEmpty(request.getContentCode())) {
log.warn("Content code is empty.");
throw new ServiceException(ServiceError.RESOURCES_CONTENT_CODE_IS_EMPTY);
}
if (StringUtils.isEmpty(request.getClientType())) {
log.warn("Client type is empty.");
throw new ServiceException(ServiceError.RESOURCES_CLIENT_TYPE_IS_EMPTY);
}
if (StringUtils.isEmpty(request.getGender())) {
log.warn("Gender is empty.");
throw new ServiceException(ServiceError.RESOURCES_GENDER_IS_EMPTY);
}
}
/**
* 查找并解析资源内容数据
*
... ...