mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-14 05:16:49 +08:00
获取用户受众的处理
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
package com.xboe.data.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 受众人员
|
||||||
|
* @author seastar
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class AudienceUser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的统一id
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的姓名
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的代码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.xboe.data.outside;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.xboe.data.dto.AudienceUser;
|
||||||
|
|
||||||
|
public interface IOutSideDataService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取受众的所有用户
|
||||||
|
* @param task
|
||||||
|
*/
|
||||||
|
List<AudienceUser> getUsersByAudienceId(String audienceId);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package com.xboe.data.outside;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.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.data.dto.AudienceUser;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
@Slf4j
|
||||||
|
public class OutSideDataServiceImpl implements IOutSideDataService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HttpServletRequest request;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OkHttpUtil okHttpUtil;
|
||||||
|
|
||||||
|
|
||||||
|
private String getNodeText(JsonNode jn) {
|
||||||
|
if(jn!=null) {
|
||||||
|
return jn.asText();
|
||||||
|
}else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AudienceUser> getUsersByAudienceId(String audienceId){
|
||||||
|
String token = TokenProxy.getToken(request);
|
||||||
|
String type="application/json";
|
||||||
|
String[] headers=new String[] {"token",token,"Content-Type",type};
|
||||||
|
String url= SysConstant.getConfigValue("xboe.old.base.url")+"/userbasic/audience/memberList";
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
params.put("audienceId", "");
|
||||||
|
String json = null;
|
||||||
|
List<AudienceUser> list=new ArrayList<AudienceUser>();
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
try {
|
||||||
|
|
||||||
|
json = mapper.writeValueAsString(params);
|
||||||
|
|
||||||
|
String responseStr = okHttpUtil.doPostJson(url, json, headers);
|
||||||
|
JsonNode rootNode= mapper.readTree(responseStr);
|
||||||
|
|
||||||
|
|
||||||
|
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()) {
|
||||||
|
//这里应该是单独的线程去处理
|
||||||
|
for(JsonNode JsonNode :result) {
|
||||||
|
AudienceUser au=new AudienceUser();
|
||||||
|
au.setId(result.get("id").asText());
|
||||||
|
au.setName(getNodeText(result.get("userName")));
|
||||||
|
au.setCode(getNodeText(result.get("userNo")));
|
||||||
|
list.add(au);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取受众用户列表错误",e);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
package com.xboe.outsize.api;
|
|
||||||
|
|
||||||
import com.xboe.common.utils.StringUtil;
|
|
||||||
import com.xboe.core.JsonResponse;
|
|
||||||
import com.xboe.core.api.ApiBaseController;
|
|
||||||
import com.xboe.core.log.AutoLog;
|
|
||||||
import com.xboe.module.exam.dto.ExamTestDto;
|
|
||||||
import com.xboe.module.exam.entity.ExamUserTask;
|
|
||||||
import com.xboe.module.exam.service.IExamUserTaskService;
|
|
||||||
import com.xboe.outsize.service.IuserGroupTaskService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping(value = "/xboe/m/oldusergroup/task")
|
|
||||||
public class userGroupTaskApi extends ApiBaseController {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private IExamUserTaskService service;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private IuserGroupTaskService iuserGroupTaskService;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*考试的推送记录
|
|
||||||
**/
|
|
||||||
// @PostMapping("/list")
|
|
||||||
// public JsonResponse<List<ExamUserTask>> list(String testId){
|
|
||||||
// List<ExamUserTask> list = service.findByTestId(testId);
|
|
||||||
// return success(list);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @PostMapping("/check-paper")
|
|
||||||
// public JsonResponse<Boolean> checkByPaperId(String paperId){
|
|
||||||
// if(StringUtils.isBlank(paperId)) {
|
|
||||||
// return badRequest("参数错误,未指定试卷id");
|
|
||||||
// }
|
|
||||||
// boolean ok=service.hasByPaperId(paperId);
|
|
||||||
// return success(ok);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行推送处理
|
|
||||||
* */
|
|
||||||
@PostMapping("execute")
|
|
||||||
@AutoLog(module = "考试管理",action = "推送考试",info = "")
|
|
||||||
public JsonResponse<Boolean> save(ExamTestDto task){
|
|
||||||
if(StringUtil.isBlank(task.getTestId())){
|
|
||||||
return badRequest("未指定考虑");
|
|
||||||
}
|
|
||||||
if(StringUtil.isBlank(task.getTestName())){
|
|
||||||
return badRequest("缺少考试标题");
|
|
||||||
}
|
|
||||||
if(StringUtil.isBlank(task.getGroupId())){
|
|
||||||
return badRequest("未指定受众");
|
|
||||||
}
|
|
||||||
ExamUserTask hasTask=service.findByTestIdAndGroupId(task.getTestId(),task.getGroupId());
|
|
||||||
|
|
||||||
try {
|
|
||||||
if(hasTask!=null) {
|
|
||||||
//return badRequest("此受众已推送过了,不能重复推送");
|
|
||||||
iuserGroupTaskService.rePushTask(task);
|
|
||||||
}else {
|
|
||||||
iuserGroupTaskService.addTask(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
return success(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("推送考试错误",e);
|
|
||||||
return error("推送考试失败",e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.xboe.outsize.service;
|
|
||||||
|
|
||||||
import com.xboe.module.exam.dto.ExamTestDto;
|
|
||||||
|
|
||||||
public interface IuserGroupTaskService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 推送
|
|
||||||
* @param task
|
|
||||||
*/
|
|
||||||
void addTask(ExamTestDto task);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 再次推送同一个任务
|
|
||||||
* @param task
|
|
||||||
*/
|
|
||||||
void rePushTask(ExamTestDto task);
|
|
||||||
}
|
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
package com.xboe.outsize.service.impl;
|
|
||||||
|
|
||||||
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.orm.FieldFilters;
|
|
||||||
import com.xboe.core.utils.OkHttpUtil;
|
|
||||||
import com.xboe.module.exam.dao.AloneExamDao;
|
|
||||||
import com.xboe.module.exam.dto.ExamTestDto;
|
|
||||||
import com.xboe.module.exam.entity.AloneExam;
|
|
||||||
import com.xboe.module.exam.entity.AloneExamAnswer;
|
|
||||||
import com.xboe.module.exam.entity.ExamUserTask;
|
|
||||||
import com.xboe.module.exam.service.IExamUserTaskService;
|
|
||||||
import com.xboe.module.usergroup.entity.UserGroupItem;
|
|
||||||
import com.xboe.outsize.service.IuserGroupTaskService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Transactional
|
|
||||||
@Slf4j
|
|
||||||
public class UserGroupTaskServiceImpl implements IuserGroupTaskService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private HttpServletRequest request;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private OkHttpUtil okHttpUtil;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private AloneExamDao aloneExamDao;
|
|
||||||
|
|
||||||
private String getNodeText(JsonNode jn) {
|
|
||||||
if(jn!=null) {
|
|
||||||
return jn.asText();
|
|
||||||
}else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addTask(ExamTestDto task) {
|
|
||||||
String token = TokenProxy.getToken(request);
|
|
||||||
String type="application/json";
|
|
||||||
String[] headers=new String[] {"token",token,"Content-Type",type};
|
|
||||||
String url= SysConstant.getConfigValue("xboe.old.base.url")+"/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(JsonNode JsonNode :result) {
|
|
||||||
if(amap.containsKey(result.get("userId"))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//检查是否存在
|
|
||||||
AloneExam aloneExam = new AloneExam();
|
|
||||||
aloneExam.setAid(getNodeText(result.get("personId")));
|
|
||||||
aloneExam.setTestId(task.getTestId());
|
|
||||||
aloneExam.setTestName(task.getTestName());
|
|
||||||
aloneExam.setName(getNodeText(result.get("userName")));
|
|
||||||
aloneExam.setUcode(getNodeText(result.get("userNo")));
|
|
||||||
aloneExam.setTestDuration(task.getDuration());
|
|
||||||
aloneExam.setTaskTime(LocalDateTime.now());
|
|
||||||
aloneExam.setStartTime(task.getStartTime());
|
|
||||||
aloneExam.setStatus(AloneExamAnswer.STATUS_NONE);//未考试过
|
|
||||||
aloneExam.setScore(0f);
|
|
||||||
aloneExamDao.save(aloneExam);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// examUserTask.setStatus(ExamUserTask.STATUS_FINISH);
|
|
||||||
// dao.update(examUserTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void rePushTask(ExamTestDto task) {
|
|
||||||
//查询受众的信息,2022、11、30 这个的返回需要从接口获取人员信息,然后推送
|
|
||||||
// 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("xboe.old.base.url")+"/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(JsonNode JsonNode :result) {
|
|
||||||
if(amap.containsKey(result.get("userId"))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//检查是否存在
|
|
||||||
AloneExam aloneExam = new AloneExam();
|
|
||||||
aloneExam.setAid(getNodeText(result.get("personId")));
|
|
||||||
aloneExam.setTestId(task.getTestId());
|
|
||||||
aloneExam.setTestName(task.getTestName());
|
|
||||||
aloneExam.setName(getNodeText(result.get("userName")));
|
|
||||||
aloneExam.setUcode(getNodeText(result.get("userNo")));
|
|
||||||
aloneExam.setTestDuration(task.getDuration());
|
|
||||||
aloneExam.setTaskTime(LocalDateTime.now());
|
|
||||||
aloneExam.setStartTime(task.getStartTime());
|
|
||||||
aloneExam.setStatus(AloneExamAnswer.STATUS_NONE);//未考试过
|
|
||||||
aloneExam.setScore(0f);
|
|
||||||
aloneExamDao.update(aloneExam);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//examUserTask.setStatus(ExamUserTask.STATUS_FINISH);
|
|
||||||
//dao.update(examUserTask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user