14 changed files with 324 additions and 27 deletions
@ -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); |
|||
} |
@ -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; |
|||
|
|||
/** |
|||
* 所属组织机构ID(customer_organization.id) |
|||
*/ |
|||
private String pid; |
|||
|
|||
/** |
|||
* 所有上级组织ID |
|||
*/ |
|||
private String pids; |
|||
} |
@ -0,0 +1,7 @@ |
|||
package com.epmet.service; |
|||
|
|||
public interface StatsDimService { |
|||
|
|||
void initGridDim(); |
|||
|
|||
} |
@ -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()); |
|||
} |
|||
} |
@ -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); |
|||
} |
@ -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); |
|||
} |
|||
} |
@ -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> |
Loading…
Reference in new issue