Browse Source

1.增加网格维度初始化

master
wxz 5 years ago
parent
commit
75d5d7ae43
  1. 20
      epmet-module/data-statistical/data-statistical-server/pom.xml
  2. 16
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DimController.java
  3. 44
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/org/CustomerGridDao.java
  4. 8
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimGridDao.java
  5. 82
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/org/CustomerGridEntity.java
  6. 7
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsDimService.java
  7. 68
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDimServiceImpl.java
  8. 17
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/CustomerGridService.java
  9. 25
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/impl/CustomerGridServiceImpl.java
  10. 7
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimGridService.java
  11. 15
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimGridServiceImpl.java
  12. 13
      epmet-module/data-statistical/data-statistical-server/src/main/resources/bootstrap.yml
  13. 21
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerGridDao.xml
  14. 8
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimGridDao.xml

20
epmet-module/data-statistical/data-statistical-server/pom.xml

@ -99,33 +99,33 @@
<!-- 数据库配置-->
<datasource.druid.stats.url>
<![CDATA[jdbc:mysql://118.190.150.119:47306/epmet_data_statistical?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai]]>
<![CDATA[jdbc:mysql://192.168.1.130:3306/epmet_data_statistical?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai]]>
</datasource.druid.stats.url>
<datasource.druid.stats.username>epmet_data_statistical_user</datasource.druid.stats.username>
<datasource.druid.stats.password>EpmEt-db-UsEr</datasource.druid.stats.password>
<datasource.druid.org.url>
<![CDATA[jdbc:mysql://118.190.150.119:47306/epmet_gov_org?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai]]>
<![CDATA[jdbc:mysql://192.168.1.130:3306/epmet_gov_org?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai]]>
</datasource.druid.org.url>
<datasource.druid.org.username>epmet_gov_org_user</datasource.druid.org.username>
<datasource.druid.org.password>EpmEt-db-UsEr</datasource.druid.org.password>
<datasource.druid.issue.url>
<![CDATA[jdbc:mysql://118.190.150.119:47306/epmet_gov_issue?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai]]>
<![CDATA[jdbc:mysql://192.168.1.130:3306/epmet_gov_issue?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai]]>
</datasource.druid.issue.url>
<datasource.druid.issue.username>epmet_gov_issue_user</datasource.druid.issue.username>
<datasource.druid.issue.password>EpmEt-db-UsEr</datasource.druid.issue.password>
<datasource.druid.project.url>
<![CDATA[jdbc:mysql://118.190.150.119:47306/epmet_gov_project?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai]]>
<![CDATA[jdbc:mysql://192.168.1.130:3306/epmet_gov_project?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai]]>
</datasource.druid.project.url>
<datasource.druid.project.username>epmet_gov_project_user</datasource.druid.project.username>
<datasource.druid.project.password>EpmEt-db-UsEr</datasource.druid.project.password>
<!-- redis配置 -->
<spring.redis.index>0</spring.redis.index>
<spring.redis.host>118.190.150.119</spring.redis.host>
<spring.redis.port>47379</spring.redis.port>
<spring.redis.host>192.168.1.130</spring.redis.host>
<spring.redis.port>6379</spring.redis.port>
<spring.redis.password>123456</spring.redis.password>
<!-- nacos -->
<nacos.register-enabled>false</nacos.register-enabled>
@ -140,8 +140,8 @@
<spring.flyway.enabled>false</spring.flyway.enabled>
<!--线程池配置-->
<thread.pool.core-pool-size>10</thread.pool.core-pool-size>
<thread.pool.max-pool-size>20</thread.pool.max-pool-size>
<thread.pool.core-pool-size>5</thread.pool.core-pool-size>
<thread.pool.max-pool-size>8</thread.pool.max-pool-size>
<thread.pool.queue-capacity>10</thread.pool.queue-capacity>
<thread.pool.keep-alive>30</thread.pool.keep-alive>
</properties>
@ -198,8 +198,8 @@
<spring.flyway.enabled>true</spring.flyway.enabled>
<!--线程池配置-->
<thread.pool.core-pool-size>10</thread.pool.core-pool-size>
<thread.pool.max-pool-size>30</thread.pool.max-pool-size>
<thread.pool.core-pool-size>5</thread.pool.core-pool-size>
<thread.pool.max-pool-size>8</thread.pool.max-pool-size>
<thread.pool.queue-capacity>10</thread.pool.queue-capacity>
<thread.pool.keep-alive>30</thread.pool.keep-alive>
</properties>

16
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DimController.java

@ -1,6 +1,7 @@
package com.epmet.controller;
import com.epmet.commons.tools.utils.Result;
import com.epmet.service.StatsDimService;
import com.epmet.service.stats.DimDateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
@ -14,14 +15,27 @@ public class DimController {
@Autowired
private DimDateService dimDateService;
@Autowired
private StatsDimService statsDimService;
/**
* 初始化按日维度
* @return
*/
@PostMapping("/date/init")
public Result initDim() {
public Result initDateDim() {
dimDateService.initDimDate();
return new Result();
}
/**
* 初始化网格维度
* @return
*/
@PostMapping("/grid/init")
public Result initGridDim() {
statsDimService.initGridDim();
return new Result();
}
}

44
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/org/CustomerGridDao.java

@ -0,0 +1,44 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.dao.org;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.entity.org.CustomerGridEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
* 客户网格表
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-03-16
*/
@Mapper
public interface CustomerGridDao extends BaseDao<CustomerGridEntity> {
/**
* 根据创建时间截取时间段内的网格
* @param start
* @param end
* @return
*/
List<CustomerGridEntity> listGridsByCreateTime(@Param("start") Date start, @Param("end") Date end);
}

8
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimGridDao.java

@ -18,9 +18,13 @@
package com.epmet.dao.stats;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.entity.org.CustomerGridEntity;
import com.epmet.entity.stats.DimGridEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.Date;
import java.util.List;
/**
* 客户网格维度
*
@ -29,5 +33,7 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface DimGridDao extends BaseDao<DimGridEntity> {
DimGridEntity getLastCreatedGridDimEntity();
}

82
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/org/CustomerGridEntity.java

@ -0,0 +1,82 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.entity.org;
import com.baomidou.mybatisplus.annotation.TableName;
import com.epmet.commons.mybatis.entity.BaseEpmetEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 客户网格表
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-03-16
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("customer_grid")
public class CustomerGridEntity extends BaseEpmetEntity {
private static final long serialVersionUID = 1L;
/**
* 客户ID
*/
private String customerId;
/**
* 网格名称
*/
private String gridName;
/**
* 中心位置经度
*/
private String longitude;
/**
* 中心位置纬度
*/
private String latitude;
/**
* 所属地区码所属组织地区码
*/
private String areaCode;
/**
* 管辖区域
*/
private String manageDistrict;
/**
* 当前网格总人数
*/
private Integer totalUser;
/**
* 所属组织机构IDcustomer_organization.id
*/
private String pid;
/**
* 所有上级组织ID
*/
private String pids;
}

7
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsDimService.java

@ -0,0 +1,7 @@
package com.epmet.service;
public interface StatsDimService {
void initGridDim();
}

68
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDimServiceImpl.java

@ -0,0 +1,68 @@
package com.epmet.service.impl;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.entity.org.CustomerGridEntity;
import com.epmet.entity.stats.DimGridEntity;
import com.epmet.service.StatsDimService;
import com.epmet.service.org.CustomerGridService;
import com.epmet.service.stats.DimGridService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class StatsDimServiceImpl implements StatsDimService {
@Autowired
private DimGridService dimGridService;
@Autowired
private CustomerGridService customerGridService;
@Override
public void initGridDim() {
DimGridEntity lastCreatedGridDim = dimGridService.getLastCreatedGridDim();
List<CustomerGridEntity> grids;
if (lastCreatedGridDim == null) {
// 首次初始化
grids = customerGridService.listGridsByCreateTime(null, null);
} else {
// 非首次初始化
// 结束时间边界与开始时间边界,包含开始时间不包含结束时间。结束时间可以为空,则查询从开始时间往后的所有新创建网格
//Date endTimeBorder = DateUtils.parse(DateUtils.format(new Date(), DateUtils.DATE_PATTERN_YYYYMMDD), DateUtils.DATE_PATTERN_YYYYMMDD);
Date startTimeBorder = DateUtils.parse(DateUtils.format(lastCreatedGridDim.getCreatedTime(), DateUtils.DATE_PATTERN_YYYYMMDD), DateUtils.DATE_PATTERN_YYYYMMDD);
grids = customerGridService.listGridsByCreateTime(startTimeBorder, null);
}
List<DimGridEntity> gridDims = convertCustomerGrid2GridDim(grids);
dimGridService.addGridDims(gridDims);
}
/**
* 将网格信息转换成网格维度信息
* @param grids
* @return
*/
private List<DimGridEntity> convertCustomerGrid2GridDim(List<CustomerGridEntity> grids) {
Date now = new Date();
return grids.stream().map(grid -> {
DimGridEntity dimGrid = new DimGridEntity();
dimGrid.setAgencyId(grid.getPid());
dimGrid.setAreaCode(grid.getAreaCode());
dimGrid.setCustomerId(grid.getCustomerId());
dimGrid.setGridName(grid.getGridName());
dimGrid.setCreatedBy("APP_USER");
dimGrid.setCreatedTime(now);
dimGrid.setDelFlag("0");
dimGrid.setId(grid.getId());
dimGrid.setRevision(0);
dimGrid.setUpdatedBy("APP_USER");
dimGrid.setUpdatedTime(now);
return dimGrid;
}).collect(Collectors.toList());
}
}

17
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/CustomerGridService.java

@ -0,0 +1,17 @@
package com.epmet.service.org;
import com.epmet.entity.org.CustomerGridEntity;
import java.util.Date;
import java.util.List;
public interface CustomerGridService {
/**
* 根据创建时间截取时间段内的网格
* @param start
* @param end
* @return
* @Param("start") Date start, @Param("end") Date end
*/
List<CustomerGridEntity> listGridsByCreateTime(Date start, Date end);
}

25
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/impl/CustomerGridServiceImpl.java

@ -0,0 +1,25 @@
package com.epmet.service.org.impl;
import com.epmet.commons.dynamic.datasource.annotation.DataSource;
import com.epmet.constant.DataSourceConstant;
import com.epmet.dao.org.CustomerGridDao;
import com.epmet.entity.org.CustomerGridEntity;
import com.epmet.service.org.CustomerGridService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
@DataSource(DataSourceConstant.GOV_ORG)
public class CustomerGridServiceImpl implements CustomerGridService {
@Autowired
private CustomerGridDao customerGridDao;
@Override
public List<CustomerGridEntity> listGridsByCreateTime(Date start, Date end) {
return customerGridDao.listGridsByCreateTime(start, end);
}
}

7
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimGridService.java

@ -20,8 +20,11 @@ package com.epmet.service.stats;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.stats.DimGridDTO;
import com.epmet.entity.org.CustomerGridEntity;
import com.epmet.entity.stats.DimGridEntity;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -92,4 +95,8 @@ public interface DimGridService extends BaseService<DimGridEntity> {
* @date 2020-06-16
*/
void delete(String[] ids);
DimGridEntity getLastCreatedGridDim();
void addGridDims(List<DimGridEntity> gridDims);
}

15
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimGridServiceImpl.java

@ -28,7 +28,6 @@ import com.epmet.dto.stats.DimGridDTO;
import com.epmet.entity.stats.DimGridEntity;
import com.epmet.service.stats.DimGridService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -97,4 +96,18 @@ public class DimGridServiceImpl extends BaseServiceImpl<DimGridDao, DimGridEntit
baseDao.deleteBatchIds(Arrays.asList(ids));
}
@Override
public DimGridEntity getLastCreatedGridDim() {
return baseDao.getLastCreatedGridDimEntity();
}
@Transactional
@Override
public void addGridDims(List<DimGridEntity> gridDims) {
for (DimGridEntity gridDim : gridDims) {
baseDao.insert(gridDim);
}
}
}

13
epmet-module/data-statistical/data-statistical-server/src/main/resources/bootstrap.yml

@ -61,19 +61,6 @@ spring:
baseline-on-migrate: true
baseline-version: 0
#stats:
# datasources:
# - name: statsDatasource
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: @datasource.druid.stats.url@
# username: @datasource.druid.stats.username@
# password: @datasource.druid.stats.password@
# - name: orgDatasource
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: @datasource.druid.org.url@
# username: @datasource.druid.org.username@
# password: @datasource.druid.org.password@
management:
endpoints:
web:

21
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerGridDao.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epmet.dao.org.CustomerGridDao">
<!--根据创建时间,截取时间段内的网格-->
<select id="listGridsByCreateTime" resultType="com.epmet.entity.org.CustomerGridEntity">
SELECT *
FROM customer_grid
<where>
DEL_FLAG = 0
<if test="start != null">
AND CREATED_TIME >= #{start}
</if>
<if test="end != null">
AND CREATED_TIME <![CDATA[<]]> #{end}
</if>
</where>
ORDER BY CREATED_TIME ASC;
</select>
</mapper>

8
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimGridDao.xml

@ -3,7 +3,13 @@
<mapper namespace="com.epmet.dao.stats.DimGridDao">
<select id="getLastCreatedGridDimEntity" resultType="com.epmet.entity.stats.DimGridEntity">
SELECT *
FROM dim_grid
WHERE DEL_FLAG = 0
ORDER BY CREATED_TIME DESC
LIMIT 1
</select>
</mapper>
Loading…
Cancel
Save