mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-08 18:36:51 +08:00
暂时先提交
This commit is contained in:
@@ -1,12 +1,27 @@
|
||||
package com.xboe.module.exam.service.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xboe.core.SysConstant;
|
||||
import com.xboe.core.api.TokenProxy;
|
||||
import com.xboe.core.utils.OkHttpUtil;
|
||||
import com.xboe.standard.BaseConstant;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
@@ -25,6 +40,7 @@ import com.xboe.module.usergroup.dao.UserGroupItemDao;
|
||||
import com.xboe.module.usergroup.entity.UserGroupItem;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ExamUserTaskServiceImpl implements IExamUserTaskService{
|
||||
|
||||
@Resource
|
||||
@@ -42,6 +58,85 @@ public class ExamUserTaskServiceImpl implements IExamUserTaskService{
|
||||
@Resource
|
||||
AloneExamDao aloneExamDao;
|
||||
|
||||
@Resource
|
||||
private OkHttpUtil okHttpUtil;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
|
||||
|
||||
private static final String oldUserGoupItem="xboe.old.base.url";
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// String token = "eyJ0eXBlIjoidG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC91LmJvZS5jb20iLCJpYXQiOjE2Njk4MDM2OTMsImV4cCI6MTY2OTgxMDg5MywiR2l2ZW5OYW1lIjoiYm9ldSIsInVzZXJJZCI6IjAxNTU1M0RELTQ0NUUtNjlENC0zNTFGLUREOUExQTU2NDIwRSIsInVJZCI6Ijk2NTM0MTk5OTY0MzIzNDMwNCIsInBlcm1pc3Npb24iOiIifQ==.2dff2cc8262affb5bfdf8c96325e71ab2178ebc45b0228f23958263160f7464f";
|
||||
// String type="application/json";
|
||||
// String[] headers=new String[] {"token",token,"Content-Type",type};
|
||||
// String url= "https://u-pre.boe.com/userbasic/audience/memberList";
|
||||
// System.out.println(url);
|
||||
// Map<String, String> params = new HashMap<>();
|
||||
// params.put("audienceId", "7002943034057035777");
|
||||
//
|
||||
// String json = null;
|
||||
// try {
|
||||
// ObjectMapper mapper=new ObjectMapper();
|
||||
// json = mapper.writeValueAsString(params);
|
||||
// } catch (JsonProcessingException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// RequestBody requestBody = RequestBody.create(JSON, json);
|
||||
//
|
||||
// Request.Builder postBuilder = new Request.Builder();
|
||||
// postBuilder.addHeader("Connection", "close");
|
||||
// if (headers != null && headers.length > 0) {
|
||||
// if (headers.length % 2 == 0) {
|
||||
// for (int i = 0; i < headers.length; i = i + 2) {
|
||||
// postBuilder.addHeader(headers[i], headers[i + 1]);
|
||||
// }
|
||||
// } else {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// Request request = postBuilder.url(url).post(requestBody).build();
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// System.out.println(request.headers());
|
||||
// OkHttpClient okHttpClient=new OkHttpClient();
|
||||
// try {
|
||||
// Response execute = okHttpClient.newCall(request).execute();
|
||||
// String json = null;
|
||||
// try {
|
||||
// ObjectMapper mapper=new ObjectMapper();
|
||||
// json = mapper.writeValueAsString(params);
|
||||
// } catch (JsonProcessingException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// System.out.println(execute.body().string());
|
||||
//
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
private String getNodeText(JsonNode jn) {
|
||||
if(jn!=null) {
|
||||
return jn.asText();
|
||||
}else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void addTask(ExamTestDto task) {
|
||||
@@ -56,23 +151,46 @@ public class ExamUserTaskServiceImpl implements IExamUserTaskService{
|
||||
dao.save(examUserTask);
|
||||
//执行推送,当前因为是固定人,所以这里直接添加处理,按受众添加到每个人中
|
||||
//查询受众的信息
|
||||
List<UserGroupItem> items = ugroupDao.findList("groupId", task.getGroupId());
|
||||
if(items.size()>0) {
|
||||
// List<UserGroupItem> items = ugroupDao.findList("groupId", task.getGroupId());
|
||||
String token = TokenProxy.getToken(request);
|
||||
String type="application/json";
|
||||
String[] headers=new String[] {"token",token,"Content-Type",type};
|
||||
String url= SysConstant.getConfigValue(oldUserGoupItem)+"/userbasic/audience/memberList";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("audienceId", "");
|
||||
String json = null;
|
||||
try {
|
||||
ObjectMapper mapper=new ObjectMapper();
|
||||
json = mapper.writeValueAsString(params);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String responseStr = okHttpUtil.doPostJson(url, json, headers);
|
||||
JsonNode rootNode=null;
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
rootNode = objectMapper.readTree(responseStr);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("结构解析错误");
|
||||
}
|
||||
|
||||
JsonNode result = rootNode.get("result")!=null ?( rootNode.get("result").get("data") !=null ? rootNode.get("result").get("data"):null):null;
|
||||
if(rootNode.get("result")!=null & rootNode.get("result").isArray()) {
|
||||
//防止加入两条的问题,应该是先查询,再添加
|
||||
Map<String,Object> amap= aloneExamDao.findMap("aid", "name",FieldFilters.eq("testId", task.getTestId()));
|
||||
|
||||
//这里应该是单独的线程去处理
|
||||
for(UserGroupItem item :items) {
|
||||
if(amap.containsKey(item.getAid())) {
|
||||
for(JsonNode JsonNode :result) {
|
||||
if(amap.containsKey(result.get("userId"))) {
|
||||
continue;
|
||||
}
|
||||
//检查是否存在
|
||||
AloneExam aloneExam = new AloneExam();
|
||||
aloneExam.setAid(item.getAid());
|
||||
aloneExam.setAid(getNodeText(result.get("personId")));
|
||||
aloneExam.setTestId(task.getTestId());
|
||||
aloneExam.setTestName(task.getTestName());
|
||||
aloneExam.setName(item.getName());
|
||||
aloneExam.setUcode(item.getUserNo());
|
||||
aloneExam.setName(getNodeText(result.get("userName")));
|
||||
aloneExam.setUcode(getNodeText(result.get("userNo")));
|
||||
aloneExam.setTestDuration(task.getDuration());
|
||||
aloneExam.setTaskTime(LocalDateTime.now());
|
||||
aloneExam.setStartTime(task.getStartTime());
|
||||
|
||||
Reference in New Issue
Block a user