From c1c0fb974512036a0387bc85e527c4a00c998458 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Fri, 1 Sep 2023 10:54:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E5=89=8D?= =?UTF-8?q?=20=E5=85=88=E5=88=A0=E9=99=A4=E6=89=80=E6=9C=89=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gov/manage/GovProjectCollectionManage.java | 19 ++++++ .../scheduler/task/SynProjectCollectionTask.java | 5 +- pmapi/src/main/resources/application-dev.yml | 2 +- pmapi/src/main/resources/application-pre.yml | 1 + pmapi/src/main/resources/application-prod.yml | 1 + pmapi/src/test/resources/application-dev.yml | 2 +- pmapi/src/test/resources/application-pre.yml | 1 + pmapi/src/test/resources/application-prod.yml | 1 + .../open/controller/ProjectReceiveController.java | 7 ++- .../open/manage/ProjectReceiveManage.java | 67 ++++++++++++++++++---- 10 files changed, 91 insertions(+), 15 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/gov/manage/GovProjectCollectionManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/gov/manage/GovProjectCollectionManage.java index 1f8f81a..7045db5 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/gov/manage/GovProjectCollectionManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/gov/manage/GovProjectCollectionManage.java @@ -75,6 +75,9 @@ public class GovProjectCollectionManage { @Value("${project.no-effective-url}") private String noEffectiveUrl; + @Value("${project.delete-all-url}") + private String deleteAllUrl; + public List dictionary(String type) { List dictionaries = dictionaryService.list(Wrappers.lambdaQuery(GovProjectDictionary.class) @@ -472,4 +475,20 @@ public class GovProjectCollectionManage { log.info("推送失败,{}",e.getMessage()); } } + + public void deleteAll() { + String url = deleteAllUrl; + try{ + log.info("推送删除数据url {}",url); + HttpHeaders headers = new HttpHeaders(); + MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); + headers.setContentType(type); + headers.add("Accept", MediaType.APPLICATION_JSON.toString()); + HttpEntity formEntity = new HttpEntity(null, headers); + ResponseEntity response = restTemplate.postForEntity(url, formEntity, String.class); + log.info("推送删除结果 :{}",response); + }catch (Exception e){ + log.info("推送删除失败,{}",e.getMessage()); + } + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProjectCollectionTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProjectCollectionTask.java index 04b2fa5..82cc112 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProjectCollectionTask.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProjectCollectionTask.java @@ -55,10 +55,13 @@ public class SynProjectCollectionTask { log.info("预发环境不用同步!"); return; } - log.info("数据同步任务开始"); + StopWatch stopWatch = new StopWatch(); stopWatch.start(); + log.info("数据同步任务开始之前 先删除前置机上的所有数据"); + collectionManage.deleteAll(); + //取昨天1点 到今天1点的 项目归集 ProjectListReq req = new ProjectListReq(); req.setCreateOnMax(DateUtil.convertDateToLocal(DateUtil.getTodayTime(TASK_HOUR_TODAY))); diff --git a/pmapi/src/main/resources/application-dev.yml b/pmapi/src/main/resources/application-dev.yml index f936cdb..2d73ea8 100644 --- a/pmapi/src/main/resources/application-dev.yml +++ b/pmapi/src/main/resources/application-dev.yml @@ -233,7 +233,7 @@ hostname: iZbp13nwyvib53j4j1p2xoZ project: push-url: http://120.26.44.207:38088/open/api/v1/project-receive/save no-effective-url: http://120.26.44.207:38088/open/api/v1/project-receive/not-effective - + delete-all-url: http://120.26.44.207:38088/open/api/v1/project-receive/delete-all login: phone-verify-code: skip: true diff --git a/pmapi/src/main/resources/application-pre.yml b/pmapi/src/main/resources/application-pre.yml index 4e9d514..b6d0de4 100644 --- a/pmapi/src/main/resources/application-pre.yml +++ b/pmapi/src/main/resources/application-pre.yml @@ -236,6 +236,7 @@ hostname: iZ6mx01asxnsmennpzoxooZ project: push-url: http://10.53.168.41:38088/open/api/v1/project-receive/save no-effective-url: http://10.53.168.41:38088/open/api/v1/project-receive/not-effective + delete-all-url: http://10.53.168.41:38088/open/api/v1/project-receive/delete-all login: phone-verify-code: skip: true diff --git a/pmapi/src/main/resources/application-prod.yml b/pmapi/src/main/resources/application-prod.yml index c2f8c75..b1aa4ee 100644 --- a/pmapi/src/main/resources/application-prod.yml +++ b/pmapi/src/main/resources/application-prod.yml @@ -236,6 +236,7 @@ hostname: iZ6mx01gyeodd80imxd2gbZ project: push-url: http://10.53.168.41:38088/open/api/v1/project-receive/save no-effective-url: http://10.53.168.41:38088/open/api/v1/project-receive/not-effective + delete-all-url: http://10.53.168.41:38088/open/api/v1/project-receive/delete-all login: phone-verify-code: skip: true diff --git a/pmapi/src/test/resources/application-dev.yml b/pmapi/src/test/resources/application-dev.yml index f936cdb..2d73ea8 100644 --- a/pmapi/src/test/resources/application-dev.yml +++ b/pmapi/src/test/resources/application-dev.yml @@ -233,7 +233,7 @@ hostname: iZbp13nwyvib53j4j1p2xoZ project: push-url: http://120.26.44.207:38088/open/api/v1/project-receive/save no-effective-url: http://120.26.44.207:38088/open/api/v1/project-receive/not-effective - + delete-all-url: http://120.26.44.207:38088/open/api/v1/project-receive/delete-all login: phone-verify-code: skip: true diff --git a/pmapi/src/test/resources/application-pre.yml b/pmapi/src/test/resources/application-pre.yml index 4e9d514..b6d0de4 100644 --- a/pmapi/src/test/resources/application-pre.yml +++ b/pmapi/src/test/resources/application-pre.yml @@ -236,6 +236,7 @@ hostname: iZ6mx01asxnsmennpzoxooZ project: push-url: http://10.53.168.41:38088/open/api/v1/project-receive/save no-effective-url: http://10.53.168.41:38088/open/api/v1/project-receive/not-effective + delete-all-url: http://10.53.168.41:38088/open/api/v1/project-receive/delete-all login: phone-verify-code: skip: true diff --git a/pmapi/src/test/resources/application-prod.yml b/pmapi/src/test/resources/application-prod.yml index ce9b5dd..758f192 100644 --- a/pmapi/src/test/resources/application-prod.yml +++ b/pmapi/src/test/resources/application-prod.yml @@ -236,6 +236,7 @@ hostname: iZ6mx01gyeodd80imxd2gbZ project: push-url: http://10.53.168.41:38088/open/api/v1/project-receive/save no-effective-url: http://10.53.168.41:38088/open/api/v1/project-receive/not-effective + delete-all-url: http://10.53.168.41:38088/open/api/v1/project-receive/delete-all login: phone-verify-code: skip: true diff --git a/syn-data-task/src/main/java/com/ningdatech/syndataapi/open/controller/ProjectReceiveController.java b/syn-data-task/src/main/java/com/ningdatech/syndataapi/open/controller/ProjectReceiveController.java index e8655ca..0ec1583 100644 --- a/syn-data-task/src/main/java/com/ningdatech/syndataapi/open/controller/ProjectReceiveController.java +++ b/syn-data-task/src/main/java/com/ningdatech/syndataapi/open/controller/ProjectReceiveController.java @@ -4,7 +4,6 @@ import com.ningdatech.basic.model.ApiResponse; import com.ningdatech.syndataapi.open.manage.ProjectReceiveManage; import com.ningdatech.syndataapi.scheduler.model.dto.ProjectBaseInfoDTO; import com.ningdatech.syndataapi.scheduler.model.dto.ProjectSaveDTO; -import com.ningdatech.syndataapi.scheduler.model.entity.ProjectBaseInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -37,4 +36,10 @@ public class ProjectReceiveController { public ApiResponse notEffective(@Valid @RequestBody ProjectBaseInfoDTO baseinfo) { return ApiResponse.ofSuccess(receiveManage.notEffective(baseinfo)); } + + @PostMapping("/delete-all") + @ApiOperation("清空当前表数据") + public ApiResponse deleteAll() { + return ApiResponse.ofSuccess(receiveManage.deleteAll()); + } } diff --git a/syn-data-task/src/main/java/com/ningdatech/syndataapi/open/manage/ProjectReceiveManage.java b/syn-data-task/src/main/java/com/ningdatech/syndataapi/open/manage/ProjectReceiveManage.java index 4a3bea1..7ee3071 100644 --- a/syn-data-task/src/main/java/com/ningdatech/syndataapi/open/manage/ProjectReceiveManage.java +++ b/syn-data-task/src/main/java/com/ningdatech/syndataapi/open/manage/ProjectReceiveManage.java @@ -1,7 +1,6 @@ package com.ningdatech.syndataapi.open.manage; import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ningdatech.basic.function.VUtils; import com.ningdatech.syndataapi.common.constant.BizConst; @@ -59,10 +58,16 @@ public class ProjectReceiveManage { .last(BizConst.LIMIT_1)); ProjectBaseInfo saveBase = BeanUtil.copyProperties(baseInfo,ProjectBaseInfo.class); if(Objects.isNull(oldBaseInfo)){ - saveBase.setOp(BizConst.OP_INSERT); + //如果当前 数据不存在 但是我们平台操作是修改 说明之前数据被推送过了那么 可以置为修改update + if(StringUtils.isNotBlank(baseInfo.getOp()) && BizConst.OP_UPDATE.equals(baseInfo.getOp())){ + saveBase.setOp(BizConst.OP_UPDATE); + }else{ + saveBase.setOp(BizConst.OP_INSERT); + } saveBase.setTongTime(LocalDateTime.now()); }else { - saveBase.setOp(BizConst.OP_UPDATE); + saveBase.setOp(BizConst.OP_INSERT); + saveBase.setTongID(oldBaseInfo.getTongID()); } saveBase.setBizTime(LocalDateTime.now()); baseInfoService.saveOrUpdate(saveBase); @@ -77,11 +82,18 @@ public class ProjectReceiveManage { ProjectApply saveApply = BeanUtil.copyProperties(apply,ProjectApply.class); saveApply.setBaseProjId(baseProjId); if(Objects.isNull(oldApply)){ - saveApply.setOp(BizConst.OP_INSERT); + //如果当前 数据不存在 但是我们平台操作是修改 说明之前数据被推送过了那么 可以置为修改update + if(StringUtils.isNotBlank(apply.getOp()) && BizConst.OP_UPDATE.equals(apply.getOp())){ + saveApply.setOp(BizConst.OP_UPDATE); + }else{ + saveApply.setOp(BizConst.OP_INSERT); + } saveApply.setTongTime(LocalDateTime.now()); }else{ - saveApply.setOp(BizConst.OP_UPDATE); + saveApply.setOp(BizConst.OP_INSERT); + saveApply.setTongID(oldApply.getTongID()); } + saveApply.setBizTime(LocalDateTime.now()); applyService.saveOrUpdate(saveApply); @@ -95,10 +107,16 @@ public class ProjectReceiveManage { ProjectApprove saveApprove = BeanUtil.copyProperties(approve,ProjectApprove.class); saveApprove.setBaseProjId(baseProjId); if(Objects.isNull(oldApprove)){ - saveApprove.setOp(BizConst.OP_INSERT); + //如果当前 数据不存在 但是我们平台操作是修改 说明之前数据被推送过了那么 可以置为修改update + if(StringUtils.isNotBlank(approve.getOp()) && BizConst.OP_UPDATE.equals(approve.getOp())){ + saveApprove.setOp(BizConst.OP_UPDATE); + }else{ + saveApprove.setOp(BizConst.OP_INSERT); + } saveApprove.setTongTime(LocalDateTime.now()); }else{ - saveApprove.setOp(BizConst.OP_UPDATE); + saveApprove.setOp(BizConst.OP_INSERT); + saveApprove.setTongID(oldApprove.getTongID()); } saveApprove.setBizTime(LocalDateTime.now()); approveService.saveOrUpdate(saveApprove); @@ -114,10 +132,16 @@ public class ProjectReceiveManage { ProjectCimplement saveCimplement = BeanUtil.copyProperties(cimplement,ProjectCimplement.class); saveCimplement.setBaseProjId(baseProjId); if(Objects.isNull(oldCimplement)){ - saveCimplement.setOp(BizConst.OP_INSERT); + //如果当前 数据不存在 但是我们平台操作是修改 说明之前数据被推送过了那么 可以置为修改update + if(StringUtils.isNotBlank(cimplement.getOp()) && BizConst.OP_UPDATE.equals(cimplement.getOp())){ + saveCimplement.setOp(BizConst.OP_UPDATE); + }else{ + saveCimplement.setOp(BizConst.OP_INSERT); + } saveCimplement.setTongTime(LocalDateTime.now()); }else{ - saveCimplement.setOp(BizConst.OP_UPDATE); + saveCimplement.setOp(BizConst.OP_INSERT); + saveCimplement.setTongID(oldCimplement.getTongID()); } saveCimplement.setBizTime(LocalDateTime.now()); cimplementService.saveOrUpdate(saveCimplement); @@ -133,10 +157,16 @@ public class ProjectReceiveManage { ProjectMimplement saveMimplement = BeanUtil.copyProperties(mimplement,ProjectMimplement.class); saveMimplement.setBaseProjId(baseProjId); if(Objects.isNull(oldMimplement)){ - saveMimplement.setOp(BizConst.OP_INSERT); + //如果当前 数据不存在 但是我们平台操作是修改 说明之前数据被推送过了那么 可以置为修改update + if(StringUtils.isNotBlank(mimplement.getOp()) && BizConst.OP_UPDATE.equals(mimplement.getOp())){ + saveMimplement.setOp(BizConst.OP_UPDATE); + }else{ + saveMimplement.setOp(BizConst.OP_INSERT); + } saveMimplement.setTongTime(LocalDateTime.now()); }else{ - saveMimplement.setOp(BizConst.OP_UPDATE); + saveMimplement.setOp(BizConst.OP_INSERT); + saveMimplement.setTongID(oldMimplement.getTongID()); } saveMimplement.setBizTime(LocalDateTime.now()); mimplementService.saveOrUpdate(saveMimplement); @@ -191,4 +221,19 @@ public class ProjectReceiveManage { return BizConst.OP_SUCCESS; } + + /** + * 删除表里的所有数据 + * @return + */ + public String deleteAll() { + baseInfoService.remove(Wrappers.lambdaQuery(ProjectBaseInfo.class)); + applyService.remove(Wrappers.lambdaQuery(ProjectApply.class)); + approveService.remove(Wrappers.lambdaQuery(ProjectApprove.class)); + cimplementService.remove(Wrappers.lambdaQuery(ProjectCimplement.class)); + mimplementService.remove(Wrappers.lambdaQuery(ProjectMimplement.class)); + procureService.remove(Wrappers.lambdaQuery(ProjectProcure.class)); + log.info("删除所有前置表数据成功"); + return BizConst.OP_SUCCESS; + } }