RestTemplate 组装数据

@Component
public class CouponOnlineTask {
/*
@Autowired
private CouponOnline couponOnline;
private RestTemplate restTemplate;*/
@Value(“ a p i . o c m . c o u p o n O n l i n e U r l " ) p r i v a t e S t r i n g c o u p o n U r l ; @ V a l u e ( " {api.ocm.couponOnlineUrl}") private String couponUrl; @Value(" api.ocm.couponOnlineUrl")privateStringcouponUrl;@Value("{api.ocm.couponCancellationUrl}”)
private String couponCancellationUrl;
@Value(“ o c m . u s e r N a m e " ) p r i v a t e S t r i n g o c m U s e r N a m e ; @ V a l u e ( " {ocm.userName}") private String ocmUserName; @Value(" ocm.userName")privateStringocmUserName;@Value("{ocm.secretKey}”)
private String ocmSecretKey;

private static final Logger LOGGER =  LoggerFactory.getLogger(CouponOnlineTask.class);

@XxlJob(“couponIssueTask”)
public void couponIssueTask(){
LOGGER.info(“定时任务开始执行,批次发放优惠卷…”);
EEyeLogSender.info(“定时任务开始执行,批次发放优惠卷…”);
LOGGER.info(“url”+couponUrl+" username:"+ocmUserName+“ocmSeretKey”+ocmSecretKey);
// 调用定时任务
try{
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType(“application/json; charset=UTF-8”);
headers.setContentType(type);
headers.add(“Accept”, MediaType.APPLICATION_JSON.toString());
headers.add(“userName”, ocmUserName);
headers.add(“secretKey”,ocmSecretKey);
//JSONObject jsonObj = JSONObject.fromObject(params);

        HttpEntity<String> formEntity = new HttpEntity<String>(headers);

        String result = restTemplate.postForObject(couponUrl, formEntity, String.class);

        LOGGER.info("执行优惠券批次发放定时任务返回"+result.toString());
        EEyeLogSender.info("执行优惠券批次发放定时任务返回"+result.toString());
    }catch (Exception e){
        e.printStackTrace();
        LOGGER.error("定时任务发放优惠券出错.",e);
        EEyeLogSender.error("定时任务发放优惠券出错"+e);
    }

}

@XxlJob(“couponIssueTaskFri”)
public void couponIssueTaskFri(){
LOGGER.info(“定时任务开始执行,批次发放优惠卷…”);
EEyeLogSender.info(“定时任务开始执行,批次发放优惠卷…”);
LOGGER.info(“url”+couponUrl+" username:"+ocmUserName+“ocmSeretKey”+ocmSecretKey);
// 调用定时任务
try{
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType(“application/json; charset=UTF-8”);
headers.setContentType(type);
headers.add(“Accept”, MediaType.APPLICATION_JSON.toString());
headers.add(“userName”, ocmUserName);
headers.add(“secretKey”,ocmSecretKey);
//JSONObject jsonObj = JSONObject.fromObject(params);

        HttpEntity<String> formEntity = new HttpEntity<String>(headers);

        String result = restTemplate.postForObject(couponUrl, formEntity, String.class);

        LOGGER.info("执行优惠券批次发放定时任务返回"+result.toString());
        EEyeLogSender.info("执行优惠券批次发放定时任务返回"+result.toString());
    }catch (Exception e){
        e.printStackTrace();
        LOGGER.error("定时任务发放优惠券出错.",e);
        EEyeLogSender.error("定时任务发放优惠券出错"+e);
    }

}

@XxlJob(“couponCancellationTask”)
public void couponCancellationTask(){
LOGGER.info(“定时任务开始执行,处理异常优惠卷…”);
EEyeLogSender.info(“定时任务开始执行,处理异常优惠卷…”);
LOGGER.info(“url”+couponCancellationUrl+" username:"+ocmUserName+“ocmSeretKey”+ocmSecretKey);
// 调用定时任务
try{
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType(“application/json; charset=UTF-8”);
headers.setContentType(type);
headers.add(“Accept”, MediaType.APPLICATION_JSON.toString());
headers.add(“userName”, ocmUserName);
headers.add(“secretKey”,ocmSecretKey);
//JSONObject jsonObj = JSONObject.fromObject(params);

        HttpEntity<String> formEntity = new HttpEntity<String>(headers);

        String result = restTemplate.postForObject(couponCancellationUrl, formEntity, String.class);

        LOGGER.info("执行处理异常优惠券定时任务返回"+result.toString());
        EEyeLogSender.info("执行处理异常优惠券定时任务返回"+result.toString());
    }catch (Exception e){
        e.printStackTrace();
        LOGGER.error("执行处理异常优惠券定时任务异常.",e);
        EEyeLogSender.error("执行处理异常优惠券定时任务异常"+e);
    }

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值