51e847e9d185abcabf5b742fb1a0d054a5455fb7.svn-base 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.chinacreator.process.job;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import org.apache.log4j.Logger;
  6. import org.quartz.DisallowConcurrentExecution;
  7. import org.quartz.PersistJobDataAfterExecution;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import com.chinacreator.common.exception.BusinessException;
  10. import com.chinacreator.process.bean.TencentVacOrderBean;
  11. import com.chinacreator.process.dao.DictionaryDao;
  12. import com.chinacreator.process.dao.VacOrderDao;
  13. import com.chinacreator.process.util.JsonUtil;
  14. import com.chinacreator.video.queue.MessageService;
  15. import com.chinacreator.video.queue.bean.MessagePipe;
  16. @PersistJobDataAfterExecution
  17. @DisallowConcurrentExecution
  18. public class TencentActivityJob {
  19. private static Logger log = Logger.getLogger(TencentActivityJob.class);
  20. private static Logger logger = Logger.getLogger("tencentActivity");
  21. @Autowired
  22. private DictionaryDao dictionaryDao;
  23. @Autowired
  24. private MessageService messageService;
  25. @Autowired
  26. private VacOrderDao vacOrderDao;
  27. public void doProcess() throws Exception {
  28. if(dictionaryDao.getValue("recivemq").equals("0")){
  29. log.info("========》腾讯20元0元扣费job启动(接受)");
  30. long beginTime = System.currentTimeMillis();
  31. List<MessagePipe> list = messageService
  32. .reciveBatchMessage("vacorder", 500);
  33. log.info("腾讯20元0元扣费队列(接受)花费时间:"+(System.currentTimeMillis()-beginTime));
  34. log.info("腾讯20元0元扣费队列(接受)大小:"+ (list == null ? 0 : list.size()));
  35. for (MessagePipe messagePipe : list) {
  36. String resultcode="0";
  37. String errorinfo="";
  38. Map<String,String> logMap = new HashMap<String, String>();
  39. try{
  40. TencentVacOrderBean bean = transBean(messagePipe.getBody());
  41. logMap.put("parmar", JsonUtil.objectToJson(messagePipe.getBody()));
  42. TencentVacOrderBean localbean = vacOrderDao.query(bean.getCpid(),bean.getSpid(), bean.getUserid());
  43. if(localbean == null){
  44. log.info("腾讯20元0元扣费队列(接受)插入");
  45. vacOrderDao.insert(bean);
  46. }else if(bean.getStatus().equals("0")){
  47. log.info("腾讯20元0元扣费队列(接受)order");
  48. vacOrderDao.order(bean.getOrdertime(), localbean.getId());
  49. }else{
  50. log.info("腾讯20元0元扣费队列(接受)cancel");
  51. vacOrderDao.cancel(bean.getCanceltime(), localbean.getId());
  52. }
  53. }catch(Exception e){
  54. log.error("",e);
  55. e.printStackTrace();
  56. if(e instanceof BusinessException){
  57. resultcode = ((BusinessException) e).getCode();
  58. errorinfo = ((BusinessException) e).getMessage();
  59. }else{
  60. resultcode = "8000";
  61. errorinfo = "系统错误";
  62. }
  63. }finally {
  64. logMap.put("resultcode", resultcode);
  65. logMap.put("errorinfo",errorinfo);
  66. logger.info(JsonUtil.objectToJson(logMap));
  67. }
  68. }
  69. }else{
  70. log.info("========》腾讯20元接收0元扣费job停止");
  71. }
  72. }
  73. public TencentVacOrderBean transBean(Map<String, Object> body) {
  74. String jsonStr = JsonUtil.objectToJson(body);
  75. return (TencentVacOrderBean) JsonUtil.jsonToBean(jsonStr, TencentVacOrderBean.class);
  76. }
  77. }