diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/crm/CustomerRelationDTO.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/crm/CustomerRelationDTO.java
new file mode 100644
index 0000000000..3a2fa60edf
--- /dev/null
+++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/crm/CustomerRelationDTO.java
@@ -0,0 +1,116 @@
+/**
+ * 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.dto.crm;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+
+/**
+ * 客户关系表(01.14 add)
+ *
+ * @author generator generator@elink-cn.com
+ * @since v1.0.0 2021-02-03
+ */
+@Data
+public class CustomerRelationDTO implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 主键
+ */
+ private String id;
+
+ /**
+ * 客户id
+ */
+ private String customerId;
+
+ /**
+ * 父级客户id;如果是顶级客户,此列=0
+ */
+ private String parentCustomerId;
+
+ /**
+ * 当前客户的所有父级客户id,以英文冒号隔开,如果是顶级客户,此列=0
+ */
+ private String pids;
+
+ /**
+ * 当前客户类型取值: external:外部客户,internal:内部客户
+ */
+ private String customerType;
+
+ /**
+ * 父级客户类型取值: external:外部客户,internal:内部客户;如果是顶级客户,此列=0
+ */
+ private String parentCustomerType;
+
+ /**
+ * open,closed是否启用
+ */
+ private String status;
+
+ /**
+ * 当前客户级别(社区级:community,
+乡(镇、街道)级:street,
+区县级: district,
+市级: city
+省级:province)
+ */
+ private String level;
+
+ /**
+ * 当前客户的地区编码,实际就是根组织的area_code
+ */
+ private String areaCode;
+
+ /**
+ * 删除标识0未删除1已删除
+ */
+ private String delFlag;
+
+ /**
+ * 乐观锁
+ */
+ private Integer revision;
+
+ /**
+ * 创建人
+ */
+ private String createdBy;
+
+ /**
+ * 创建时间
+ */
+ private Date createdTime;
+
+ /**
+ * 更新人
+ */
+ private String updatedBy;
+
+ /**
+ * 更新时间
+ */
+ private Date updatedTime;
+
+}
\ No newline at end of file
diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/stats/form/GmUploadEventFormDTO.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/stats/form/GmUploadEventFormDTO.java
index 13d689fc6a..d4ece8c8e5 100644
--- a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/stats/form/GmUploadEventFormDTO.java
+++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/stats/form/GmUploadEventFormDTO.java
@@ -18,12 +18,6 @@ public class GmUploadEventFormDTO implements Serializable {
private static final long serialVersionUID = -9178779369245037701L;
//为true时需要删除历史数据
private Boolean isFirst;
- //客户Id
- @NotBlank(message = "客户Id不能为空", groups = {UploadEvent.class})
- private String customerId;
- //日维度Id
- @NotBlank(message = "dateId不能为空", groups = {UploadEvent.class})
- private String dateId;
//数据集合对象
@NotEmpty(message = "数据集合对象不能为空",groups = UploadEvent.class)
private List dataList;
@@ -31,8 +25,12 @@ public class GmUploadEventFormDTO implements Serializable {
@Data
public static class DataList{
- //客户Id 【dim_customer.id】
+ //来源类型 external:外部,internal:内部
+ private String sourceType;
+ //客户Id 【dim_customer.id】[接口传入的是来源数据的客户Id]
private String customerId;
+ //数据来源客户Id
+ private String parentCustomerId;
//机关Id 【dim_agency.id】
private String agencyId;
//日维度Id 【dim_date.id】
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/crm/CustomerRelationDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/crm/CustomerRelationDao.java
index 11ec9c119c..db7fab8791 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/crm/CustomerRelationDao.java
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/crm/CustomerRelationDao.java
@@ -18,6 +18,7 @@
package com.epmet.dao.crm;
import com.epmet.commons.mybatis.dao.BaseDao;
+import com.epmet.dto.crm.CustomerRelationDTO;
import com.epmet.dto.indexcal.CustomerSubInfoDTO;
import com.epmet.entity.crm.CustomerRelationEntity;
import org.apache.ibatis.annotations.Mapper;
@@ -51,4 +52,11 @@ public interface CustomerRelationDao extends BaseDao {
* @date 2021/3/23 上午10:21
*/
List selectSubCustomer(@Param("customerId") String customerId);
+
+ /**
+ * @Description 查询客户所属父客户信息
+ * @author sun
+ */
+ CustomerRelationDTO selectByCustomerId(@Param("customerId") String customerId);
+
}
\ No newline at end of file
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/crm/CustomerService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/crm/CustomerService.java
index dbc2cc03f9..d6f9e8e2d3 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/crm/CustomerService.java
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/crm/CustomerService.java
@@ -1,5 +1,6 @@
package com.epmet.service.crm;
+import com.epmet.dto.crm.CustomerRelationDTO;
import com.epmet.entity.crm.CustomerEntity;
import java.util.Date;
@@ -10,4 +11,10 @@ public interface CustomerService {
List listValidCustomersByCreateTime(Date createTimeFrom, Date createTimeTo);
List listValidCustomersByUpdatedTime(Date updatedTime, Date initTime);
+
+ /**
+ * @Description 查询客户所属父客户信息
+ * @author sun
+ */
+ CustomerRelationDTO getByCustomerId(String customerId);
}
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/crm/impl/CustomerServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/crm/impl/CustomerServiceImpl.java
index 056df4e50e..84598562ca 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/crm/impl/CustomerServiceImpl.java
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/crm/impl/CustomerServiceImpl.java
@@ -3,6 +3,8 @@ package com.epmet.service.crm.impl;
import com.epmet.commons.dynamic.datasource.annotation.DataSource;
import com.epmet.constant.DataSourceConstant;
import com.epmet.dao.crm.CustomerDao;
+import com.epmet.dao.crm.CustomerRelationDao;
+import com.epmet.dto.crm.CustomerRelationDTO;
import com.epmet.entity.crm.CustomerEntity;
import com.epmet.service.crm.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -17,6 +19,8 @@ public class CustomerServiceImpl implements CustomerService {
@Autowired
private CustomerDao customerDao;
+ @Autowired
+ private CustomerRelationDao customerRelationDao;
@Override
public List listValidCustomersByCreateTime(Date createTimeFrom, Date createTimeTo) {
@@ -27,4 +31,13 @@ public class CustomerServiceImpl implements CustomerService {
public List listValidCustomersByUpdatedTime(Date startTime, Date endTime) {
return customerDao.listValidCustomersByUpdateTime(startTime, endTime);
}
+
+ /**
+ * @Description 查询客户所属父客户信息
+ * @author sun
+ */
+ @Override
+ public CustomerRelationDTO getByCustomerId(String customerId) {
+ return customerRelationDao.selectByCustomerId(customerId);
+ }
}
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsUserServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsUserServiceImpl.java
index ee68d5dbe7..7ba72ee7ef 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsUserServiceImpl.java
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsUserServiceImpl.java
@@ -3,16 +3,19 @@ package com.epmet.service.impl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.constant.NumConstant;
+import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.ProjectConstant;
import com.epmet.dao.stats.DataStatsDao;
import com.epmet.dto.AgencySubTreeDto;
import com.epmet.dto.CustomerAgencyDTO;
import com.epmet.dto.StatsFormDTO;
+import com.epmet.dto.crm.CustomerRelationDTO;
import com.epmet.dto.stats.form.GmUploadDataFormDTO;
import com.epmet.dto.stats.form.GmUploadEventFormDTO;
import com.epmet.dto.stats.user.result.UserStatisticalData;
import com.epmet.service.StatsUserService;
+import com.epmet.service.crm.CustomerService;
import com.epmet.service.evaluationindex.screen.ScreenCustomerAgencyService;
import com.epmet.service.stats.DimAgencyService;
import com.epmet.service.stats.DimCustomerService;
@@ -26,6 +29,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.Calendar;
@@ -60,6 +64,8 @@ public class StatsUserServiceImpl implements StatsUserService {
private ScreenCustomerAgencyService screenCustomerAgencyService;
@Autowired
private DataStatsDao dataStatsDao;
+ @Autowired
+ private CustomerService customerService;
/**
@@ -149,18 +155,20 @@ public class StatsUserServiceImpl implements StatsUserService {
* @author sun
*/
@Override
+ @Transactional(rollbackFor = Exception.class)
public void gmUploadEvent(GmUploadEventFormDTO formDTO) {
- //1.判断是否批量删除历史数据
- if (formDTO.getIsFirst()) {
- int deleteNum;
- do {
- deleteNum = userService.delGmUploadEvent(formDTO.getCustomerId(), formDTO.getDateId());
- } while (deleteNum > NumConstant.ZERO);
+ //1.数据上报只涉及数据库部分数据,其他数据都是计算出来的,所以不存在删除历史数据,有就更新没有就新增
+ String customerId = formDTO.getDataList().get(0).getCustomerId();
+
+ //2.数据准备
+ //2-1.查询当前客户index库组织信息供数据封装使用
+ List agencyList = screenCustomerAgencyService.getByCustomerId(customerId);
+ //2-2.查询客户所属父客户信息
+ CustomerRelationDTO crm = customerService.getByCustomerId(customerId);
+ if (null == crm) {
+ throw new RenException(String.format("未查询到子客户所属父客户信息,子客户Id->%s", customerId));
}
- //2.查询当前客户index库组织信息供数据封装使用
- List agencyList = screenCustomerAgencyService.getByCustomerId(formDTO.getCustomerId());
-
//3.分批处理上传数据
List> partition = ListUtils.partition(formDTO.getDataList(), NumConstant.ONE_HUNDRED);
partition.forEach(p -> {
@@ -175,6 +183,8 @@ public class StatsUserServiceImpl implements StatsUserService {
}
});
if (bl.get()) {
+ m.setSourceType("external");
+ m.setParentCustomerId(crm.getParentCustomerId());
m.setGridPids(gridPids.toString());
m.setPatrolTotal(NumConstant.ZERO);
m.setTotalTime(NumConstant.ZERO);
@@ -197,6 +207,7 @@ public class StatsUserServiceImpl implements StatsUserService {
* @author sun
*/
@Override
+ @Transactional(rollbackFor = Exception.class)
public void gmUploadData(GmUploadDataFormDTO formDTO) {
//1.判断是否批量删除历史数据
if (formDTO.getIsFirst()) {
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/crm/CustomerRelationDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/crm/CustomerRelationDao.xml
index fad1ca0443..ba3cccf88b 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/crm/CustomerRelationDao.xml
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/crm/CustomerRelationDao.xml
@@ -39,4 +39,15 @@
SELECT * FROM customer_relation WHERE DEL_FLAG = 0 AND PARENT_CUSTOMER_ID = #{customerId}
+
+
+ SELECT
+ *
+ FROM
+ customer_relation
+ WHERE
+ del_flag = '0'
+ AND customer_id = #{customerId}
+
+
\ No newline at end of file
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml
index 4b5a6966f8..d0fc049555 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml
@@ -641,7 +641,9 @@
INSERT INTO stats_staff_patrol_record_daily
(
id,
+ source_type,
customer_id,
+ source_customer_id,
date_id,
week_id,
month_id,
@@ -667,6 +669,8 @@
(
REPLACE(UUID(), '-', ''),
+ #{i.sourceType},
+ #{i.parentCustomerId},
#{i.customerId},
#{i.dateId},
#{i.weekId},
@@ -692,6 +696,9 @@
ON DUPLICATE KEY
UPDATE
+ source_type = values(source_type),
+ customer_id = values(customer_id),
+ source_customer_id = values(source_customer_id),
report_project_count = values(report_project_count),
updated_by = 'BASE_REPORT',
updated_time = NOW()