package cn.com.qmth.im; import java.io.IOException; import java.util.Map; import org.apache.commons.io.IOUtils; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import com.google.common.collect.Maps; import cn.com.qmth.multithread.Consumer; import cn.com.qmth.param.Param; import okhttp3.Response; public class DeleteQuestionConsumer extends Consumer { private static Logger logger = LogManager.getLogger(DeleteQuestionConsumer.class); @Override public void consume(DeleteQuestionDto dto) { for (QuestionId c : dto.getIds()) { try { submit(c); } catch (IOException e) { logger.error("删除失败:" + c.getUnitId() + " | " + c.getQuestionId(), e); } } } private static void submit(QuestionId ic) throws IOException { Map params = Maps.newHashMap(); Map headers = Maps.newHashMap(); headers.put("key", Param.key); headers.put("token", Param.token); Response resp = null; try { resp = OKHttpUtil.call(HttpMethod.DELETE, Param.host + "/api/ecs_ques/paper/deleteQuestion/" + ic.getUnitId() + "/" + ic.getQuestionId(), headers, params); if (resp.code() != 200) { logger.error(ic.getUnitId() + " | " + ic.getQuestionId() + ":body:" + resp.body().string()); // throw new RuntimeException(ic.getUnitId() + " | " + // ic.getQuestionId() + ":body:" + resp.body().string()); } } finally { IOUtils.closeQuietly(resp); } } }