|
@@ -14,9 +14,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.zhongzheng.common.core.domain.entity.SysUser;
|
|
|
import com.zhongzheng.common.core.redis.RedisCache;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.type.EncryptHandler;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.common.utils.ServletUtils;
|
|
|
+import com.zhongzheng.common.utils.file.FileUtils;
|
|
|
import com.zhongzheng.common.utils.http.HttpUtils;
|
|
|
+import com.zhongzheng.common.utils.poi.ExcelUtil;
|
|
|
+import com.zhongzheng.modules.alioss.bo.OssRequest;
|
|
|
+import com.zhongzheng.modules.alioss.service.OssService;
|
|
|
import com.zhongzheng.modules.alisms.vo.ResultBean;
|
|
|
import com.zhongzheng.modules.base.service.IProfileTpService;
|
|
|
import com.zhongzheng.modules.base.vo.ProfileTpVo;
|
|
@@ -98,7 +103,9 @@ import com.zhongzheng.modules.polyv.service.IPolyvLiveService;
|
|
|
import com.zhongzheng.modules.schedule.service.IScheduleService;
|
|
|
import com.zhongzheng.modules.system.bo.SysTenantBadBillConfigBo;
|
|
|
import com.zhongzheng.modules.system.bo.SysTenantQueryBo;
|
|
|
+import com.zhongzheng.modules.system.domain.SysTask;
|
|
|
import com.zhongzheng.modules.system.domain.SysTenant;
|
|
|
+import com.zhongzheng.modules.system.service.ISysTaskService;
|
|
|
import com.zhongzheng.modules.system.service.ISysTenantService;
|
|
|
import com.zhongzheng.modules.system.service.ISysUserService;
|
|
|
import com.zhongzheng.modules.system.vo.SysTenantVo;
|
|
@@ -128,7 +135,14 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
@@ -136,6 +150,7 @@ import java.time.ZoneId;
|
|
|
import java.time.ZonedDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* 定时任务
|
|
@@ -328,6 +343,10 @@ public class ScheduleServiceImpl extends ServiceImpl<PolyvVideoMapper, PolyvVide
|
|
|
private ICourseProjectTypeService iCourseProjectTypeService;
|
|
|
@Autowired
|
|
|
private ICourseBusinessService iCourseBusinessService;
|
|
|
+ @Autowired
|
|
|
+ private ISysTaskService iSysTaskService;
|
|
|
+ @Autowired
|
|
|
+ private OssService ossService;
|
|
|
|
|
|
|
|
|
@Value("${aliyun.sms.OpenTheGoodsCode}")
|
|
@@ -1815,6 +1834,202 @@ public class ScheduleServiceImpl extends ServiceImpl<PolyvVideoMapper, PolyvVide
|
|
|
iUserStudyRecordService.syncUserDateStudyLog();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void usbUserDownload() {
|
|
|
+ int count = iSysTaskService
|
|
|
+ .count(new LambdaQueryWrapper<SysTask>()
|
|
|
+ .eq(SysTask::getStatus, 1)
|
|
|
+ .eq(SysTask::getTaskStatus, 2));
|
|
|
+ if (count > 0){
|
|
|
+ //已有任务在执行中 不同步执行
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SysTask task = iSysTaskService.getOne(new LambdaQueryWrapper<SysTask>()
|
|
|
+ .eq(SysTask::getTaskStatus, 1)
|
|
|
+ .eq(SysTask::getStatus, 1)
|
|
|
+ .orderByAsc(SysTask::getCreateTime)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (ObjectUtils.isNull(task)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //执行下载任务
|
|
|
+ SubUserExportBo subUserExportBo = JSONObject.parseObject(task.getTaskParam(), SubUserExportBo.class);
|
|
|
+ List<UserSubscribe> subscribeList = iUserSubscribeService.listByTimeNoTenant(subUserExportBo);
|
|
|
+ if (CollectionUtils.isEmpty(subscribeList)){
|
|
|
+ task.setTaskStatus(3);//完成
|
|
|
+ iSysTaskService.updateById(task);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ task.setTaskStatus(2);//执行中
|
|
|
+ iSysTaskService.updateById(task);
|
|
|
+ String zhiyuan = System.getProperty("user.dir");
|
|
|
+ String destDirPath = zhiyuan+"/zhongzheng-admin/src/main/resources/"
|
|
|
+ +String.format("%s预约考试",DateUtils.timestampToDateFormat(subUserExportBo.getApplyTime(),"yyyy-MM-dd"));
|
|
|
+ List<UserStudyRecordExport> recordExports = new ArrayList<>();
|
|
|
+ for (int i = 0; i < subscribeList.size(); i++) {
|
|
|
+ UserSubscribe item = subscribeList.get(i);
|
|
|
+ User user = iUserService.getByIdNoTenant(item.getUserId());
|
|
|
+ String userPhotoPath = destDirPath+"/"+user.getRealname()+"/"+"个人相片";
|
|
|
+ File dirw = new File(userPhotoPath);
|
|
|
+ if (!dirw.exists()){
|
|
|
+ dirw.mkdirs();
|
|
|
+ }
|
|
|
+ //获取个人近照和身份证照片
|
|
|
+ try {
|
|
|
+ InputStream inputStream = ossService.getStreamByObject(user.getOneInchPhotos());
|
|
|
+ //写入本地文件
|
|
|
+ String inchPath = userPhotoPath + "/"+String.format("%s$头像.jpg", EncryptHandler.decrypt(user.getIdCard()));
|
|
|
+ FileOutputStream fileOutputStream = new FileOutputStream(inchPath);
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int len = 0;
|
|
|
+ while ((len = inputStream.read(buffer)) != -1) {
|
|
|
+ fileOutputStream.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ inputStream.close();
|
|
|
+ fileOutputStream.close();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ InputStream inputStream = ossService.getStreamByObject(user.getIdCardImg2());
|
|
|
+ //写入本地文件
|
|
|
+ String cardPath1 = userPhotoPath + "/"+String.format("%s身份证反面.jpg", user.getRealname());
|
|
|
+ FileOutputStream fileOutputStream = new FileOutputStream(cardPath1);
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int len = 0;
|
|
|
+ while ((len = inputStream.read(buffer)) != -1) {
|
|
|
+ fileOutputStream.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ inputStream.close();
|
|
|
+ fileOutputStream.close();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ InputStream inputStream = ossService.getStreamByObject(user.getIdCardImg1());
|
|
|
+ //写入本地文件
|
|
|
+ String cardPath2 = userPhotoPath + "/"+String.format("%s身份证正面.jpg", user.getRealname());
|
|
|
+ FileOutputStream fileOutputStream = new FileOutputStream(cardPath2);
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int len = 0;
|
|
|
+ while ((len = inputStream.read(buffer)) != -1) {
|
|
|
+ fileOutputStream.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ inputStream.close();
|
|
|
+ fileOutputStream.close();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ //学习照片
|
|
|
+ OrderGoods orderGoods = iOrderGoodsService.getByIdNoTenant(item.getOrderGoodsId());
|
|
|
+ Goods goods = iGoodsService.getGoodsByIdNotTenant(orderGoods.getGoodsId());
|
|
|
+ String goodsPath = destDirPath+"/"+user.getRealname()+"/"+goods.getGoodsName();
|
|
|
+ File dirw2 = new File(goodsPath);
|
|
|
+ if (!dirw2.exists()){
|
|
|
+ dirw2.mkdirs();
|
|
|
+ }
|
|
|
+ List<UserStudyRecord> recordList = iUserStudyRecordService.getStudyRecordNoTenant(orderGoods.getOrderGoodsId());
|
|
|
+ if (CollectionUtils.isEmpty(recordList)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<Long, List<UserStudyRecord>> map = recordList.stream().collect(Collectors.groupingBy(UserStudyRecord::getSectionId));
|
|
|
+ map.forEach((k,v) -> {
|
|
|
+ CourseSection section = iCourseSectionService.getSectionByNotTenant(k);
|
|
|
+ String sectionPath = goodsPath+"/"+section.getName();
|
|
|
+ File dirw3 = new File(sectionPath);
|
|
|
+ if (!dirw3.exists()){
|
|
|
+ dirw3.mkdirs();
|
|
|
+ }
|
|
|
+ //视频拍照信息
|
|
|
+ v.stream().filter(x -> ObjectUtils.isNotNull(x.getPhoto())).forEach(photo -> {
|
|
|
+ try {
|
|
|
+ InputStream inputStream = ossService.getStreamByObject(photo.getPhoto());
|
|
|
+ //写入本地文件
|
|
|
+ String photoPath1 = sectionPath + "/"+String.format("%s.jpg",DateUtils.getNowTime());
|
|
|
+ FileOutputStream fileOutputStream = new FileOutputStream(photoPath1);
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int len = 0;
|
|
|
+ while ((len = inputStream.read(buffer)) != -1) {
|
|
|
+ fileOutputStream.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ inputStream.close();
|
|
|
+ fileOutputStream.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ //学习记录
|
|
|
+ List<UserStudyRecordExport> exports = iExamApplyService.getUserStudyRecordNoTenant(item.getOrderGoodsId());
|
|
|
+ if (CollectionUtils.isEmpty(exports)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ exports.forEach(recordItem -> {
|
|
|
+ recordItem.setUserName(user.getRealname());
|
|
|
+ recordItem.setIdCard(EncryptHandler.decrypt(user.getIdCard()));
|
|
|
+ recordItem.setCompanyName(user.getCompanyName());
|
|
|
+ recordItem.setSectionTime(DateUtils.secondConvertHourMinSecond(recordItem.getDurationTime()));
|
|
|
+ if (ObjectUtils.isNotNull(recordItem.getStatus()) && recordItem.getStatus() == 1) {
|
|
|
+ //已学完
|
|
|
+ recordItem.setStudyTime(DateUtils.secondConvertHourMinSecond(recordItem.getDurationTime()));
|
|
|
+ recordItem.setFinish("已完成");
|
|
|
+ } else {
|
|
|
+ recordItem.setFinish("未完成");
|
|
|
+ }
|
|
|
+ recordItem.setStudyStartTime(DateUtils.timestampToDateFormat(recordItem.getStartTime(), "yyyy/MM/dd HH:mm:ss"));
|
|
|
+ recordItem.setStudyEndTime(DateUtils.timestampToDateFormat(recordItem.getEndTime(), "yyyy/MM/dd HH:mm:ss"));
|
|
|
+ });
|
|
|
+ recordExports.addAll(exports);
|
|
|
+ task.setFinishNum(i+1);
|
|
|
+ iSysTaskService.updateById(task);
|
|
|
+ }
|
|
|
+ ExcelUtil<UserStudyRecordExport> util = new ExcelUtil<UserStudyRecordExport>(UserStudyRecordExport.class);
|
|
|
+ String path = destDirPath + "/" +"学习记录表" + ".xlsx";
|
|
|
+ util.exportEasyExcelStudy(util.exportEasyData(recordExports), path);
|
|
|
+ //打包zip 上传oss
|
|
|
+ String zipPath = zhiyuan+"/zhongzheng-admin/src/main/resources/"
|
|
|
+ +String.format("%s预约考试.zip",DateUtils.timestampToDateFormat(subUserExportBo.getApplyTime(),"yyyy-MM-dd"));
|
|
|
+ FileUtils.toZip(zipPath,destDirPath,true);
|
|
|
+ //上传oss
|
|
|
+ OssRequest ossRequest = new OssRequest();
|
|
|
+ ossRequest.setGradeId(0L);
|
|
|
+ ossRequest.setUserId(0L);
|
|
|
+ ossRequest.setImageStatus(7);
|
|
|
+ File file1 = new File(zipPath);
|
|
|
+ ossRequest.setFile(FileUtils.getMultipartFile(file1));
|
|
|
+ try {
|
|
|
+ String upload = ossService.upload(ossRequest);
|
|
|
+ task.setTaskPath(upload);
|
|
|
+ task.setTaskStatus(3);//完成
|
|
|
+ iSysTaskService.updateById(task);
|
|
|
+ //删除本地资源
|
|
|
+ Path pathStr = Paths.get(destDirPath);
|
|
|
+ try (Stream<Path> walk = Files.walk(pathStr)) {
|
|
|
+ walk.sorted(Comparator.reverseOrder())
|
|
|
+ .forEach(FileUtils::deleteDirectoryStream);
|
|
|
+ }catch (IOException e) {
|
|
|
+ log.error("删除本地资源失败:"+ DateUtils.getNowTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ Path zipStr = Paths.get(zipPath);
|
|
|
+ try (Stream<Path> walk = Files.walk(zipStr)) {
|
|
|
+ walk.sorted(Comparator.reverseOrder())
|
|
|
+ .forEach(FileUtils::deleteDirectoryStream);
|
|
|
+ }catch (IOException e) {
|
|
|
+ log.error("删除本地资源失败:"+ DateUtils.getNowTime());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private String getWeeks(Long time){
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(DateUtils.timeToDate(time));
|