diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/DimLastSyncRecordDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/DimLastSyncRecordDao.java new file mode 100644 index 0000000000..cdcdeda243 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/DimLastSyncRecordDao.java @@ -0,0 +1,48 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao.evaluationindex.screen; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.evaluationindex.screen.DimLastSyncRecordEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-12-28 + */ +@Mapper +public interface DimLastSyncRecordDao extends BaseDao { + /** + * 查询最后一次同步时间 + * @return + */ + Date getDimLastSyncEndTime(@Param("subject") String subject); + + /** + * 更新最后一次同步时间 + * @param subject + * @param statsEndTime + * @return + */ + int updateLastSyncEndTime(@Param("subject") String subject, @Param("statsEndTime") Date statsEndTime); +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/DimLastSyncRecordEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/DimLastSyncRecordEntity.java new file mode 100644 index 0000000000..d53db62b22 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/DimLastSyncRecordEntity.java @@ -0,0 +1,51 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity.evaluationindex.screen; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-12-28 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("dim_last_sync_record") +public class DimLastSyncRecordEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 主体。agency:机关,department:部门,grid:网格 + */ + private String subject; + + /** + * 最后一次同步时间 + */ + private Date lastSyncTime; + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerDeptEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerDeptEntity.java index d8adca7a34..c0c78ebb24 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerDeptEntity.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerDeptEntity.java @@ -87,4 +87,9 @@ public class ScreenCustomerDeptEntity extends BaseEpmetEntity { * desc: 是否参与上级计算yes:参与;no:不参与 add 01.14 */ private String upToCal; + + /** + * desc: 是否显示 1显示 0不显示 + */ + private String isDisplay; } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerGridEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerGridEntity.java index cf6c373dca..aa566d645d 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerGridEntity.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerGridEntity.java @@ -97,4 +97,9 @@ public class ScreenCustomerGridEntity extends BaseEpmetEntity { * 地区码 */ private String code; + + /** + * desc: 是否显示 1显示 0不显示 + */ + private String isDisplay; } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerAgencyService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerAgencyService.java index 9a46990c1d..a249907314 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerAgencyService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerAgencyService.java @@ -17,6 +17,7 @@ package com.epmet.service.evaluationindex.screen; +import cn.hutool.db.DaoTemplate; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.extract.form.PartyBaseInfoFormDTO; @@ -27,6 +28,7 @@ import com.epmet.dto.extract.result.OrgNameResultDTO; import com.epmet.entity.evaluationindex.screen.ScreenCustomerAgencyEntity; import com.epmet.entity.org.CustomerAgencyEntity; +import java.util.Date; import java.util.List; import java.util.Map; @@ -61,7 +63,7 @@ public interface ScreenCustomerAgencyService extends BaseService agencies2Add, List agencies2Update); + void initAgencies(List agencies2Add, List agencies2Update, Date statsEndTime); /** * @Description 查询下一级机关的ID【即以agencyId为pid的agency】 @@ -164,4 +166,10 @@ public interface ScreenCustomerAgencyService extends BaseService depts2Add, List depts2Update); + void addAndUpdateDepartments(List depts2Add, List depts2Update, Date syncEndTime); + /** + * 查询上次同步的截止时间 + * @return + */ + Date getLastSyncEndTime(); } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerGridService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerGridService.java index bf701b81d3..e7e08d78b2 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerGridService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerGridService.java @@ -27,6 +27,7 @@ import com.epmet.dto.screen.ScreenProjectGridDailyDTO; import com.epmet.entity.evaluationindex.screen.ScreenCustomerGridEntity; import com.epmet.entity.org.CustomerGridEntity; +import java.util.Date; import java.util.List; import java.util.Map; @@ -41,7 +42,7 @@ public interface ScreenCustomerGridService extends BaseService grids2Add, List grids2Update); + void addAndUpdateGrids(List grids2Add, List grids2Update, Date syncEndTime); /** * @Description 查询客户下所有网格ID @@ -129,4 +130,10 @@ public interface ScreenCustomerGridService extends BaseService getGridList(String customerId); + + /** + * 查询上次同步截止时间 + * @return + */ + Date getLastSyncEndTime(); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerAgencyServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerAgencyServiceImpl.java index 7a0b1a5415..249c5bceb0 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerAgencyServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerAgencyServiceImpl.java @@ -25,6 +25,7 @@ import com.epmet.commons.tools.utils.DateUtils; import com.epmet.constant.DataSourceConstant; import com.epmet.constant.OrgSourceTypeConstant; import com.epmet.constant.ScreenConstant; +import com.epmet.dao.evaluationindex.screen.DimLastSyncRecordDao; import com.epmet.dao.evaluationindex.screen.ScreenCustomerAgencyDao; import com.epmet.dao.evaluationindex.screen.ScreenCustomerGridDao; import com.epmet.dto.CustomerAgencyDTO; @@ -34,6 +35,7 @@ import com.epmet.dto.extract.form.ScreenPartyLinkMassesDataFormDTO; import com.epmet.dto.extract.result.CustomerAgencyInfoResultDTO; import com.epmet.dto.extract.result.OrgNameResultDTO; import com.epmet.dto.screen.result.TreeResultDTO; +import com.epmet.entity.evaluationindex.screen.DimLastSyncRecordEntity; import com.epmet.entity.evaluationindex.screen.ScreenCustomerAgencyEntity; import com.epmet.entity.org.CustomerAgencyEntity; import com.epmet.service.evaluationindex.screen.ScreenCustomerAgencyService; @@ -63,6 +65,8 @@ public class ScreenCustomerAgencyServiceImpl extends BaseServiceImpl agencies2Add, List agencies2Update) { + public void initAgencies(List agencies2Add, List agencies2Update, Date statsEndTime) { String dateEndTime = DateUtils.format(new Date(), DateUtils.DATE_PATTERN_YYYYMMDD); if (!CollectionUtils.isEmpty(agencies2Add)) { // 添加 for (CustomerAgencyEntity e : agencies2Add) { - addAgency(e, dateEndTime); + addOrUpdateAgency(e, dateEndTime); } } @@ -137,11 +141,11 @@ public class ScreenCustomerAgencyServiceImpl extends BaseServiceImpl query = new LambdaQueryWrapper<>(); + query.eq(ScreenCustomerAgencyEntity::getCustomerId, e.getCustomerId()); + query.eq(ScreenCustomerAgencyEntity::getAgencyId, e.getId()); + ScreenCustomerAgencyEntity existsOne = screenCustomerAgencyDao.selectOne(query); + if (existsOne != null) { + // 已经存在 + existsOne.setAgencyId(e.getId()); + existsOne.setAgencyName(e.getOrganizationName()); + existsOne.setAllParentNames(e.getAllParentName()); + existsOne.setAreaCode(e.getAreaCode()); + //cae.setAreaMarks(e); + //如果没有区划 则默认暂时不显示 + //if (StringUtils.isEmpty(e.getAreaCode())) { + // existsOne.setIsDisplay(NumConstant.ZERO_STR); + //} else { + // existsOne.setIsDisplay(NumConstant.ONE_STR); + //} + existsOne.setCustomerId(e.getCustomerId()); + existsOne.setDataEndTime(dateEndTime); + existsOne.setLevel(e.getLevel()); + existsOne.setPid(e.getPid()); + existsOne.setPids(e.getPids()); + existsOne.setSourceType(OrgSourceTypeConstant.INTERNAL); + existsOne.setParentAreaCode(e.getParentAreaCode()); + existsOne.setCode(e.getCode()); + screenCustomerAgencyDao.updateById(existsOne); + return; } else { - cae.setIsDisplay(NumConstant.ONE_STR); + // 不存在,需要添加 + ScreenCustomerAgencyEntity cae = new ScreenCustomerAgencyEntity(); + cae.setAgencyId(e.getId()); + cae.setAgencyName(e.getOrganizationName()); + cae.setAllParentNames(e.getAllParentName()); + cae.setAreaCode(e.getAreaCode()); + //cae.setAreaMarks(e); + //如果没有区划 则默认暂时不显示 + if (StringUtils.isEmpty(e.getAreaCode())) { + cae.setIsDisplay(NumConstant.ZERO_STR); + } else { + cae.setIsDisplay(NumConstant.ONE_STR); + } + cae.setCustomerId(e.getCustomerId()); + cae.setDataEndTime(dateEndTime); + cae.setLevel(e.getLevel()); + cae.setPid(e.getPid()); + cae.setPids(e.getPids()); + cae.setSourceType(OrgSourceTypeConstant.INTERNAL); + cae.setParentAreaCode(e.getParentAreaCode()); + cae.setCode(e.getCode()); + screenCustomerAgencyDao.insert(cae); } - cae.setCustomerId(e.getCustomerId()); - cae.setDataEndTime(dateEndTime); - cae.setLevel(e.getLevel()); - cae.setPid(e.getPid()); - cae.setPids(e.getPids()); - cae.setSourceType(OrgSourceTypeConstant.INTERNAL); - cae.setParentAreaCode(e.getParentAreaCode()); - cae.setCode(e.getCode()); - screenCustomerAgencyDao.insert(cae); } /** @@ -355,4 +403,8 @@ public class ScreenCustomerAgencyServiceImpl extends BaseServiceImpl depts2Add, List depts2Update) { + public void addAndUpdateDepartments(List depts2Add, List depts2Update, Date syncEndTime) { String dateStr = DateUtils.format(new Date(), "YYYYmmdd"); for (CustomerDepartmentEntity dept : depts2Add) { ScreenCustomerDeptEntity e = screenCustomerDeptDao.selectByDeptId(dept.getId()); @@ -77,7 +84,22 @@ public class ScreenCustomerDeptServiceImpl extends BaseServiceImpl lastSyncRecordQuery = new LambdaQueryWrapper<>(); + lastSyncRecordQuery.eq(DimLastSyncRecordEntity::getSubject, "department"); + + DimLastSyncRecordEntity syncRecord = dimLastSyncRecordDao.selectOne(lastSyncRecordQuery); + if (syncRecord != null) { + dimLastSyncRecordDao.updateLastSyncEndTime("department", syncEndTime); + } else { + syncRecord = new DimLastSyncRecordEntity(); + syncRecord.setSubject("department"); + syncRecord.setLastSyncTime(syncEndTime); + dimLastSyncRecordDao.insert(syncRecord); + } + } + @Override + public Date getLastSyncEndTime() { + return dimLastSyncRecordDao.getDimLastSyncEndTime("department"); + } } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerGridServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerGridServiceImpl.java index 33fffebc37..fc7048f8e0 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerGridServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerGridServiceImpl.java @@ -22,16 +22,19 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.epmet.commons.dynamic.datasource.annotation.DataSource; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.constant.DataSourceConstant; import com.epmet.constant.OrgSourceTypeConstant; +import com.epmet.dao.evaluationindex.screen.DimLastSyncRecordDao; import com.epmet.dao.evaluationindex.screen.ScreenCustomerGridDao; import com.epmet.dto.extract.form.*; import com.epmet.dto.extract.result.GridInfoResultDTO; import com.epmet.dto.indexcollect.form.CustomerBizOrgFormDTO; import com.epmet.dto.screen.ScreenCustomerGridDTO; import com.epmet.dto.screen.ScreenProjectGridDailyDTO; +import com.epmet.entity.evaluationindex.screen.DimLastSyncRecordEntity; import com.epmet.entity.evaluationindex.screen.ScreenCustomerGridEntity; import com.epmet.entity.org.CustomerGridEntity; import com.epmet.service.evaluationindex.screen.ScreenCustomerGridService; @@ -57,6 +60,8 @@ public class ScreenCustomerGridServiceImpl extends BaseServiceImpl grids2Add, List grids2Update) { + public void addAndUpdateGrids(List grids2Add, List grids2Update, Date syncEndTime) { String dateStr = DateUtils.format(new Date(), "YYYYmmdd"); for (CustomerGridEntity grid : grids2Add) { ScreenCustomerGridEntity screenGrid = screenCustomerGridDao.getByGridId(grid.getId()); if (screenGrid == null) { - ScreenCustomerGridEntity insertOne = new ScreenCustomerGridEntity(); - insertOne.setAllParentIds(grid.getPids()); - insertOne.setCustomerId(grid.getCustomerId()); - insertOne.setDataEndTime(dateStr); - insertOne.setGridId(grid.getId()); - insertOne.setGridName(grid.getGridName()); - insertOne.setParentAgencyId(grid.getPid()); - insertOne.setSourceType(OrgSourceTypeConstant.INTERNAL); - insertOne.setAreaCode(grid.getAreaCode()); - insertOne.setCode(grid.getCode()); - screenCustomerGridDao.insert(insertOne); + screenGrid = new ScreenCustomerGridEntity(); + screenGrid.setAllParentIds(grid.getPids()); + screenGrid.setCustomerId(grid.getCustomerId()); + screenGrid.setDataEndTime(dateStr); + screenGrid.setGridId(grid.getId()); + screenGrid.setGridName(grid.getGridName()); + screenGrid.setParentAgencyId(grid.getPid()); + screenGrid.setSourceType(OrgSourceTypeConstant.INTERNAL); + screenGrid.setAreaCode(grid.getAreaCode()); + screenGrid.setCode(grid.getCode()); + //如果没有区划 则默认暂时不显示 + if (StringUtils.isEmpty(grid.getAreaCode())) { + screenGrid.setIsDisplay(NumConstant.ZERO_STR); + } else { + screenGrid.setIsDisplay(NumConstant.ONE_STR); + } + screenCustomerGridDao.insert(screenGrid); + } else { + screenGrid.setAllParentIds(grid.getPids()); + screenGrid.setCustomerId(grid.getCustomerId()); + screenGrid.setDataEndTime(dateStr); + screenGrid.setGridId(grid.getId()); + screenGrid.setGridName(grid.getGridName()); + screenGrid.setParentAgencyId(grid.getPid()); + screenGrid.setSourceType(OrgSourceTypeConstant.INTERNAL); + screenGrid.setAreaCode(grid.getAreaCode()); + screenGrid.setCode(grid.getCode()); + screenCustomerGridDao.updateById(screenGrid); } } @@ -109,6 +131,19 @@ public class ScreenCustomerGridServiceImpl extends BaseServiceImpl list = baseDao.selectList(wrapper); return ConvertUtils.sourceToTarget(list, ScreenCustomerGridDTO.class).stream().collect(Collectors.toMap(ScreenCustomerGridDTO::getGridId, Function.identity())); } + + @Override + public Date getLastSyncEndTime() { + return dimLastSyncRecordDao.getDimLastSyncEndTime("grid"); + } } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/EIDimServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/EIDimServiceImpl.java index c67213d6d2..47cb0e6d2a 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/EIDimServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/EIDimServiceImpl.java @@ -2,9 +2,6 @@ package com.epmet.service.impl; import com.epmet.dto.screen.ScreenProjectGridDailyDTO; import com.epmet.dto.screen.form.GridCenterPointForm; -import com.epmet.entity.evaluationindex.screen.ScreenCustomerAgencyEntity; -import com.epmet.entity.evaluationindex.screen.ScreenCustomerDeptEntity; -import com.epmet.entity.evaluationindex.screen.ScreenCustomerGridEntity; import com.epmet.entity.org.CustomerAgencyEntity; import com.epmet.entity.org.CustomerDepartmentEntity; import com.epmet.entity.org.CustomerGridEntity; @@ -45,10 +42,11 @@ public class EIDimServiceImpl implements EIDimService { @Override public void initAgencies() { - List agencies2Add = listAgencies2Add(); - List agencies2Update = listAgencies2Update(); + Date statsEndTime = new Date();//DateUtils.integrate(new Date(), DateUtils.DATE_PATTERN); + List agencies2Add = listAgencies2Add(statsEndTime); + List agencies2Update = listAgencies2Update(statsEndTime); - screenCustomerAgencyService.initAgencies(agencies2Add, agencies2Update); + screenCustomerAgencyService.initAgencies(agencies2Add, agencies2Update, statsEndTime); } /** @@ -56,17 +54,9 @@ public class EIDimServiceImpl implements EIDimService { * * @return */ - private List listAgencies2Update() { - ScreenCustomerAgencyEntity e = screenCustomerAgencyService.getLastUpdatedAgency(); - - if (e != null) { - // 说明不是第一次初始化 - Date startTime = e.getUpdatedTime(); - Date endTime = new Date(); - return originCustomerAgencyService.listAgenciesByUpdatedTime(startTime, endTime); - } - - return new ArrayList<>(); + private List listAgencies2Update(Date endTime) { + Date startTime = screenCustomerAgencyService.getDimLastSyncTime(); + return originCustomerAgencyService.listAgenciesByUpdatedTime(startTime, endTime); } /** @@ -74,23 +64,17 @@ public class EIDimServiceImpl implements EIDimService { * * @return */ - private List listAgencies2Add() { - ScreenCustomerAgencyEntity e = screenCustomerAgencyService.getLastAddedAgency(); - - Date endTime = new Date(); - Date startTime = null; - if (e != null) { - startTime = e.getCreatedTime(); - } - + private List listAgencies2Add(Date endTime) { + Date startTime = screenCustomerAgencyService.getDimLastSyncTime(); return originCustomerAgencyService.listAgenciesByCreateTime(null, startTime, endTime); } @Override public void initDepartments() { - List depts2Add = listDepts2Add(); - List depts2Update = listDepts2Update(); - screenCustomerDeptService.addAndUpdateDepartments(depts2Add, depts2Update); + Date syncEndTime = new Date();//DateUtils.integrate(new Date(), DateUtils.DATE_PATTERN); + List depts2Add = listDepts2Add(syncEndTime); + List depts2Update = listDepts2Update(syncEndTime); + screenCustomerDeptService.addAndUpdateDepartments(depts2Add, depts2Update, syncEndTime); } /** @@ -98,17 +82,19 @@ public class EIDimServiceImpl implements EIDimService { * * @return */ - private List listDepts2Update() { - ScreenCustomerDeptEntity lastUpdateDept = screenCustomerDeptService.getLastUpdateDept(); - - if (lastUpdateDept != null) { - // 不是第一次初始化 - Date endTime = new Date(); - Date startTime = lastUpdateDept.getUpdatedTime(); - return originCustomerDepartmentService.listDepartmentsByUpdatedTime(startTime, endTime); - } - - return new ArrayList<>(); + private List listDepts2Update(Date syncEndTime) { + //ScreenCustomerDeptEntity lastUpdateDept = screenCustomerDeptService.getLastUpdateDept(); + // + //if (lastUpdateDept != null) { + // // 不是第一次初始化 + // Date endTime = new Date(); + // Date startTime = lastUpdateDept.getUpdatedTime(); + // return originCustomerDepartmentService.listDepartmentsByUpdatedTime(startTime, endTime); + //} + //return new ArrayList<>(); + + Date lastSyncEndTime = screenCustomerDeptService.getLastSyncEndTime(); + return originCustomerDepartmentService.listDepartmentsByUpdatedTime(lastSyncEndTime, syncEndTime); } /** @@ -116,23 +102,25 @@ public class EIDimServiceImpl implements EIDimService { * * @return */ - private List listDepts2Add() { - ScreenCustomerDeptEntity lastAddDept = screenCustomerDeptService.getLastAddDept(); - - Date startTime = null; - Date endTime = new Date(); - if (lastAddDept != null) { - startTime = lastAddDept.getCreatedTime(); - } - - return originCustomerDepartmentService.listDepartmentsByCreatedTime(null, startTime, endTime); + private List listDepts2Add(Date syncEndTime) { + //ScreenCustomerDeptEntity lastAddDept = screenCustomerDeptService.getLastAddDept(); + // + //Date startTime = null; + //Date endTime = new Date(); + //if (lastAddDept != null) { + // startTime = lastAddDept.getCreatedTime(); + //} + + Date startTime = screenCustomerDeptService.getLastSyncEndTime(); + return originCustomerDepartmentService.listDepartmentsByCreatedTime(null, startTime, syncEndTime); } @Override public void initGrids() { - List grids2Add = listGrids2Add(); - List grids2Update = listGrids2Update(); - screenCustomerGridService.addAndUpdateGrids(grids2Add, grids2Update); + Date syncEndTime = new Date();//DateUtils.integrate(new Date(), DateUtils.DATE_PATTERN); + List grids2Add = listGrids2Add(syncEndTime); + List grids2Update = listGrids2Update(syncEndTime); + screenCustomerGridService.addAndUpdateGrids(grids2Add, grids2Update, syncEndTime); } @Override @@ -159,26 +147,32 @@ public class EIDimServiceImpl implements EIDimService { return result; } - private List listGrids2Update() { - ScreenCustomerGridEntity lastUpdateGrid = screenCustomerGridService.getLastUpdateGrid(); - if (lastUpdateGrid != null) { - Date endTime = new Date(); - Date startTime = lastUpdateGrid.getUpdatedTime(); - return customerGridService.listUpdatedGridsByUpdateTime(startTime, endTime); - } - - return new ArrayList(); + private List listGrids2Update(Date syncEndTime) { + //ScreenCustomerGridEntity lastUpdateGrid = screenCustomerGridService.getLastUpdateGrid(); + //if (lastUpdateGrid != null) { + // Date endTime = new Date(); + // Date startTime = lastUpdateGrid.getUpdatedTime(); + // return customerGridService.listUpdatedGridsByUpdateTime(startTime, endTime); + //} + // + //return new ArrayList(); + + Date lastSyncEndTime = screenCustomerGridService.getLastSyncEndTime(); + return customerGridService.listUpdatedGridsByUpdateTime(lastSyncEndTime, syncEndTime); } - private List listGrids2Add() { - ScreenCustomerGridEntity lastAddGrid = screenCustomerGridService.getLastAddGrid(); - - Date endTime = new Date(); - Date startTime = null; - if (lastAddGrid != null) { - startTime = lastAddGrid.getCreatedTime(); - } - - return customerGridService.listGridsByCreateTime(null, startTime, endTime); + private List listGrids2Add(Date syncEndTime) { + //ScreenCustomerGridEntity lastAddGrid = screenCustomerGridService.getLastAddGrid(); + // + //Date endTime = new Date(); + //Date startTime = null; + //if (lastAddGrid != null) { + // startTime = lastAddGrid.getCreatedTime(); + //} + // + //return customerGridService.listGridsByCreateTime(null, startTime, endTime); + + Date lastSyncEndTime = screenCustomerGridService.getLastSyncEndTime(); + return customerGridService.listGridsByCreateTime(null, lastSyncEndTime, syncEndTime); } } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.27__create_indexdimsyncrecord.sql b/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.27__create_indexdimsyncrecord.sql new file mode 100644 index 0000000000..7e5acdfbf5 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.27__create_indexdimsyncrecord.sql @@ -0,0 +1,15 @@ +create table dim_last_sync_record +( + `ID` varchar(64) primary key comment '主键', + `SUBJECT` varchar(32) not null comment '主体。agency:机关,department:部门,grid:网格', + `LAST_SYNC_TIME` datetime not null comment '最后一次同步时间', + `DEL_FLAG` char(1) NOT NULL DEFAULT '0' COMMENT '删除标识 0未删除;1已删除', + `REVISION` int(11) NOT NULL COMMENT '乐观锁', + `CREATED_BY` varchar(64) NOT NULL COMMENT '创建人', + `CREATED_TIME` datetime NOT NULL COMMENT '创建时间', + `UPDATED_BY` varchar(64) NOT NULL COMMENT '更新人', + `UPDATED_TIME` datetime NOT NULL COMMENT '更新时间' +) default character set utf8mb4 engine InnoDB; + +create unique index dim_last_sync_record_SUBJECT_uindex + on dim_last_sync_record (SUBJECT); \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/DimLastSyncRecordDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/DimLastSyncRecordDao.xml new file mode 100644 index 0000000000..0f574a4702 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/DimLastSyncRecordDao.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + update dim_last_sync_record + set LAST_SYNC_TIME = #{statsEndTime} + where SUBJECT = #{subject} + and DEL_FLAG = '0' + + + + + \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerDepartmentDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerDepartmentDao.xml index 1df3ef3a1a..2ba0e21b5a 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerDepartmentDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerDepartmentDao.xml @@ -44,7 +44,9 @@ from customer_department cd LEFT JOIN customer_agency ca ON ( cd.AGENCY_ID = ca.id and ca.DEL_FLAG='0') - where cd.UPDATED_TIME > #{startTime} - and cd.UPDATED_TIME #{endTime} + where + cd.CREATED_TIME #{startTime} + and cd.UPDATED_TIME >= #{startTime} + and cd.UPDATED_TIME #{endTime} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerGridDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerGridDao.xml index 587b75120e..4ebde89821 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerGridDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerGridDao.xml @@ -71,6 +71,7 @@ pids FROM customer_grid WHERE SYNC_FLAG='1' + AND CREATED_TIME #{startTime} AND UPDATED_TIME >= #{startTime} AND UPDATED_TIME #{endTime} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/StatsCustomerAgencyDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/StatsCustomerAgencyDao.xml index aa337955ad..fa5da30046 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/StatsCustomerAgencyDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/StatsCustomerAgencyDao.xml @@ -102,9 +102,10 @@ district, PARENT_AREA_CODE as parentAreaCode from customer_agency - where SYNC_FLAG='1' + where SYNC_FLAG='1' + AND CREATED_TIME #{startTime} AND UPDATED_TIME >= #{startTime} - and UPDATED_TIME #{endTime} + AND UPDATED_TIME #{endTime}