package com.goafanti.sc.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.goafanti.common.bo.Result;
import com.goafanti.common.constant.ErrorConstants;
import com.goafanti.common.controller.CertifyApiController;
import com.goafanti.common.model.ScMessage;
import com.goafanti.common.utils.StringUtils;
import com.goafanti.sc.service.CommonService;

@RestController
@RequestMapping(value = "/open/api")
public class CommonController extends CertifyApiController {
	
	@Resource
	private CommonService		commonService;
	 /**
     * 增加留言
     */
     @RequestMapping(value = "/addMessage", method = RequestMethod.GET)
     private Result addMessage(ScMessage s){
     	Result res = new Result();
     	if (StringUtils.isBlank(s.getMobile())) {
          	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到号码", "号码"));
               return res;
   		}
     	if (StringUtils.isBlank(s.getName())) {
         	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到名称", "名称"));
              return res;
  		}
     	res.setData(commonService.addMessage(s));
     	return res;
     }
     /**
      * 留言列表
      */
     @RequestMapping(value = "/listMessage", method = RequestMethod.GET)
     private Result listMessage(String id,Integer pageSize,Integer pageNo) {
         Result res = new Result();
         if (StringUtils.isBlank(id)) {
         	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到名称", "来源"));
              return res;
  		}
        res.setData(commonService.listMessage(id,pageSize,pageNo));
        return res;
     }

}
