Browse Source

dimCustomer初始化添加areaCode

master
zxc 5 years ago
parent
commit
5c5d610f38
  1. 25
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/org/result/CustomerAreaCodeResultDTO.java
  2. 9
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/org/StatsCustomerAgencyDao.java
  3. 3
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/crm/CustomerEntity.java
  4. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/stats/DimCustomerEntity.java
  5. 17
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDimServiceImpl.java
  6. 9
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/CustomerAgencyService.java
  7. 18
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/impl/CustomerAgencyServiceImpl.java
  8. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimCustomerServiceImpl.java
  9. 17
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/StatsCustomerAgencyDao.xml
  10. 2
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimCustomerDao.xml

25
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/org/result/CustomerAreaCodeResultDTO.java

@ -0,0 +1,25 @@
package com.epmet.dto.org.result;
import lombok.Data;
import java.io.Serializable;
/**
* @Author zxc
* @DateTime 2021/1/14 上午11:05
*/
@Data
public class CustomerAreaCodeResultDTO implements Serializable {
private static final long serialVersionUID = -4722604654441455214L;
/**
* 客户ID
*/
private String customerId;
/**
* 行政区域编码
*/
private String areaCode;
}

9
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/org/StatsCustomerAgencyDao.java

@ -2,6 +2,7 @@ package com.epmet.dao.org;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.AgencySubTreeDto;
import com.epmet.dto.org.result.CustomerAreaCodeResultDTO;
import com.epmet.entity.org.CustomerAgencyEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -22,4 +23,12 @@ public interface StatsCustomerAgencyDao extends BaseDao<CustomerAgencyEntity> {
List<AgencySubTreeDto> selectSubAgencyByPid(@Param("pid")String pid);
List<CustomerAgencyEntity> listAgenciesByUpdatedTime(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
/**
* @Description 查询客户所属区域编码
* @Param customerIds
* @author zxc
* @date 2021/1/14 上午11:07
*/
List<CustomerAreaCodeResultDTO> selectCustomerAreaCodeById(@Param("customerIds") List<String> customerIds);
}

3
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/crm/CustomerEntity.java

@ -17,6 +17,7 @@
package com.epmet.entity.crm;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.epmet.commons.mybatis.entity.BaseEpmetEntity;
@ -88,4 +89,6 @@ public class CustomerEntity extends BaseEpmetEntity {
*/
private String logo;
@TableField(exist = false)
private String areaCode;
}

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/stats/DimCustomerEntity.java

@ -43,4 +43,6 @@ public class DimCustomerEntity extends BaseEpmetEntity {
*/
private String customerName;
private String areaCode;
}

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

@ -1,6 +1,7 @@
package com.epmet.service.impl;
import com.epmet.constant.RobotConstant;
import com.epmet.dto.org.result.CustomerAreaCodeResultDTO;
import com.epmet.entity.crm.CustomerEntity;
import com.epmet.entity.org.CustomerAgencyEntity;
import com.epmet.entity.org.CustomerDepartmentEntity;
@ -199,6 +200,14 @@ public class StatsDimServiceImpl implements StatsDimService {
List<CustomerEntity> customers = customerService.listValidCustomersByCreateTime(lastInitTime, initTime);
// 添加 areaCode
if (!CollectionUtils.isEmpty(customers)){
List<String> customerIds = customers.stream().map(m -> m.getId()).collect(Collectors.toList());
List<CustomerAreaCodeResultDTO> areaCodes = customerAgencyService.selectCustomerAreaCodeById(customerIds);
if (!CollectionUtils.isEmpty(areaCodes)){
customers.forEach(c -> areaCodes.stream().filter(a -> c.getId().equals(a.getCustomerId())).forEach(a -> c.setAreaCode(a.getAreaCode())));
}
}
return customers;
}
@ -212,6 +221,14 @@ public class StatsDimServiceImpl implements StatsDimService {
if (lastCreatedDim != null) {
// 说明不是首次初始化
List<CustomerEntity> customers = customerService.listValidCustomersByUpdatedTime(lastCreatedDim.getUpdatedTime(), initTime);
// 添加 areaCode
if (!CollectionUtils.isEmpty(customers)){
List<String> customerIds = customers.stream().map(m -> m.getId()).collect(Collectors.toList());
List<CustomerAreaCodeResultDTO> areaCodes = customerAgencyService.selectCustomerAreaCodeById(customerIds);
if (!CollectionUtils.isEmpty(areaCodes)){
customers.forEach(c -> areaCodes.stream().filter(a -> c.getId().equals(a.getCustomerId())).forEach(a -> c.setAreaCode(a.getAreaCode())));
}
}
return customers;
}
return new ArrayList<>();

9
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/CustomerAgencyService.java

@ -1,5 +1,6 @@
package com.epmet.service.org;
import com.epmet.dto.org.result.CustomerAreaCodeResultDTO;
import com.epmet.entity.org.CustomerAgencyEntity;
import java.util.Date;
@ -9,4 +10,12 @@ public interface CustomerAgencyService {
List<CustomerAgencyEntity> listAgenciesByCreateTime(Date statsStartTime, Date statsEndTime);
List<CustomerAgencyEntity> listAgenciesByUpdatedTime(Date updatedTime, Date now);
/**
* @Description 查询客户所属区域编码
* @Param customerIds
* @author zxc
* @date 2021/1/14 上午11:07
*/
List<CustomerAreaCodeResultDTO> selectCustomerAreaCodeById(List<String> customerIds);
}

18
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/impl/CustomerAgencyServiceImpl.java

@ -3,11 +3,14 @@ package com.epmet.service.org.impl;
import com.epmet.commons.dynamic.datasource.annotation.DataSource;
import com.epmet.constant.DataSourceConstant;
import com.epmet.dao.org.StatsCustomerAgencyDao;
import com.epmet.dto.org.result.CustomerAreaCodeResultDTO;
import com.epmet.entity.org.CustomerAgencyEntity;
import com.epmet.service.org.CustomerAgencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -27,4 +30,19 @@ public class CustomerAgencyServiceImpl implements CustomerAgencyService {
public List<CustomerAgencyEntity> listAgenciesByUpdatedTime(Date startTime, Date endTime) {
return customerAgencyDao.listAgenciesByUpdatedTime(startTime, endTime);
}
/**
* @Description 查询客户所属区域编码
* @Param customerIds
* @author zxc
* @date 2021/1/14 上午11:07
*/
@Override
public List<CustomerAreaCodeResultDTO> selectCustomerAreaCodeById(List<String> customerIds) {
if (!CollectionUtils.isEmpty(customerIds)){
List<CustomerAreaCodeResultDTO> resultDTOS = customerAgencyDao.selectCustomerAreaCodeById(customerIds);
return resultDTOS;
}
return new ArrayList<>();
}
}

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimCustomerServiceImpl.java

@ -128,6 +128,7 @@ public class DimCustomerServiceImpl extends BaseServiceImpl<DimCustomerDao, DimC
for (CustomerEntity customer : newCustomers) {
DimCustomerEntity dim = new DimCustomerEntity();
dim.setCustomerName(customer.getCustomerName());
dim.setAreaCode(customer.getAreaCode());
dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setId(customer.getId());
@ -143,6 +144,7 @@ public class DimCustomerServiceImpl extends BaseServiceImpl<DimCustomerDao, DimC
existsCustomerDim.setCustomerName(updatedCustomer.getCustomerName());
existsCustomerDim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
existsCustomerDim.setUpdatedTime(initTime);
existsCustomerDim.setAreaCode(updatedCustomer.getAreaCode());
baseDao.updateById(existsCustomerDim);
}
}

17
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/StatsCustomerAgencyDao.xml

@ -100,4 +100,21 @@
and UPDATED_TIME <![CDATA[<=]]> #{endTime}
</select>
<!-- 查询客户所属区域编码 -->
<select id="selectCustomerAreaCodeById" resultType="com.epmet.dto.org.result.CustomerAreaCodeResultDTO">
SELECT
CUSTOMER_ID,
AREA_CODE
FROM
customer_agency
WHERE
DEL_FLAG = '0'
AND PID = '0'
AND (
<foreach collection="customerIds" item="customerId" separator=" OR ">
CUSTOMER_ID = #{customerId}
</foreach>
)
</select>
</mapper>

2
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimCustomerDao.xml

@ -15,6 +15,7 @@
<select id="getLatestCreatedDimEntity" resultType="com.epmet.entity.stats.DimCustomerEntity">
SELECT id,
customer_name,
area_code,
del_flag,
revision,
created_by,
@ -30,6 +31,7 @@
select
id,
customer_name,
area_code,
del_flag,
revision,
created_by,

Loading…
Cancel
Save