只知道普通的接口的定义,服务接口还真不知道怎么下手。下面是原先一个小模块的服务接口
package cn.damai.mt.app.advert.rest.impl;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import cn.damai.mt.app.advert.rest.AdvertRestService;
import cn.damai.mt.app.advert.service.MtcAppAdvertService;
import cn.damai.mt.app.model.MtcAppAdvert;
import cn.damai.mt.app.resp.ModelResp;
import cn.damai.mt.app.util.ParamUtil;
@Service("terminalAppAdvertRestService")
public class AdvertRestServiceImpl implements AdvertRestService {
private Log log = LogFactory.getLog(getClass());
@Resource(name = "mtcAppAdvertService")
MtcAppAdvertService mtcAppAdvertService;
@Override
public ModelResp> getHomeAdvert(HttpServletRequest request) {
ModelResp> resp=new ModelResp>();
Map map=ParamUtil.getParaMap(request);
Map resultMap=new HashMap();
int type=0;
if(map.get("type")!=null){
try {
type=(Integer)map.get("type");
} catch (Exception e) {
log.info("参数不符合条件!");
resp.setCode(400);
return resp;
}
}
if(type==1||type==2||type==3){
try {
MtcAppAdvert mtcAppAdvert = mtcAppAdvertService.getHomeAdvert();
MtcAppAdvert mtcAppAd = mtcAppAdvertService.getHomeAd();
if(mtcAppAdvert!=null){
String imgUrl = mtcAppAdvert.getImgUrl();
String[] array = imgUrl.split(",");
String md5 = mtcAppAdvert.getMd5();
String[] arr = md5.split(",");
if(type==1){
imgUrl = array[0];
md5 = arr[0];
}else if(type==2){
imgUrl = array[1];
md5 = arr[1];
}else if(type==3){
imgUrl = array[2];
md5 = arr[2];
}
resultMap.put("advertTitle", mtcAppAdvert.getAdvertTitle());
resultMap.put("jumpContent", mtcAppAdvert.getJumpContent());
resultMap.put("imgUrl", imgUrl);
resultMap.put("md5", md5);
resp.setCode(200);
resp.setData(resultMap);
return resp;
}else{//符合条件的为空,
if(mtcAppAd!=null){//有数据,但不符合条件
log.info("有数据,但不符合条件!");
resp.setCode(203);
//203:无数据返回
return resp;
}
log.info("没有广告!");
resp.setCode(201);
//201:无数据返回
return resp;
}
} catch (Exception e) {
log.error(e);
e.printStackTrace();
resp.setCode(500);
return resp;
}
}else{
log.info("获取首页广告图:安卓和ios的分辨类型不正确!");
resp.setCode(400);
return resp;
}
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。