Commit b692129d by 涂亚平

拆班推送/班级里分组推送

1 parent 829fbc99
package com.subsidy.controller;
import com.subsidy.common.ResponseVO;
import com.subsidy.dto.renshe.PushClassMembersDataDTO;
import com.subsidy.service.RenSheJuService;
import com.subsidy.vo.renshe.RensheResponseVO;
import com.subsidy.vo.renshe.RensheStringVO;
......@@ -7,6 +9,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -74,4 +77,10 @@ public class RenSheJuController {
return renSheJuService.post6plus();
}
@PostMapping("pushClassMembersData")
@ApiOperation("推送某个班级前一天的数据 classId memberIds 逗号隔开")
public RensheResponseVO pushClassMembersData(@RequestBody PushClassMembersDataDTO pushClassMembersDataDTO) throws Exception{
return renSheJuService.pushClassMembersData(pushClassMembersDataDTO);
}
}
package com.subsidy.dto.renshe;
import lombok.Data;
@Data
public class PushClassMembersDataDTO {
private Long classId;
private String memberIds;
}
......@@ -35,9 +35,19 @@ public interface RenSheJuMapper {
List<Long> newClasses(String classType);
/**
* 前一天新增视频学习数据
* 前一天班级的基本信息
*/
List<DailyStudyInfoVO> dailyStudyInfo(Long classId);
List<DailyStudyInfoVO> dailyStudyInfo(Long classId,List<Long> memberIds);
/**
* 某班级去重学员
*/
List<Long> classDistinctMember(Long classId);
/**
* 查看前一天班级的数据条数
*/
Integer dataCount(Long classId);
/**
* 前一天活跃度检测列表
......@@ -131,6 +141,11 @@ public interface RenSheJuMapper {
List<Long> vodClassIds(String classType);
/**
* 产生数据班级+数据量
*/
List<VodClassIdsVO> vodClassCnt(String classType);
/**
* 产生考试数据的班级
*/
List<Long> examClassIds(String classType);
......
package com.subsidy.service;
import com.subsidy.dto.renshe.PushClassMembersDataDTO;
import com.subsidy.vo.renshe.RensheResponseVO;
import com.subsidy.vo.renshe.RensheStringVO;
......@@ -24,8 +25,8 @@ public interface RenSheJuService {
RensheStringVO clear()throws IOException;
void test();
RensheResponseVO post6plus() throws Exception ;
RensheResponseVO pushClassMembersData(PushClassMembersDataDTO pushClassMembersDataDTO) throws Exception ;
}
......@@ -12,6 +12,7 @@ import com.subsidy.model.*;
import com.subsidy.service.RenSheJuService;
import com.subsidy.util.OSSUtils;
import com.subsidy.util.RenSheJuConstant;
import com.subsidy.util.SMSUtils;
import com.subsidy.vo.renshe.*;
import net.sf.json.JSONObject;
import okhttp3.*;
......@@ -21,8 +22,9 @@ import org.springframework.stereotype.Service;
import java.io.IOException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@Service
public class RenSheJuServiceImpl implements RenSheJuService {
......@@ -42,6 +44,9 @@ public class RenSheJuServiceImpl implements RenSheJuService {
@Autowired
private ImageCheckRecordMapper imageCheckRecordMapper;
@Autowired
private SMSUtils smsUtils;
public RensheResponseVO classBaseInfo() throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
......@@ -69,7 +74,6 @@ public class RenSheJuServiceImpl implements RenSheJuService {
List<Long> imageClassIds = renSheJuMapper.imageClassIds("0");
Set<Long> classIds = new HashSet<>();
// classIds.add(490L);
vodClassIds.stream().forEach(x -> classIds.add(x));
examClassIds.stream().forEach(x -> classIds.add(x));
......@@ -153,26 +157,63 @@ public class RenSheJuServiceImpl implements RenSheJuService {
.build();
MediaType mediaType = MediaType.parse("application/json");
ClassHourBehaviorDTO classHourBehaviorDTO = new ClassHourBehaviorDTO();
// 产生视频学习数据的班级
List<VodClassIdsVO> vodClassIdsVOS = renSheJuMapper.vodClassCnt("0");
for (VodClassIdsVO vodClassIdsVO : vodClassIdsVOS) {
ClassHourBehaviorDTO classHourBehaviorDTO = new ClassHourBehaviorDTO();
classHourBehaviorDTO.setPrivateKey(getSecret());
List<ClassHourBasic> classHourBasics = new ArrayList<>();
// 产生视频学习数据的班级
List<Long> vodClassIds = renSheJuMapper.vodClassIds("0");
// List<Long> vodClassIds = new ArrayList<>();
// vodClassIds.add(537L);
//查看该班级今天产生的数据条数
int count = renSheJuMapper.dataCount(vodClassIdsVO.getClassId());
List<Long> longs = renSheJuMapper.classDistinctMember(vodClassIdsVO.getClassId());
if (count > 300) {
//某班级前一天数据人员去重
int times = (int) Math.ceil((double) count / 300);
int block = (int) Math.ceil((double) longs.size() / times);
List<List<Long>> devide = devide(longs, block);
for (List<Long> memberIds : devide) {
try {
sendStudyData(client, mediaType, classHourBehaviorDTO, vodClassIdsVO.getClassId(), memberIds);
} catch (Exception e) {
e.printStackTrace();
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_4);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(classHourBehaviorDTO).toString());
renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_FAIL);
renshejuHistoryMapper.insert(renshejuHistoryDO);
List<String> telephones = Arrays.asList("15201936167", "18201963812");
for (String telephone : telephones) {
smsUtils.sendWarning("SMS_460945631", telephone, RenSheJuConstant.POST_3);
}
}
}
} else {
try {
sendStudyData(client, mediaType, classHourBehaviorDTO, vodClassIdsVO.getClassId(), longs);
} catch (Exception e) {
e.printStackTrace();
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_4);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(classHourBehaviorDTO).toString());
renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_FAIL);
renshejuHistoryMapper.insert(renshejuHistoryDO);
List<String> telephones = Arrays.asList("15201936167", "18201963812");
for (String telephone : telephones) {
smsUtils.sendWarning("SMS_460945631", telephone, "3");
}
}
}
}
return null;
}
List<DailyStudyInfoVO> result = new ArrayList<>();
public void sendStudyData(OkHttpClient client, MediaType mediaType, ClassHourBehaviorDTO classHourBehaviorDTO, Long classId, List<Long> memberIds) throws Exception {
try {
for (Long classId : vodClassIds) {
List<ClassHourBasic> classHourBasics = new ArrayList<>();
//产生数据的班级
List<DailyStudyInfoVO> dailyStudyInfoVOS = renSheJuMapper.dailyStudyInfo(classId);
result.addAll(dailyStudyInfoVOS);
}
for (DailyStudyInfoVO dailyStudyInfoVO : result) {
List<DailyStudyInfoVO> dailyStudyInfoVOS = renSheJuMapper.dailyStudyInfo(classId, memberIds);
for (DailyStudyInfoVO dailyStudyInfoVO : dailyStudyInfoVOS) {
ClassHourBasic classHourBasic = new ClassHourBasic();
BeanUtils.copyProperties(dailyStudyInfoVO, classHourBasic);
classHourBasic.setClassCode(dailyStudyInfoVO.getClassCode());
......@@ -218,9 +259,9 @@ public class RenSheJuServiceImpl implements RenSheJuService {
classHourBasic.setActivityList(activityLists);
classHourBasics.add(classHourBasic);
}
classHourBehaviorDTO.setClassHourBasic(classHourBasics);
System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(classHourBehaviorDTO));
classHourBehaviorDTO.setClassHourBasic(classHourBasics);
// System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(classHourBehaviorDTO));
if (classHourBasics.size() > 0) {
RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(classHourBehaviorDTO).toString());
......@@ -242,7 +283,7 @@ public class RenSheJuServiceImpl implements RenSheJuService {
renshejuHistoryDO.setOutputParam(RenSheJuConstant.API_ERROR);
}
renshejuHistoryMapper.insert(renshejuHistoryDO);
return rensheResponseVO;
classHourBasics.clear();
} else {
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_4);
......@@ -250,23 +291,9 @@ public class RenSheJuServiceImpl implements RenSheJuService {
renshejuHistoryDO.setOutputParam(RenSheJuConstant.NO_DATA);
renshejuHistoryMapper.insert(renshejuHistoryDO);
}
// return null;
} catch (Exception e) {
e.printStackTrace();
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_4);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(classHourBehaviorDTO).toString());
renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_FAIL);
renshejuHistoryMapper.insert(renshejuHistoryDO);
List<String> telephones = Arrays.asList("15201936167", "18201963812");
// for (String telephone : telephones) {
// smsUtils.sendWarning("SMS_460945631", telephone, RenSheJuConstant.POST_3);
// }
}
return null;
}
public RensheResponseVO uploadChapterBehavior() throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
......@@ -690,7 +717,7 @@ public class RenSheJuServiceImpl implements RenSheJuService {
List<Long> classIds = new ArrayList<>();
classIds.add(477L);
// classIds.add(477L);
for (Long classId : classIds) {
......@@ -780,6 +807,123 @@ public class RenSheJuServiceImpl implements RenSheJuService {
return rensheStringVO;
}
public RensheResponseVO pushClassMembersData(PushClassMembersDataDTO pushClassMembersDataDTO) throws Exception {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
// 产生视频学习数据的班级
ClassHourBehaviorDTO classHourBehaviorDTO = new ClassHourBehaviorDTO();
classHourBehaviorDTO.setPrivateKey(getSecret());
//查看该班级今天产生的数据条数
List<Long> memberIds = new ArrayList<>();
String[] strings = pushClassMembersDataDTO.getMemberIds().split(",");
for (String string : strings) {
memberIds.add(Long.valueOf(string));
}
try {
List<ClassHourBasic> classHourBasics = new ArrayList<>();
//产生数据的班级
List<DailyStudyInfoVO> dailyStudyInfoVOS = renSheJuMapper.dailyStudyInfo(pushClassMembersDataDTO.getClassId(), memberIds);
for (DailyStudyInfoVO dailyStudyInfoVO : dailyStudyInfoVOS) {
ClassHourBasic classHourBasic = new ClassHourBasic();
BeanUtils.copyProperties(dailyStudyInfoVO, classHourBasic);
classHourBasic.setClassCode(dailyStudyInfoVO.getClassCode());
//找到当天每次上线下线时间
//上线时间
List<OprMemDictDO> loginRecords = renSheJuMapper.loginRecords(dailyStudyInfoVO.getMemberId());
//下线时间
List<OprMemDictDO> loginOutRecords = renSheJuMapper.loginOutRecords(dailyStudyInfoVO.getMemberId());
List<LoginList> loginLists = new ArrayList<>();
for (int i = 0; i < loginRecords.size(); i++) {
LoginList loginList = new LoginList();
loginList.setIp(loginRecords.get(i).getIpAddress());
loginList.setStartTime(Timestamp.valueOf(loginRecords.get(i).getCreateDate()).getTime());
loginList.setEndTime(Timestamp.valueOf(loginOutRecords.get(i).getCreateDate()).getTime());
//查看这个人该时间段的学习记录
List<ChapterList3> chapterList3s = renSheJuMapper.dailyStudyRecords(dailyStudyInfoVO.getMemberId(), dailyStudyInfoVO.getClassId(), loginRecords.get(i).getCreateDate().toString().replace("T", " "), loginOutRecords.get(i).getCreateDate().toString().replace("T", " "));
if (chapterList3s.size() > 0) {
loginList.setChapterList(chapterList3s);
loginLists.add(loginList);
}
}
classHourBasic.setLoginList(loginLists);
//活跃度列表
List<ActivityList> activityLists = new ArrayList<>();
List<DailyActivitiesVO> activityDetectionDOS = renSheJuMapper.dailyActivities(dailyStudyInfoVO.getClassId(), dailyStudyInfoVO.getMemberId());
for (DailyActivitiesVO dailyActivitiesVO : activityDetectionDOS) {
ActivityList activityList = new ActivityList();
if (0 == dailyActivitiesVO.getCheckType()) {
activityList.setActivityDetection(2);
} else if (1 == dailyActivitiesVO.getCheckType()) {
activityList.setActivityDetection(1);
}
activityList.setActivityTime(dailyActivitiesVO.getActivityTime());
activityLists.add(activityList);
}
classHourBasic.setActivityList(activityLists);
classHourBasics.add(classHourBasic);
}
classHourBehaviorDTO.setClassHourBasic(classHourBasics);
System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(classHourBehaviorDTO));
if (classHourBasics.size() > 0) {
RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(classHourBehaviorDTO).toString());
Request request = new Request.Builder()
.url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadClassHourBehavior")
.method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_4);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(classHourBehaviorDTO).toString());
if (200 == response.code()) {
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString());
} else {
renshejuHistoryDO.setOutputParam(RenSheJuConstant.API_ERROR);
}
renshejuHistoryMapper.insert(renshejuHistoryDO);
classHourBasics.clear();
} else {
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_4);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(classHourBehaviorDTO).toString());
renshejuHistoryDO.setOutputParam(RenSheJuConstant.NO_DATA);
renshejuHistoryMapper.insert(renshejuHistoryDO);
}
} catch (Exception e) {
e.printStackTrace();
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_4);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(classHourBehaviorDTO).toString());
renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_FAIL);
renshejuHistoryMapper.insert(renshejuHistoryDO);
List<String> telephones = Arrays.asList("15201936167", "18201963812");
for (String telephone : telephones) {
smsUtils.sendWarning("SMS_460945631", telephone, RenSheJuConstant.POST_3);
}
}
return null;
}
public String getSecret() throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
......@@ -811,13 +955,25 @@ public class RenSheJuServiceImpl implements RenSheJuService {
// String s = JSONObject.fromObject(getSecretVO).toString();
// System.out.println(s);
LocalDateTime localDateTime = LocalDateTime.now();
System.out.println(localDateTime.toString());
// LocalDateTime localDateTime = LocalDateTime.now();
// System.out.println(localDateTime.toString());
// int ttl = 1600;
// int memCnt = 173;
// System.out.println((int) Math.ceil((double) ttl / 500) + "=============");
System.out.println(devide(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), 3));
}
public void test() {
System.out.println("132222222222222222222222222222");
public static <T> List<List<T>> devide(List<T> origin, int size) {
int block = (origin.size() + size - 1) / size;
return IntStream.range(0, block)
.boxed().map(i -> {
int start = i * size;
int end = Math.min(start + size, origin.size());
return origin.subList(start, end);
}).collect(Collectors.toList());
}
}
\ No newline at end of file
package com.subsidy.vo.renshe;
import lombok.Data;
@Data
public class VodClassIdsVO {
private Long classId;
private String classCode;
private Integer cnt;
}
......@@ -96,8 +96,36 @@
t.delete_date IS NULL
AND t3.delete_date IS NULL
AND t.class_id = #{classId}
<if test="memberIds != null and memberIds.size>0">
and t.member_id in
<foreach collection="memberIds" item="id" index="index" open="(" close=")" separator=",">
#{id}
</foreach>
</if>
</select>
<select id="classDistinctMember" parameterType="long" resultType="long">
SELECT DISTINCT
t.member_id
FROM
vod_play_history t
WHERE
t.class_id = #{classId}
AND t.delete_date IS NULL
AND DATE_FORMAT( DATE_ADD( t.create_date, interval 1 DAY ), '%Y-%m-%d' ) = DATE_FORMAT( NOW(), '%Y-%m-%d' )
</select>
<select id="dataCount" parameterType="long" resultType="integer">
SELECT
count( 0 )
FROM
vod_play_history t
LEFT JOIN class_dict t2 ON t.class_id = t2.id
WHERE
t.delete_date IS NULL
AND DATE_FORMAT( DATE_ADD( t.create_date, interval 1 DAY ), '%Y-%m-%d' ) = DATE_FORMAT( NOW(), '%Y-%m-%d' )
and t2.id = #{classId}
</select>
<select id="dailyActivities" resultType="com.subsidy.vo.renshe.DailyActivitiesVO">
SELECT
......@@ -429,6 +457,23 @@
AND t.class_type = #{classType}
</select>
<select id="vodClassCnt" parameterType="string" resultType="com.subsidy.vo.renshe.VodClassIdsVO">
SELECT
class_id,
t2.class_code,
count( 0 )
FROM
vod_play_history t
LEFT JOIN class_dict t2 ON t.class_id = t2.id
WHERE
t.delete_date IS NULL
AND DATE_FORMAT( DATE_ADD( t.create_date, interval 1 DAY ), '%Y-%m-%d' ) = DATE_FORMAT( NOW(), '%Y-%m-%d' )
AND t2.class_type = #{classType}
GROUP BY
class_id,
t2.class_code
</select>
<select id="examClassIds" parameterType="string" resultType="long">
SELECT
t.id
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!