diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/OrgSourceTypeConstant.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/OrgSourceTypeConstant.java new file mode 100644 index 0000000000..966c3edc80 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/OrgSourceTypeConstant.java @@ -0,0 +1,11 @@ +package com.epmet.constant; + +public interface OrgSourceTypeConstant { + + // 外部 + String EXTERNAL = "external"; + + // 内部 + String INTERNAL = "internal"; + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/EIDimController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/EIDimController.java new file mode 100644 index 0000000000..1c0f7520b0 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/EIDimController.java @@ -0,0 +1,48 @@ +package com.epmet.controller; + +import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.service.EIDimService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * epmet_evaluation_index库的维度controller + */ +@RestController +@RequestMapping("eidim") +public class EIDimController { + + Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private EIDimService eiDimService; + + @PostMapping("init-all") + public Result initAll() { + + try { + //eiDimService.initAgencies(); + } catch (Exception e) { + logger.error("初始化epmet_evaluation_index的agency维度失败:{}", ExceptionUtils.getErrorStackTrace(e)); + } + + try { + //eiDimService.initDepartments(); + } catch (Exception e) { + logger.error("初始化epmet_evaluation_index的department维度失败:{}", ExceptionUtils.getErrorStackTrace(e)); + } + + try { + eiDimService.initGrids(); + } catch (Exception e) { + logger.error("初始化epmet_evaluation_index的grids维度失败:{}", ExceptionUtils.getErrorStackTrace(e)); + } + return new Result(); + } + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerAgencyDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerAgencyDao.java index 8c8f910d37..7d9362a1aa 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerAgencyDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerAgencyDao.java @@ -119,4 +119,10 @@ public interface ScreenCustomerAgencyDao extends BaseDao selectSubAgencyList(@Param("pids") String pids); + + ScreenCustomerAgencyEntity getLastAddedAgency(); + + ScreenCustomerAgencyEntity getLastUpdatedAgency(); + + ScreenCustomerAgencyEntity selectByAgencyId(String agencyId); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerDeptDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerDeptDao.java index cbe11d059c..3a992c7ca6 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerDeptDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerDeptDao.java @@ -86,4 +86,14 @@ public interface ScreenCustomerDeptDao extends BaseDao * @Date 16:57 2020-09-03 **/ List selectListDeptInfo(@Param("customerId")String customerId); + + /** + * 查询最后一次添加的部门 + * @return + */ + ScreenCustomerDeptEntity getLastAddDept(); + + ScreenCustomerDeptEntity getLastUpdateDept(); + + ScreenCustomerDeptEntity selectByDeptId(String deptId); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerGridDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerGridDao.java index 335548ac8a..5e49d15e0c 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerGridDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerGridDao.java @@ -122,4 +122,10 @@ public interface ScreenCustomerGridDao extends BaseDao * @date 2020/9/22 2:16 下午 */ List selectGridIdByAgencyId(@Param("agencyId")String agencyId); + + ScreenCustomerGridEntity getLastAddGrid(); + + ScreenCustomerGridEntity getLastUpdateGrid(); + + ScreenCustomerGridEntity getByGridId(String gridId); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerAgencyEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerAgencyEntity.java index e06907ca84..da0a164888 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerAgencyEntity.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerAgencyEntity.java @@ -93,6 +93,8 @@ public class ScreenCustomerAgencyEntity extends BaseEpmetEntity { */ private String areaCode; + private String sourceType; + /** * 数据更新至: yyyy|yyyyMM|yyyyMMdd(08-21新增) */ 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 6fdb38f4b8..474243815a 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 @@ -75,4 +75,6 @@ public class ScreenCustomerDeptEntity extends BaseEpmetEntity { */ private String dataEndTime; + private String sourceType; + } 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 19fdd132be..0b98a125eb 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 @@ -79,4 +79,6 @@ public class ScreenCustomerGridEntity extends BaseEpmetEntity { * 所有上级ID,用英文逗号分开(8.26新增) */ private String allParentIds; + + private String sourceType; } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/EIDimService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/EIDimService.java new file mode 100644 index 0000000000..64ba669caf --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/EIDimService.java @@ -0,0 +1,13 @@ +package com.epmet.service; + +import org.springframework.stereotype.Service; + +/** + * epmet_evaluation_index 维度的service + */ +@Service +public interface EIDimService { + void initAgencies(); + void initDepartments(); + void initGrids(); +} 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 afce93ccad..4928669aaa 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,10 @@ package com.epmet.service.evaluationindex.screen; +import com.epmet.entity.evaluationindex.screen.ScreenCustomerAgencyEntity; +import com.epmet.entity.org.CustomerAgencyEntity; + +import java.util.List; import java.util.Map; /** @@ -38,4 +42,9 @@ public interface ScreenCustomerAgencyService{ */ Map selectAllSubAgencyId(String agencyId, String customerId); + ScreenCustomerAgencyEntity getLastAddedAgency(); + + ScreenCustomerAgencyEntity getLastUpdatedAgency(); + + void initAgencies(List agencies2Add, List agencies2Update); } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerDeptService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerDeptService.java index e2acb8dee2..88405c7f49 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerDeptService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerDeptService.java @@ -19,6 +19,9 @@ package com.epmet.service.evaluationindex.screen; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.entity.evaluationindex.screen.ScreenCustomerDeptEntity; +import com.epmet.entity.org.CustomerDepartmentEntity; + +import java.util.List; /** * 部门信息 @@ -28,4 +31,14 @@ import com.epmet.entity.evaluationindex.screen.ScreenCustomerDeptEntity; */ public interface ScreenCustomerDeptService extends BaseService { + /** + * 最后一次添加的部门 + * @return + */ + ScreenCustomerDeptEntity getLastAddDept(); + + ScreenCustomerDeptEntity getLastUpdateDept(); + + void addAndUpdateDepartments(List depts2Add, List depts2Update); + } \ 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 5093fedbae..d12238c077 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 @@ -20,6 +20,9 @@ package com.epmet.service.evaluationindex.screen; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.entity.evaluationindex.screen.ScreenCustomerGridEntity; +import com.epmet.entity.org.CustomerGridEntity; + +import java.util.List; /** * 网格(党支部)信息 @@ -29,4 +32,8 @@ import com.epmet.entity.evaluationindex.screen.ScreenCustomerGridEntity; */ public interface ScreenCustomerGridService extends BaseService { + ScreenCustomerGridEntity getLastAddGrid(); + ScreenCustomerGridEntity getLastUpdateGrid(); + + void addAndUpdateGrids(List grids2Add, List grids2Update); } \ 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/ScreenCustomerAgencyServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerAgencyServiceImpl.java index 379f57306a..55193ccacb 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 @@ -18,20 +18,22 @@ package com.epmet.service.evaluationindex.screen.impl; import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.constant.OrgSourceTypeConstant; import com.epmet.dao.evaluationindex.screen.ScreenCustomerAgencyDao; import com.epmet.dao.evaluationindex.screen.ScreenCustomerGridDao; import com.epmet.dto.screen.result.TreeResultDTO; import com.epmet.constant.ScreenConstant; +import com.epmet.entity.evaluationindex.screen.ScreenCustomerAgencyEntity; +import com.epmet.entity.org.CustomerAgencyEntity; import com.epmet.service.evaluationindex.screen.ScreenCustomerAgencyService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * 组织机构信息 @@ -86,4 +88,67 @@ public class ScreenCustomerAgencyServiceImpl implements ScreenCustomerAgencyServ } return result; } + + @Override + public ScreenCustomerAgencyEntity getLastAddedAgency() { + return screenCustomerAgencyDao.getLastAddedAgency(); + } + + @Override + public ScreenCustomerAgencyEntity getLastUpdatedAgency() { + return screenCustomerAgencyDao.getLastUpdatedAgency(); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public void initAgencies(List agencies2Add, List agencies2Update) { + String dateEndTime = DateUtils.format(new Date(), "YYYYmmdd"); + if (!CollectionUtils.isEmpty(agencies2Add)) { + // 添加 + for (CustomerAgencyEntity e : agencies2Add) { + addAgency(e, dateEndTime); + } + } + + if (!CollectionUtils.isEmpty(agencies2Update)) { + // 更新 + for (CustomerAgencyEntity e : agencies2Update) { + ScreenCustomerAgencyEntity exists = screenCustomerAgencyDao.selectByAgencyId(e.getId()); + if (exists != null) { + exists.setAgencyName(e.getOrganizationName()); + exists.setPids(e.getPids()); + exists.setPid(e.getPid()); + exists.setLevel(e.getLevel()); + exists.setDataEndTime(dateEndTime); + exists.setAreaCode(e.getAreaCode()); + exists.setAllParentNames(e.getAllParentName()); + updateAgency(exists); + } + } + } + } + + private void updateAgency(ScreenCustomerAgencyEntity exists) { + screenCustomerAgencyDao.updateById(exists); + } + + /** + * 添加agency + * @param e + */ + private void addAgency(CustomerAgencyEntity e, String dateEndTime) { + ScreenCustomerAgencyEntity cae = new ScreenCustomerAgencyEntity(); + cae.setAgencyId(e.getId()); + cae.setAgencyName(e.getOrganizationName()); + cae.setAllParentNames(e.getAllParentName()); + cae.setAreaCode(e.getAreaCode()); + //cae.setAreaMarks(e); + cae.setCustomerId(e.getCustomerId()); + cae.setDataEndTime(dateEndTime); + cae.setLevel(e.getLevel()); + cae.setPid(e.getPid()); + cae.setPids(e.getPids()); + cae.setSourceType(OrgSourceTypeConstant.INTERNAL); + screenCustomerAgencyDao.insert(cae); + } } \ 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/ScreenCustomerDeptServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerDeptServiceImpl.java index ae997fc4b3..0570eb7de1 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerDeptServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerDeptServiceImpl.java @@ -18,10 +18,18 @@ package com.epmet.service.evaluationindex.screen.impl; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.constant.OrgSourceTypeConstant; import com.epmet.dao.evaluationindex.screen.ScreenCustomerDeptDao; import com.epmet.entity.evaluationindex.screen.ScreenCustomerDeptEntity; +import com.epmet.entity.org.CustomerDepartmentEntity; import com.epmet.service.evaluationindex.screen.ScreenCustomerDeptService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.List; /** * 部门信息 @@ -32,5 +40,52 @@ import org.springframework.stereotype.Service; @Service public class ScreenCustomerDeptServiceImpl extends BaseServiceImpl implements ScreenCustomerDeptService { + @Autowired + private ScreenCustomerDeptDao screenCustomerDeptDao; + + @Override + public ScreenCustomerDeptEntity getLastAddDept() { + return screenCustomerDeptDao.getLastAddDept(); + } + + @Override + public ScreenCustomerDeptEntity getLastUpdateDept() { + return screenCustomerDeptDao.getLastUpdateDept(); + } + + /** + * 添加/更新部门列表 + * @param depts2Add + * @param depts2Update + */ + @Transactional(rollbackFor = Exception.class) + public void addAndUpdateDepartments(List depts2Add, List depts2Update) { + String dateStr = DateUtils.format(new Date(), "YYYYmmdd"); + for (CustomerDepartmentEntity dept : depts2Add) { + ScreenCustomerDeptEntity e = screenCustomerDeptDao.selectByDeptId(dept.getId()); + if (e == null) { + e = new ScreenCustomerDeptEntity(); + e.setCustomerId(dept.getCustomerId()); + e.setDataEndTime(dateStr); + e.setDeptId(dept.getId()); + e.setDeptName(dept.getDepartmentName()); + e.setParentAgencyId(dept.getAgencyId()); + e.setSourceType(OrgSourceTypeConstant.INTERNAL); + screenCustomerDeptDao.insert(e); + } + } + + for (CustomerDepartmentEntity dept : depts2Update) { + ScreenCustomerDeptEntity e = screenCustomerDeptDao.selectByDeptId(dept.getId()); + if (e != null) { + // 不是新增的 + e.setParentAgencyId(dept.getAgencyId()); + e.setDeptName(dept.getDepartmentName()); + e.setDataEndTime(dateStr); + e.setCustomerId(dept.getCustomerId()); + screenCustomerDeptDao.updateById(e); + } + } + } } \ 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 fe8a29e993..a2922cbc19 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 @@ -18,11 +18,21 @@ package com.epmet.service.evaluationindex.screen.impl; +import com.epmet.commons.dynamic.datasource.annotation.DataSource; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.constant.DataSourceConstant; +import com.epmet.constant.OrgSourceTypeConstant; import com.epmet.dao.evaluationindex.screen.ScreenCustomerGridDao; import com.epmet.entity.evaluationindex.screen.ScreenCustomerGridEntity; +import com.epmet.entity.org.CustomerGridEntity; import com.epmet.service.evaluationindex.screen.ScreenCustomerGridService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.List; /** * 网格(党支部)信息 @@ -30,8 +40,53 @@ import org.springframework.stereotype.Service; * @author generator generator@elink-cn.com * @since v1.0.0 2020-09-22 */ +@DataSource(DataSourceConstant.EVALUATION_INDEX) @Service public class ScreenCustomerGridServiceImpl extends BaseServiceImpl implements ScreenCustomerGridService { + @Autowired + private ScreenCustomerGridDao screenCustomerGridDao; + + @Override + public ScreenCustomerGridEntity getLastAddGrid() { + return screenCustomerGridDao.getLastAddGrid(); + } + + @Override + public ScreenCustomerGridEntity getLastUpdateGrid() { + return screenCustomerGridDao.getLastUpdateGrid(); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public void addAndUpdateGrids(List grids2Add, List grids2Update) { + 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); + screenCustomerGridDao.insert(insertOne); + } + } + for (CustomerGridEntity grid : grids2Update) { + ScreenCustomerGridEntity screenGrid = screenCustomerGridDao.getByGridId(grid.getId()); + if (screenGrid != null) { + //说明之前已经插入了该数据 + screenGrid.setParentAgencyId(grid.getPid()); + screenGrid.setAllParentIds(grid.getPid()); + screenGrid.setCustomerId(grid.getCustomerId()); + screenGrid.setDataEndTime(dateStr); + screenGrid.setGridName(grid.getGridName()); + screenCustomerGridDao.updateById(screenGrid); + } + } + } } \ No newline at end of file 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 new file mode 100644 index 0000000000..d35aa6bec6 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/EIDimServiceImpl.java @@ -0,0 +1,155 @@ +package com.epmet.service.impl; + +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; +import com.epmet.service.EIDimService; +import com.epmet.service.evaluationindex.screen.ScreenCustomerAgencyService; +import com.epmet.service.evaluationindex.screen.ScreenCustomerDeptService; +import com.epmet.service.evaluationindex.screen.ScreenCustomerGridService; +import com.epmet.service.org.CustomerAgencyService; +import com.epmet.service.org.CustomerDepartmentService; +import com.epmet.service.org.CustomerGridService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Service +public class EIDimServiceImpl implements EIDimService { + + @Autowired + private ScreenCustomerAgencyService screenCustomerAgencyService; + + @Autowired + private ScreenCustomerDeptService screenCustomerDeptService; + + @Autowired + private ScreenCustomerGridService screenCustomerGridService; + + @Autowired + private CustomerAgencyService originCustomerAgencyService; + + @Autowired + private CustomerDepartmentService originCustomerDepartmentService; + + @Autowired + private CustomerGridService customerGridService; + + @Override + public void initAgencies() { + List agencies2Add = listAgencies2Add(); + List agencies2Update = listAgencies2Update(); + + screenCustomerAgencyService.initAgencies(agencies2Add, agencies2Update); + } + + /** + * 查询可更新的单位 + * @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<>(); + } + + /** + * 查询可增加的单位 + * @return + */ + private List listAgencies2Add() { + ScreenCustomerAgencyEntity e = screenCustomerAgencyService.getLastAddedAgency(); + + Date endTime = new Date(); + Date startTime = null; + if (e != null) { + startTime = e.getCreatedTime(); + } + + return originCustomerAgencyService.listAgenciesByCreateTime(startTime, endTime); + } + + @Override + public void initDepartments() { + List depts2Add = listDepts2Add(); + List depts2Update = listDepts2Update(); + screenCustomerDeptService.addAndUpdateDepartments(depts2Add, depts2Update); + } + + /** + * 查询需要更新的部门列表 + * @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<>(); + } + + /** + * 查询需要新增的部门列表 + * @return + */ + private List listDepts2Add() { + ScreenCustomerDeptEntity lastAddDept = screenCustomerDeptService.getLastAddDept(); + + Date startTime = null; + Date endTime = new Date(); + if (lastAddDept != null) { + startTime = lastAddDept.getCreatedTime(); + } + + return originCustomerDepartmentService.listDepartmentsByCreatedTime(startTime, endTime); + } + + @Override + public void initGrids() { + List grids2Add = listGrids2Add(); + List grids2Update =listGrids2Update(); + screenCustomerGridService.addAndUpdateGrids(grids2Add, grids2Update); + } + + 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 listGrids2Add() { + ScreenCustomerGridEntity lastAddGrid = screenCustomerGridService.getLastAddGrid(); + + Date endTime = new Date(); + Date startTime = null; + if (lastAddGrid != null) { + startTime = lastAddGrid.getCreatedTime(); + } + + return customerGridService.listGridsByCreateTime(startTime, endTime); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/CustomerDepartmentService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/CustomerDepartmentService.java index 15178715ed..f7d5900682 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/CustomerDepartmentService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/CustomerDepartmentService.java @@ -9,5 +9,5 @@ public interface CustomerDepartmentService { List listDepartmentsByCreatedTime(Date createdTimeFrom, Date createdTimeTo); - List listDepartmentsByUpdatedTime(Date createdTime, Date initTime); + List listDepartmentsByUpdatedTime(Date startTime, Date endTime); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.4__screen_org_add_source_col.sql b/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.4__screen_org_add_source_col.sql new file mode 100644 index 0000000000..88d6e55b66 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.4__screen_org_add_source_col.sql @@ -0,0 +1,3 @@ +alter table screen_customer_agency add column SOURCE_TYPE varchar(20) default 'external' after AREA_CODE; +alter table screen_customer_dept add column SOURCE_TYPE varchar(20) default 'external' after DEPT_MARK; +alter table screen_customer_grid add column SOURCE_TYPE varchar(20) default 'external' after PARTY_MARK; \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml index 3fc77c4d7e..4ee8e31c6f 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml @@ -162,4 +162,85 @@ AND pids = #{pids} ORDER BY created_time DESC + + + + + + diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerDeptDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerDeptDao.xml index 1533203d14..26c34d328b 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerDeptDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerDeptDao.xml @@ -91,4 +91,76 @@ DEL_FLAG = '0' AND CUSTOMER_ID =#{customerId} + + + + + + diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerGridDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerGridDao.xml index f4695debc1..3a15aae8e7 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerGridDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerGridDao.xml @@ -145,4 +145,76 @@ AND parent_agency_id = #{agencyId} ORDER BY created_time DESC + + + + + +