|
|
package com.yohoufo.resource.service.impl.resource;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yohoufo.resource.helper.MakeUrlService;
|
|
|
import com.yohoufo.resource.service.IResourceParse;
|
|
|
import com.yohoufo.resource.service.Resource;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
|
/**
|
|
|
* Created by oneway.wang on 2017/7/10.
|
|
|
*/
|
|
|
@Service
|
|
|
public class TwoPictureResourceParse implements IResourceParse {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(TwoPictureResourceParse.class);
|
|
|
|
|
|
public static final String TEMPLATE_NAME="twoPicture";
|
|
|
@Autowired
|
|
|
private MakeUrlService makeUrlService;
|
|
|
|
|
|
@Override
|
|
|
public Serializable parse(Resource resource) {
|
|
|
try {
|
|
|
return parseData(resource);
|
|
|
} catch (Exception e) {
|
|
|
logger.warn("Parse TwoPicture resource fail, resource code [{}] exception: {}", resource.getCode(), e);
|
|
|
return resource.getData();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private JSONObject parseData(Resource resource) {
|
|
|
|
|
|
JSONObject returnJSON=new JSONObject();
|
|
|
//加入最基础的东西
|
|
|
returnJSON.put("template_id",resource.getId().toString());
|
|
|
|
|
|
returnJSON.put("template_intro",resource.getData().getString("template_intro"));
|
|
|
|
|
|
// 处理 data(充分利用原数据库中数据转成的JSONObject,只是遍历之后把URLObject替换成解析之后的数据)
|
|
|
JSONObject data = resource.getData().getJSONObject("data");
|
|
|
|
|
|
|
|
|
returnJSON.put("template_name",this.TEMPLATE_NAME);
|
|
|
// 处理 两张图的list
|
|
|
for (String index: data.getJSONObject("list").keySet()) {
|
|
|
makeUrl(data.getJSONObject("list").getJSONObject(index), resource.getClientType());
|
|
|
}
|
|
|
returnJSON.put("data",data);
|
|
|
return returnJSON;
|
|
|
}
|
|
|
|
|
|
private void makeUrl(JSONObject jsonElement, String clientType) {
|
|
|
JSONObject jsonUrl = jsonElement.getJSONObject("url");
|
|
|
String strUrl = makeUrlService.makeUrl(jsonUrl, clientType);
|
|
|
jsonElement.put("url", strUrl);
|
|
|
}
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|