diff --git a/src/main/java/com/glxp/udidl/admin/constant/Constant.java b/src/main/java/com/glxp/udidl/admin/constant/Constant.java new file mode 100644 index 0000000..3db3499 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/constant/Constant.java @@ -0,0 +1,38 @@ +package com.glxp.udidl.admin.constant; + +/** + * 业务常量 + */ +public interface Constant { + + /** + * 下载类型 - 手动下载 + */ + String DOWNLOAD_TYPE_MANUAL = "manual"; + + /** + * 下载类型 - 自动下载 + */ + String DOWNLOAD_TYPE_AUTO = "auto"; + + /** + * 日志类型 - SUCCESS + */ + String LOG_TYPE_SUCCESS = "success"; + + /** + * 日志类型 - INFO + */ + String LOG_TYPE_INFO = "info"; + + /** + * 日志类型 - INFO + */ + String LOG_TYPE_WARNING = "warning"; + + /** + * 日志类型 - INFO + */ + String LOG_TYPE_ERROR = "error"; + +} diff --git a/src/main/java/com/glxp/udidl/admin/service/dataSync/DeviceDownloadService.java b/src/main/java/com/glxp/udidl/admin/service/dataSync/DeviceDownloadService.java index 0ba0ce2..90a57c4 100644 --- a/src/main/java/com/glxp/udidl/admin/service/dataSync/DeviceDownloadService.java +++ b/src/main/java/com/glxp/udidl/admin/service/dataSync/DeviceDownloadService.java @@ -4,6 +4,7 @@ package com.glxp.udidl.admin.service.dataSync; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.glxp.udidl.admin.constant.Constant; import com.glxp.udidl.admin.entity.info.CompanyEntity; import com.glxp.udidl.admin.entity.udi.ProductInfoEntity; import com.glxp.udidl.admin.entity.udid.Device; @@ -105,6 +106,7 @@ public class DeviceDownloadService { try { response = HttpClient.post("sharing/single", downloadDiRequest); } catch (Exception e) { + log.error("下载产品标识详情数据异常,响应结果:{}", response); result.setReturnCode(-1); result.setReturnMsg(e.getMessage()); return result;//发生错误 退出 @@ -399,7 +401,7 @@ public class DeviceDownloadService { } } else { JobLog jobLog = new JobLog(); - jobLog.setType("error"); + jobLog.setType(Constant.LOG_TYPE_ERROR); jobLog.setMsg(res.getMsg()); jobLog.setCreateTime(new Date()); jobLogService.insert(jobLog); @@ -420,8 +422,8 @@ public class DeviceDownloadService { String msg = "下载到第" + page + "页发生错误"; //发生错误,存储日志 JobLog jobLog = new JobLog(); - jobLog.setDownloadType("manual"); - jobLog.setType("error"); + jobLog.setDownloadType(Constant.DOWNLOAD_TYPE_MANUAL); + jobLog.setType(Constant.LOG_TYPE_ERROR); jobLog.setMsg(msg); jobLog.setContent(dataSetResult.getReturnMsg()); jobLog.setCreateTime(new Date()); @@ -438,16 +440,16 @@ public class DeviceDownloadService { page++; } JobLog jobLog = new JobLog(); - jobLog.setType("info"); - jobLog.setDownloadType("manual"); + jobLog.setType(Constant.LOG_TYPE_INFO); + jobLog.setDownloadType(Constant.DOWNLOAD_TYPE_MANUAL); jobLog.setMsg("月份:" + month + ",执行成功!"); jobLog.setCreateTime(new Date()); jobLogService.insert(jobLog); } catch (Exception e) { log.error(e.getMessage(), e); JobLog jobLog = new JobLog(); - jobLog.setDownloadType("manual"); - jobLog.setType("error"); + jobLog.setDownloadType(Constant.DOWNLOAD_TYPE_MANUAL); + jobLog.setType(Constant.LOG_TYPE_ERROR); jobLog.setMsg("月份:" + month + ",执行失败:" + e.getMessage()); jobLog.setContent(JSON.toJSONString(e.getStackTrace())); jobLog.setCreateTime(new Date()); @@ -468,8 +470,8 @@ public class DeviceDownloadService { String msg = "下载到第" + page + "页发生错误"; //发生错误,存储日志 JobLog jobLog = new JobLog(); - jobLog.setDownloadType("manual"); - jobLog.setType("error"); + jobLog.setDownloadType(Constant.DOWNLOAD_TYPE_MANUAL); + jobLog.setType(Constant.LOG_TYPE_ERROR); jobLog.setMsg(msg); jobLog.setContent(dataSetResult.getReturnMsg()); jobLog.setCreateTime(new Date()); @@ -502,16 +504,16 @@ public class DeviceDownloadService { page++; } JobLog jobLog = new JobLog(); - jobLog.setType("info"); - jobLog.setDownloadType("manual"); + jobLog.setType(Constant.LOG_TYPE_INFO); + jobLog.setDownloadType(Constant.DOWNLOAD_TYPE_MANUAL); jobLog.setMsg("月份:" + month + ",执行成功!"); jobLog.setCreateTime(new Date()); jobLogService.insert(jobLog); } catch (Exception e) { e.printStackTrace(); JobLog jobLog = new JobLog(); - jobLog.setDownloadType("manual"); - jobLog.setType("error"); + jobLog.setDownloadType(Constant.DOWNLOAD_TYPE_MANUAL); + jobLog.setType(Constant.LOG_TYPE_ERROR); jobLog.setMsg("月份:" + month + ",执行失败:" + e.getMessage()); jobLog.setContent(JSON.toJSONString(e.getStackTrace())); jobLog.setCreateTime(new Date()); diff --git a/src/main/java/com/glxp/udidl/admin/service/dataSync/DeviceSyncService.java b/src/main/java/com/glxp/udidl/admin/service/dataSync/DeviceSyncService.java index 0d8d6df..b2b078c 100644 --- a/src/main/java/com/glxp/udidl/admin/service/dataSync/DeviceSyncService.java +++ b/src/main/java/com/glxp/udidl/admin/service/dataSync/DeviceSyncService.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUnit; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; +import com.glxp.udidl.admin.constant.Constant; import com.glxp.udidl.admin.entity.udi.ProductInfoEntity; import com.glxp.udidl.admin.entity.udid.*; import com.glxp.udidl.admin.req.ProductInfoFilterRequest; @@ -59,7 +60,7 @@ public class DeviceSyncService { JobLog jobLog = new JobLog(); jobLog.setDownloadType(downloadType); jobLog.setDownloadDate(DateUtil.parseDate(rangeValue)); - jobLog.setType("error"); + jobLog.setType(Constant.LOG_TYPE_ERROR); jobLog.setMsg(result.getMsg()); jobLog.setCreateTime(new Date()); jobLogService.insert(jobLog); @@ -92,7 +93,7 @@ public class DeviceSyncService { JobLog jobLog = new JobLog(); jobLog.setDownloadType(downloadType); jobLog.setDownloadDate(DateUtil.parseDate(rangeValue)); - jobLog.setType("error"); + jobLog.setType(Constant.LOG_TYPE_ERROR); jobLog.setMsg("下载历史记录出错:" + res.getMsg()); jobLog.setCreateTime(new Date()); jobLogService.insert(jobLog); @@ -107,11 +108,11 @@ public class DeviceSyncService { jobLog.setRealCount(result.realRecordCount()); jobLog.setInsertCount(insertCount); if (result.realRecordCount() != result.getTotalRecordCount()) { - jobLog.setType("warning"); + jobLog.setType(Constant.LOG_TYPE_WARNING); jobLog.setMsg("接口总行数和实际行数不一致"); jobLog.setCreateTime(new Date()); } else { - jobLog.setType("info"); + jobLog.setType(Constant.LOG_TYPE_INFO); jobLog.setMsg("执行成功!"); jobLog.setCreateTime(new Date()); } @@ -127,7 +128,7 @@ public class DeviceSyncService { JobLog jobLog = new JobLog(); jobLog.setDownloadType(downloadType); jobLog.setDownloadDate(DateUtil.parseDate(day)); - jobLog.setType("error"); + jobLog.setType(Constant.LOG_TYPE_ERROR); jobLog.setMsg(e.getMessage()); jobLog.setContent(JSON.toJSONString(e.getStackTrace())); jobLog.setCreateTime(new Date()); @@ -210,12 +211,34 @@ public class DeviceSyncService { } public BaseResponse downloadSingle(String deviceId) { - DataSetSingleResult res = deviceDownloadService.downloadByDi(deviceId); - if (res.getReturnCode() != 1) - return ResultVOUtils.error(-1, res.getReturnMsg()); - List dataSets = new ArrayList<>(); - dataSets.add(res.getDataSet()); - deviceSaveService.DeviceSave(dataSets, new Date()); + //插入日志 + JobLog jobLog = new JobLog(); + jobLog.setDownloadType(Constant.DOWNLOAD_TYPE_MANUAL); + jobLog.setDownloadDate(new Date()); + jobLog.setType(Constant.LOG_TYPE_INFO); + jobLog.setMsg("下载中"); + jobLog.setCreateTime(new Date()); + jobLog.setStatus(0); + jobLogService.insertLog(jobLog); + + DataSetSingleResult res = null; + try { + res = deviceDownloadService.downloadByDi(deviceId); + if (res.getReturnCode() != 1) + return ResultVOUtils.error(-1, res.getReturnMsg()); + List dataSets = new ArrayList<>(); + dataSets.add(res.getDataSet()); + int insertCount = deviceSaveService.DeviceSave(dataSets, new Date()); + + jobLog.setMsg("下载成功,总条数:" + dataSets.size() + " ;插入数据:" + insertCount + " 条"); + jobLog.setType(Constant.LOG_TYPE_SUCCESS); + jobLogService.update(jobLog); + } catch (Exception e) { + log.error("下载产品信息失败", e); + jobLog.setMsg("下载失败:" + res.getReturnMsg()); + jobLog.setType(Constant.LOG_TYPE_ERROR); + jobLogService.update(jobLog); + } return ResultVOUtils.success(Convert(res.getDataSet())); } @@ -389,7 +412,7 @@ public class DeviceSyncService { JobLog jobLog = new JobLog(); jobLog.setDownloadType(deviceRequest.getDownloadType()); jobLog.setDownloadDate(DateUtil.parseDate(date)); - jobLog.setType("info"); + jobLog.setType(Constant.LOG_TYPE_INFO); jobLog.setMsg("下载中"); jobLog.setCreateTime(new Date()); jobLog.setStatus(0); @@ -401,7 +424,7 @@ public class DeviceSyncService { if (data.getCode() != 1) { log.error(date + " 数据下载失败"); jobLog.setStatus(1); - jobLog.setType("error"); + jobLog.setType(Constant.LOG_TYPE_ERROR); jobLog.setMsg(data.getMsg()); jobLog.setUpdateTime(new Date()); jobLogService.update(jobLog); @@ -413,7 +436,7 @@ public class DeviceSyncService { try { int insertCount = deviceSaveService.DeviceSave(data.getData(), DateUtil.parseDate(date)); jobLog.setStatus(1); - jobLog.setType("success"); + jobLog.setType(Constant.LOG_TYPE_SUCCESS); jobLog.setMsg("下载成功,总条数:" + data.getTotalRecordCount() + " ;插入数据:" + insertCount + " 条"); jobLog.setUpdateTime(new Date()); jobLog.setInsertCount(insertCount); @@ -421,7 +444,7 @@ public class DeviceSyncService { } catch (Exception e) { log.error("插入数据失败", e); jobLog.setStatus(1); - jobLog.setType("error"); + jobLog.setType(Constant.LOG_TYPE_ERROR); jobLog.setMsg("下载成功,数据插入失败"); jobLog.setUpdateTime(new Date()); jobLog.setInsertCount(0); diff --git a/src/main/java/com/glxp/udidl/admin/thread/DownloadProductInfoTask.java b/src/main/java/com/glxp/udidl/admin/thread/DownloadProductInfoTask.java index d7e1c1d..00eb3f0 100644 --- a/src/main/java/com/glxp/udidl/admin/thread/DownloadProductInfoTask.java +++ b/src/main/java/com/glxp/udidl/admin/thread/DownloadProductInfoTask.java @@ -1,5 +1,6 @@ package com.glxp.udidl.admin.thread; +import com.glxp.udidl.admin.constant.Constant; import com.glxp.udidl.admin.dao.info.ScheduledMapper; import com.glxp.udidl.admin.entity.info.ScheduledEntity; import com.glxp.udidl.admin.entity.udid.JobLog; @@ -56,11 +57,11 @@ public class DownloadProductInfoTask implements SchedulingConfigurer { private void process() { Date endDate = DateUtil.parseDate((DateUtil.formatDate(new Date()))); Date startDate = DateUtil.addDays(endDate, -7); - BaseResponse res = productInfoDlService.ExportToFile(startDate, endDate, "auto"); + BaseResponse res = productInfoDlService.ExportToFile(startDate, endDate, Constant.DOWNLOAD_TYPE_AUTO); if (res.getCode() != 20000) { JobLog jobLog = new JobLog(); - jobLog.setType("error"); - jobLog.setDownloadType("auto"); + jobLog.setType(Constant.LOG_TYPE_ERROR); + jobLog.setDownloadType(Constant.DOWNLOAD_TYPE_AUTO); jobLog.setMsg("下载文件失败:" + res.getMessage()); jobLog.setCreateTime(new Date()); jobLogService.insert(jobLog); diff --git a/src/main/java/com/glxp/udidl/admin/util/HttpClient.java b/src/main/java/com/glxp/udidl/admin/util/HttpClient.java index 3e757ee..018173d 100644 --- a/src/main/java/com/glxp/udidl/admin/util/HttpClient.java +++ b/src/main/java/com/glxp/udidl/admin/util/HttpClient.java @@ -17,7 +17,7 @@ public class HttpClient { public static String post(String url, Object object) { RestTemplate restTemplate = new RestTemplate(); - String json = JSONObject.toJSON(object).toString(); + String json = JSONObject.toJSONString(object); MultiValueMap postParameters = new LinkedMultiValueMap<>(); postParameters.add("params", json); HttpHeaders headers = new HttpHeaders(); @@ -25,8 +25,6 @@ public class HttpClient { HttpEntity> httpEntity = new HttpEntity<>(postParameters, headers); logger.info(UdidConfig.apiUrl + url + httpEntity.toString()); String response = restTemplate.postForObject(UdidConfig.apiUrl + url, httpEntity, String.class); - //logger.info(response); - return response; } diff --git a/src/main/resources/config/redis.setting b/src/main/resources/config/redis.setting index 2593a47..182ac20 100644 --- a/src/main/resources/config/redis.setting +++ b/src/main/resources/config/redis.setting @@ -7,7 +7,7 @@ #----- 默认(公有)配置 # 地址,默认localhost -host = 127.0.0.1 +host = 192.168.235.137 # 端口,默认6379 port = 6379 # 超时,默认2000 @@ -17,7 +17,7 @@ connectionTimeout = 2000 # 读取超时,默认timeout soTimeout = 2000 # 密码,默认无 - +password = 123456 # 数据库序号,默认0 database = 0 # 客户端名,默认"Hutool"