parent
d286a3b57c
commit
d80ddc1d4b
16 changed files with 699 additions and 118 deletions
@ -0,0 +1,25 @@ |
||||
package com.blockchain.server.yyyf.dto; |
||||
|
||||
import com.blockchain.server.yyyf.entity.AssessUser; |
||||
import com.blockchain.server.yyyf.entity.AssessUserTarget; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Mr.Xu |
||||
* @version 1.0 |
||||
* @className AssessUserDto |
||||
* @description |
||||
* @date 2020-05-14 22:07 |
||||
*/ |
||||
@Data |
||||
public class AssessUserDto extends AssessUser implements Serializable { |
||||
private static final long serialVersionUID = -4573665667880888958L; |
||||
|
||||
/** |
||||
* 指标完成情况 |
||||
**/ |
||||
private List<AssessUserTarget> assessUserTargetList; |
||||
} |
@ -0,0 +1,31 @@ |
||||
package com.blockchain.server.yyyf.dto; |
||||
|
||||
import com.blockchain.server.yyyf.entity.AssessUser; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.math.BigDecimal; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @author Mr.Xu |
||||
* @version 1.0 |
||||
* @className YyyfStudentAnswerDto |
||||
* @description |
||||
* @date 2020-05-14 22:52 |
||||
*/ |
||||
@Data |
||||
public class YyyfStudentAnswerDto implements Serializable { |
||||
private static final long serialVersionUID = 505667820932379758L; |
||||
private String authorization="87DIVy348Oxzj3ha"; |
||||
private String sysType="130"; |
||||
private Integer userId; |
||||
private Double totalScore; |
||||
private Date startTime; |
||||
private Date endTime; |
||||
private int achievementType; |
||||
private String assessmentId; |
||||
private String caseId; |
||||
private String classId; |
||||
private String courseId; |
||||
} |
@ -0,0 +1,56 @@ |
||||
package com.blockchain.server.yyyf.task; |
||||
|
||||
import com.blockchain.common.base.constant.YyyfConstant; |
||||
import com.blockchain.server.yyyf.dto.ExamDto; |
||||
import com.blockchain.server.yyyf.service.AssessUserService; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.redis.core.HashOperations; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.scheduling.annotation.EnableScheduling; |
||||
import org.springframework.scheduling.annotation.Scheduled; |
||||
|
||||
import java.util.Date; |
||||
import java.util.Iterator; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* @author Mr.Xu |
||||
* @version 1.0 |
||||
* @className ScheduleTask |
||||
* @description |
||||
* @date 2020-05-14 23:16 |
||||
*/ |
||||
@Configuration |
||||
@EnableScheduling |
||||
public class ScheduleTask { |
||||
private Logger logger = LoggerFactory.getLogger(getClass()); |
||||
@Autowired |
||||
private AssessUserService assessUserService; |
||||
|
||||
@Autowired |
||||
private RedisTemplate redisTemplate; |
||||
|
||||
@Scheduled(initialDelay = 5000,fixedRate=60000) |
||||
private void OneMinuteTask() { |
||||
logger.info("开始扫描考试"+ new Date()); |
||||
HashOperations<String, String, ExamDto> examDtoOpsForHash = redisTemplate.opsForHash(); |
||||
Map<String, ExamDto> examDtoMap = examDtoOpsForHash.entries(YyyfConstant.EXAM_KEY); |
||||
Set<Map.Entry<String, ExamDto>> entries = examDtoMap.entrySet(); |
||||
Iterator<Map.Entry<String, ExamDto>> iterator = entries.iterator(); |
||||
Date now =new Date(); |
||||
logger.info("size is " + entries.size() ); |
||||
while(iterator.hasNext()){ |
||||
Map.Entry<String, ExamDto> next = iterator.next(); |
||||
ExamDto examDto = next.getValue(); |
||||
Date endTime = examDto.getEndTime(); |
||||
if(now.after(endTime)){ |
||||
this.assessUserService.synchronousScore(examDto.getExamId()); |
||||
} |
||||
} |
||||
logger.info("完成扫描考试"+ new Date()); |
||||
} |
||||
} |
@ -0,0 +1,259 @@ |
||||
package com.blockchain.server.yyyf.utils; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.apache.http.HttpEntity; |
||||
import org.apache.http.HttpResponse; |
||||
import org.apache.http.NameValuePair; |
||||
import org.apache.http.client.config.RequestConfig; |
||||
import org.apache.http.client.entity.UrlEncodedFormEntity; |
||||
import org.apache.http.client.methods.*; |
||||
import org.apache.http.entity.StringEntity; |
||||
import org.apache.http.impl.client.CloseableHttpClient; |
||||
import org.apache.http.impl.client.HttpClientBuilder; |
||||
import org.apache.http.message.BasicNameValuePair; |
||||
import org.apache.http.util.EntityUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.net.URI; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author huan.xu |
||||
* @version 1.0 |
||||
* @className HttpClientUtil |
||||
* @description |
||||
* @date 2019-11-12 17:33 |
||||
*/ |
||||
public class HttpClientUtil { |
||||
|
||||
private static final CloseableHttpClient httpClient; |
||||
private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientUtil.class); |
||||
public static final String CHARSET = "UTF-8"; |
||||
|
||||
static { |
||||
RequestConfig config = RequestConfig.custom().setConnectTimeout(60000).setSocketTimeout(15000).build(); |
||||
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build(); |
||||
} |
||||
|
||||
public static String doGet(String url, Map<String, String> params) { |
||||
return doGet(url, params, CHARSET); |
||||
} |
||||
|
||||
public static String doPost(String url, Map<String, String> params) { |
||||
return doPost(url, params, CHARSET); |
||||
} |
||||
|
||||
public static String doPostWithJSON(String url, Object params) throws Exception { |
||||
return doPostWithJSON(url, params, CHARSET); |
||||
} |
||||
|
||||
public static String doPutWithJSON(String url, Object params) throws Exception { |
||||
return doPutWithJSON(url, params, CHARSET); |
||||
} |
||||
|
||||
public static String doDeleteWithJSON(String url, Object params) throws Exception { |
||||
return doDeleteWithJSON(url, params, CHARSET); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* HTTP Get 获取内容 |
||||
* |
||||
* @param url 请求的url地址 ?之前的地址 |
||||
* @param params 请求的参数 |
||||
* @param charset 编码格式 |
||||
* @return 页面内容 |
||||
*/ |
||||
public static String doGet(String url, Map<String, String> params, String charset) { |
||||
if (StringUtils.isBlank(url)) { |
||||
return null; |
||||
} |
||||
try { |
||||
if (params != null && !params.isEmpty()) { |
||||
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size()); |
||||
for (Map.Entry<String, String> entry : params.entrySet()) { |
||||
String value = entry.getValue(); |
||||
if (value != null) { |
||||
pairs.add(new BasicNameValuePair(entry.getKey(), value)); |
||||
} |
||||
} |
||||
url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset)); |
||||
} |
||||
HttpGet httpGet = new HttpGet(url); |
||||
CloseableHttpResponse response = httpClient.execute(httpGet); |
||||
int statusCode = response.getStatusLine().getStatusCode(); |
||||
if (statusCode != 200) { |
||||
httpGet.abort(); |
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode); |
||||
} |
||||
HttpEntity entity = response.getEntity(); |
||||
String result = null; |
||||
if (entity != null) { |
||||
result = EntityUtils.toString(entity, "utf-8"); |
||||
} |
||||
EntityUtils.consume(entity); |
||||
response.close(); |
||||
return result; |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* HTTP Post 获取内容 |
||||
* |
||||
* @param url 请求的url地址 ?之前的地址 |
||||
* @param params 请求的参数 |
||||
* @param charset 编码格式 |
||||
* @return 页面内容 |
||||
*/ |
||||
public static String doPost(String url, Map<String, String> params, String charset) { |
||||
if (StringUtils.isBlank(url)) { |
||||
return null; |
||||
} |
||||
try { |
||||
List<NameValuePair> pairs = null; |
||||
if (params != null && !params.isEmpty()) { |
||||
pairs = new ArrayList<>(params.size()); |
||||
for (Map.Entry<String, String> entry : params.entrySet()) { |
||||
String value = entry.getValue(); |
||||
if (value != null) { |
||||
pairs.add(new BasicNameValuePair(entry.getKey(), value)); |
||||
} |
||||
} |
||||
} |
||||
HttpPost httpPost = new HttpPost(url); |
||||
if (pairs != null && pairs.size() > 0) { |
||||
httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET)); |
||||
} |
||||
CloseableHttpResponse response = httpClient.execute(httpPost); |
||||
int statusCode = response.getStatusLine().getStatusCode(); |
||||
if (statusCode != 200) { |
||||
httpPost.abort(); |
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode); |
||||
} |
||||
HttpEntity entity = response.getEntity(); |
||||
String result = null; |
||||
if (entity != null) { |
||||
result = EntityUtils.toString(entity, "utf-8"); |
||||
} |
||||
EntityUtils.consume(entity); |
||||
response.close(); |
||||
return result; |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* json post |
||||
* |
||||
* @author: fengyu.wang |
||||
* @date: 2017-10-27 16:14:47 |
||||
*/ |
||||
public static String doPostWithJSON(String url, Object params, String charset) throws Exception { |
||||
LOGGER.info("doPostWithJSON -- URL:" + url); |
||||
HttpPost httpPost = new HttpPost(url); |
||||
|
||||
StringEntity entity = new StringEntity(JSON.toJSONString(params), charset); |
||||
LOGGER.info("doPostWithJSON -- params:" + JSON.toJSONString(params)); |
||||
entity.setContentEncoding(charset); |
||||
entity.setContentType("application/json"); |
||||
httpPost.setEntity(entity); |
||||
|
||||
HttpResponse response = httpClient.execute(httpPost); |
||||
int statusCode = response.getStatusLine().getStatusCode(); |
||||
if (statusCode != 200) { |
||||
httpPost.abort(); |
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode); |
||||
} |
||||
HttpEntity responseEntity = response.getEntity(); |
||||
String respContent = EntityUtils.toString(responseEntity, charset); |
||||
LOGGER.info("doPostWithJSON -- respContent:" + respContent); |
||||
return respContent; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 方法 doPostWithJSON 功能: json put |
||||
* |
||||
* @author ningning.jiang 2017年10月30日 17:11:28 |
||||
*/ |
||||
public static String doPutWithJSON(String url, Object params, String charset) throws Exception { |
||||
LOGGER.info("doPutWithJSON -- URL:" + url); |
||||
HttpPut httpPut = new HttpPut(url); |
||||
|
||||
StringEntity entity = new StringEntity(JSON.toJSONString(params), charset); |
||||
LOGGER.info("doPutWithJSON -- params:" + JSON.toJSONString(params)); |
||||
entity.setContentEncoding(charset); |
||||
entity.setContentType("application/json"); |
||||
httpPut.setEntity(entity); |
||||
|
||||
HttpResponse response = httpClient.execute(httpPut); |
||||
int statusCode = response.getStatusLine().getStatusCode(); |
||||
if (statusCode != 200) { |
||||
httpPut.abort(); |
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode); |
||||
} |
||||
HttpEntity responseEntity = response.getEntity(); |
||||
String respContent = EntityUtils.toString(responseEntity, charset); |
||||
LOGGER.info("doPutWithJSON -- respContent:" + respContent); |
||||
return respContent; |
||||
} |
||||
|
||||
/** |
||||
* 方法 doPutWithJSON 功能:delete json |
||||
* |
||||
* @author ningning.jiang 2017年10月31日 08:46:44 |
||||
*/ |
||||
public static String doDeleteWithJSON(String url, Object params, String charset) throws Exception { |
||||
LOGGER.info("doDeleteWithJSON -- URL:" + url); |
||||
HttpDeleteWithBody httpDelete = new HttpDeleteWithBody(url); |
||||
|
||||
StringEntity entity = new StringEntity(JSON.toJSONString(params), charset); |
||||
LOGGER.info("doDeleteWithJSON -- params:" + JSON.toJSONString(params)); |
||||
entity.setContentEncoding(charset); |
||||
entity.setContentType("application/json"); |
||||
httpDelete.setEntity(entity); |
||||
|
||||
HttpResponse response = httpClient.execute(httpDelete); |
||||
int statusCode = response.getStatusLine().getStatusCode(); |
||||
if (statusCode != 200) { |
||||
httpDelete.abort(); |
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode); |
||||
} |
||||
HttpEntity responseEntity = response.getEntity(); |
||||
String respContent = EntityUtils.toString(responseEntity, charset); |
||||
LOGGER.info("doDeleteWithJSON -- respContent:" + respContent); |
||||
return respContent; |
||||
} |
||||
} |
||||
|
||||
class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { |
||||
|
||||
private static final String METHOD_NAME = "DELETE"; |
||||
|
||||
public String getMethod() { |
||||
return METHOD_NAME; |
||||
} |
||||
|
||||
public HttpDeleteWithBody(final String uri) { |
||||
super(); |
||||
setURI(URI.create(uri)); |
||||
} |
||||
|
||||
public HttpDeleteWithBody(final URI uri) { |
||||
super(); |
||||
setURI(uri); |
||||
} |
||||
|
||||
public HttpDeleteWithBody() { |
||||
super(); |
||||
} |
||||
} |
Loading…
Reference in new issue