You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udisyncdl-java/src/main/java/com/glxp/udidl/admin/thread/AsyncDownloadTask.java

122 lines
4.8 KiB
Java

package com.glxp.udidl.admin.thread;
import com.glxp.udidl.admin.controller.device.DownloadDeviceHelper;
import com.glxp.udidl.admin.dao.udid.DevicedownloadMapper;
import com.glxp.udidl.admin.entity.udid.Devicedownload;
import com.glxp.udidl.admin.entity.udid.TokenEntity;
import com.glxp.udidl.admin.req.udid.DeviceRequest;
import com.glxp.udidl.admin.req.udid.DownloadDiRequest;
import com.glxp.udidl.admin.service.dataSync.DeviceDownloadService;
import com.glxp.udidl.admin.service.dataSync.DeviceSyncService;
import com.glxp.udidl.admin.service.info.CompanyService;
import com.glxp.udidl.admin.service.inout.DeviceService;
import com.glxp.udidl.admin.service.inout.ProductInfoService;
import com.glxp.udidl.admin.service.udi.UdiCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class AsyncDownloadTask {
@Resource
DeviceService deviceService;
@Resource
CompanyService companyService;
@Resource
UdiCompanyService udiCompanyService;
@Resource
ProductInfoService productInfoService;
@Resource
private DevicedownloadMapper devicedownloadMapper;
@Autowired
DeviceDownloadService deviceDownloadService;
@Autowired
DeviceSyncService deviceSyncService;
@Async
public void downloadByDi(String primaryDeviceId) {
DownloadDeviceHelper downloadDeviceHelper = new DownloadDeviceHelper(companyService, udiCompanyService);
String token = deviceDownloadService.getToken();
DownloadDiRequest downloadDiRequest = new DownloadDiRequest();
downloadDiRequest.setAccessToken(token);
downloadDiRequest.setPrimaryDeviceId(primaryDeviceId);
downloadDeviceHelper.downloadBydi(downloadDiRequest, deviceService, productInfoService);
}
//https://www.udims.com/UDI_DL_Server/udidl/device/dlBymonth?month=2021-10&page=1
//按月下载UDI
@Async
public void downloadByMonth(String month, int page) {
deviceDownloadService.downloadByMonth(month, page);
}
@Async
public void downloadByMonthTest(String month, int page) {
deviceDownloadService.downloadByMonthTest(month, page);
/*int curpage = page;
DownloadDeviceHelper downloadDeviceHelper = new DownloadDeviceHelper(companyService,udiCompanyService);
TokenEntity token = downloadDeviceHelper.getToken();
while (true) {
DeviceRequest deviceRequest = new DeviceRequest();
deviceRequest.setAccessToken(token.getAccessToken());
deviceRequest.setRequestType("2");
deviceRequest.setRangeValue(month);
deviceRequest.setCurrentPageNumber(curpage + "");
int result = downloadDeviceHelper.downloadDevices(productInfoService, deviceService, deviceRequest);
if (result == -1) {
return;// ResultVOUtils.error(505, "下载出错");
}
curpage++;
}*/
}
//按天下载UDI , 手动下载
@Async
public void downloadByDay(String day) {
deviceSyncService.downloadUdi(day, "manual");
}
@Async
public void downloadAll() {
while (true) {
int curpage = 1;
Devicedownload devicedownload = devicedownloadMapper.selectByPrimaryKey("udid");
if (devicedownload != null) {
curpage = devicedownload.getAllindex();
} else {
devicedownload = new Devicedownload();
devicedownload.setId("udid");
devicedownload.setAllindex(1);
devicedownloadMapper.insert(devicedownload);
}
devicedownload.setIsdownload(1);
long startTime = System.currentTimeMillis();
devicedownload.setStarttime(startTime + "");
devicedownloadMapper.updateByPrimaryKey(devicedownload);
DownloadDeviceHelper downloadDeviceHelper = new DownloadDeviceHelper(companyService, udiCompanyService);
TokenEntity token = downloadDeviceHelper.getToken();
DeviceRequest deviceRequest = new DeviceRequest();
deviceRequest.setAccessToken(token.getAccessToken());
deviceRequest.setRequestType(3 + "");
deviceRequest.setCurrentPageNumber(curpage + "");
int result = downloadDeviceHelper.downloadDevices(productInfoService, deviceService, deviceRequest);
if (result == -1) {
return;// ResultVOUtils.error(505, "下载出错");
}
curpage++;
Devicedownload devicedownload1 = new Devicedownload();
devicedownload1.setAllindex(curpage);
devicedownload1.setId("udid");
devicedownloadMapper.updateProgress(devicedownload1);
}
}
}