|
|
|
|
@ -1,14 +1,31 @@
|
|
|
|
|
package cn.jyjz.xiaoyao.ocr.timerJob;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.jyjz.xiaoyao.admin.dataDao.DepartmentMybatisDao;
|
|
|
|
|
import cn.jyjz.xiaoyao.admin.dataobject.Department;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.PrevailCloudApi;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceParameter;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceResult;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.utils.ApiPage;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.thread.TaskQueue;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.apache.commons.compress.utils.Lists;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用于轮询获取图片数据源 定时任务
|
|
|
|
|
*
|
|
|
|
|
@ -24,11 +41,17 @@ public class PictureSourceTimerJob {
|
|
|
|
|
@Autowired
|
|
|
|
|
PrevailCloudApi prevailCloudApi;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private DepartmentMybatisDao departmentMybatisDao;
|
|
|
|
|
|
|
|
|
|
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 请求图片数据job (定时执行 每日拉取上一日全部数据)
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String pictureSourceRequestJob(){
|
|
|
|
|
private void pictureSourceRequestJob() {
|
|
|
|
|
|
|
|
|
|
//组装拉取参数
|
|
|
|
|
PictureSourceParameter pictureSourceParameter = new PictureSourceParameter();
|
|
|
|
|
@ -39,9 +62,75 @@ public class PictureSourceTimerJob {
|
|
|
|
|
pictureSourceParameter.setPageSize(200);
|
|
|
|
|
// pictureSourceParameter.setAccountNo();
|
|
|
|
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
|
|
Date yesterday = calendar.getTime();
|
|
|
|
|
String startDateStr = dateFormat.format(yesterday).split(" ")[0] + " 00:00:00"; // 开始时间为昨天的0点
|
|
|
|
|
String endDateStr = dateFormat.format(yesterday).split(" ")[0] + " 23:59:59"; // 结束时间为昨天的23点59分59秒
|
|
|
|
|
DateTime dateTime = DateUtil.parse(startDateStr, "yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
DateTime dateTime1 = DateUtil.parse(endDateStr, "yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
//1.拉取数据
|
|
|
|
|
// ApiPage<PictureSourceResult> pictureSourceResultApiPage = prevailCloudApi.pullPictureSource(pictureSourceParameter);
|
|
|
|
|
List<Department> departments = departmentMybatisDao.selectList(new QueryWrapper<>());
|
|
|
|
|
if (CollectionUtils.isEmpty(departments)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<Long, Department> departmentMap = Maps.newHashMapWithExpectedSize(departments.size());
|
|
|
|
|
for (Department department : departments) {
|
|
|
|
|
if (department.getDlevel() == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
departmentMap.put(department.getId(), department);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<PictureSourceResult> totalList = Lists.newArrayList();
|
|
|
|
|
for (Department department : departments) {
|
|
|
|
|
if (!departmentMap.containsKey(department.getParentid())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Long tenantNo = Long.valueOf(departmentMap.get(department.getParentid()).getDeptno());
|
|
|
|
|
Long accountNo = Long.valueOf(department.getDeptno());
|
|
|
|
|
|
|
|
|
|
List<PictureSourceResult> resultList = getPictureSourceResultApiPage(PictureSourceParameter pictureSourceParameter, dateTime, dateTime1, tenantNo, accountNo);
|
|
|
|
|
if (CollectionUtils.isEmpty(resultList)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
totalList.addAll(resultList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int count = totalList.size();
|
|
|
|
|
int size = 0;
|
|
|
|
|
for (PictureSourceResult pictureSourceResult : totalList) {
|
|
|
|
|
if (pictureSourceResult.getLivePhoto() != null) {
|
|
|
|
|
size++;
|
|
|
|
|
// 将可以处理数据放入处理队列中
|
|
|
|
|
TaskQueue.pictureDisposePushData(pictureSourceResult);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("当前区间内图片总数:" + count + "条,可处理数据:" + size + "条");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<PictureSourceResult> getPictureSourceResultApiPage(PictureSourceParameter pictureSourceParameter, DateTime dateTime, DateTime dateTime1, Long tenantNo, Long accountNo) {
|
|
|
|
|
//创建查询参数对象
|
|
|
|
|
Instant binstant = dateTime.toInstant();
|
|
|
|
|
Instant einstant = dateTime1.toInstant();
|
|
|
|
|
pictureSourceParameter.setStartTime(Date.from(binstant));
|
|
|
|
|
pictureSourceParameter.setEndTime(Date.from(einstant));
|
|
|
|
|
pictureSourceParameter.setTenantNo(tenantNo);
|
|
|
|
|
pictureSourceParameter.setAccountNo(accountNo);
|
|
|
|
|
|
|
|
|
|
ApiPage<PictureSourceResult> apiPage = null;
|
|
|
|
|
try {
|
|
|
|
|
apiPage = prevailCloudApi.pullPictureSource(pictureSourceParameter);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
return apiPage == null ? Lists.newArrayList() : apiPage.getRecords();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|