DeleteQuestionConsumer.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package cn.com.qmth.im;
  2. import java.io.IOException;
  3. import java.util.Map;
  4. import org.apache.commons.io.IOUtils;
  5. import org.apache.log4j.LogManager;
  6. import org.apache.log4j.Logger;
  7. import com.google.common.collect.Maps;
  8. import cn.com.qmth.multithread.Consumer;
  9. import cn.com.qmth.param.Param;
  10. import okhttp3.Response;
  11. public class DeleteQuestionConsumer extends Consumer<DeleteQuestionDto> {
  12. private static Logger logger = LogManager.getLogger(DeleteQuestionConsumer.class);
  13. @Override
  14. public void consume(DeleteQuestionDto dto) {
  15. for (QuestionId c : dto.getIds()) {
  16. try {
  17. submit(c);
  18. } catch (IOException e) {
  19. logger.error("删除失败:" + c.getUnitId() + " | " + c.getQuestionId(), e);
  20. }
  21. }
  22. }
  23. private static void submit(QuestionId ic) throws IOException {
  24. Map<String, String> params = Maps.newHashMap();
  25. Map<String, String> headers = Maps.newHashMap();
  26. headers.put("key", Param.key);
  27. headers.put("token", Param.token);
  28. Response resp = null;
  29. try {
  30. resp = OKHttpUtil.call(HttpMethod.DELETE,
  31. Param.host + "/api/ecs_ques/paper/deleteQuestion/" + ic.getUnitId() + "/" + ic.getQuestionId(),
  32. headers, params);
  33. if (resp.code() != 200) {
  34. logger.error(ic.getUnitId() + " | " + ic.getQuestionId() + ":body:" + resp.body().string());
  35. // throw new RuntimeException(ic.getUnitId() + " | " +
  36. // ic.getQuestionId() + ":body:" + resp.body().string());
  37. }
  38. } finally {
  39. IOUtils.closeQuietly(resp);
  40. }
  41. }
  42. }