+ * 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.
+ *
+ * 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.dao;
+
+import com.epmet.commons.mybatis.dao.BaseDao;
+import com.epmet.dto.CustomerRelationDTO;
+import com.epmet.entity.CustomerRelationEntity;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 客户关系表(01.14 add)
+ *
+ * @author generator generator@elink-cn.com
+ * @since v1.0.0 2021-02-03
+ */
+@Mapper
+public interface CustomerRelationDao extends BaseDao {
+
+ CustomerRelationDTO selectByCustomerId(String customerId);
+}
\ No newline at end of file
diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/entity/CustomerRelationEntity.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/entity/CustomerRelationEntity.java
new file mode 100644
index 0000000000..4843ba4506
--- /dev/null
+++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/entity/CustomerRelationEntity.java
@@ -0,0 +1,77 @@
+/**
+ * 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.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.epmet.commons.mybatis.entity.BaseEpmetEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 客户关系表(01.14 add)
+ *
+ * @author generator generator@elink-cn.com
+ * @since v1.0.0 2021-02-03
+ */
+@Data
+@EqualsAndHashCode(callSuper=false)
+@TableName("customer_relation")
+public class CustomerRelationEntity extends BaseEpmetEntity {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 客户id
+ */
+ private String customerId;
+
+ /**
+ * 父级客户id;如果是顶级客户,此列=0
+ */
+ private String parentCustomerId;
+
+ /**
+ * 当前客户类型取值: 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;
+
+}
diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerRelationService.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerRelationService.java
new file mode 100644
index 0000000000..29f9118b51
--- /dev/null
+++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerRelationService.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.
+ *
+ * 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.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
+import com.epmet.commons.tools.constant.FieldConstant;
+import com.epmet.commons.tools.constant.NumConstant;
+import com.epmet.commons.tools.constant.StrConstant;
+import com.epmet.commons.tools.page.PageData;
+import com.epmet.commons.tools.utils.ConvertUtils;
+import com.epmet.dao.CustomerRelationDao;
+import com.epmet.dto.CustomerRelationDTO;
+import com.epmet.entity.CustomerRelationEntity;
+import com.epmet.service.CustomerRelationService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 客户关系表(01.14 add)
+ *
+ * @author generator generator@elink-cn.com
+ * @since v1.0.0 2021-02-03
+ */
+@Slf4j
+@Service
+public class CustomerRelationServiceImpl extends BaseServiceImpl implements CustomerRelationService {
+
+ @Override
+ public PageData page(Map params) {
+ IPage page = baseDao.selectPage(
+ getPage(params, FieldConstant.CREATED_TIME, false),
+ getWrapper(params)
+ );
+ return getPageData(page, CustomerRelationDTO.class);
+ }
+
+ @Override
+ public List list(Map params) {
+ List entityList = baseDao.selectList(getWrapper(params));
+
+ return ConvertUtils.sourceToTarget(entityList, CustomerRelationDTO.class);
+ }
+
+ private QueryWrapper getWrapper(Map params){
+ String id = (String)params.get(FieldConstant.ID_HUMP);
+
+ QueryWrapper wrapper = new QueryWrapper<>();
+ wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id);
+
+ return wrapper;
+ }
+
+ @Override
+ public CustomerRelationDTO get(String id) {
+ CustomerRelationEntity entity = baseDao.selectById(id);
+ return ConvertUtils.sourceToTarget(entity, CustomerRelationDTO.class);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void save(CustomerRelationDTO dto) {
+ CustomerRelationEntity entity = ConvertUtils.sourceToTarget(dto, CustomerRelationEntity.class);
+ insert(entity);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void update(CustomerRelationDTO dto) {
+ CustomerRelationEntity entity = ConvertUtils.sourceToTarget(dto, CustomerRelationEntity.class);
+ updateById(entity);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void delete(String[] ids) {
+ // 逻辑删除(@TableLogic 注解)
+ baseDao.deleteBatchIds(Arrays.asList(ids));
+ }
+
+ /**
+ * 根据客户id,查询客户关系表
+ *
+ * @param customerId
+ * @return void
+ * @author generator
+ * @date 2021-02-03
+ */
+ @Override
+ public CustomerRelationDTO getByCustomerId(String customerId) {
+ return baseDao.selectByCustomerId(customerId);
+ }
+
+ /**
+ * 获取某个客户的根客户id
+ *
+ * @param customerId
+ * @return void
+ * @author generator
+ * @date 2021-02-03
+ */
+ @Override
+ public String getRootCustomerId(String customerId) {
+ CustomerRelationDTO customerRelationDTO=this.getByCustomerId(customerId);
+ if (null == customerRelationDTO) {
+ log.info(String.format("根据客户id:%s查找customer_relation为空",customerId));
+ return StrConstant.EPMETY_STR;
+ }
+ log.info(JSON.toJSONString(customerRelationDTO,true));
+ if (!NumConstant.ZERO_STR.equals(customerRelationDTO.getParentCustomerId())) {
+ log.info("parentCustomerId is not equals 0 so continue");
+ return getRootCustomerId(customerRelationDTO.getParentCustomerId());
+ }
+ return customerRelationDTO.getCustomerId();
+ }
+
+}
\ No newline at end of file
diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java
index 9080d1573f..9d4bc93994 100644
--- a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java
+++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java
@@ -42,6 +42,7 @@ import com.epmet.dto.result.*;
import com.epmet.entity.CustomerEntity;
import com.epmet.feign.*;
import com.epmet.redis.CustomerRedis;
+import com.epmet.service.CustomerRelationService;
import com.epmet.service.CustomerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@@ -84,6 +85,8 @@ public class CustomerServiceImpl extends BaseServiceImpl page(Map params) {
@@ -738,4 +741,24 @@ public class CustomerServiceImpl extends BaseServiceImpl
-
+
diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/resources/mapper/CustomerRelationDao.xml b/epmet-module/oper-crm/oper-crm-server/src/main/resources/mapper/CustomerRelationDao.xml
new file mode 100644
index 0000000000..e3af5415b1
--- /dev/null
+++ b/epmet-module/oper-crm/oper-crm-server/src/main/resources/mapper/CustomerRelationDao.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
\ No newline at end of file