diff --git a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/result/CustomerRelationTreeDTO.java b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/result/CustomerRelationTreeDTO.java new file mode 100644 index 0000000000..08780aaa0f --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/result/CustomerRelationTreeDTO.java @@ -0,0 +1,91 @@ +/** + * 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.result; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + + +/** + * 客户关系表(01.14 add) + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-02-03 + */ +@Data +public class CustomerRelationTreeDTO 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; + + /** + * 下一级 + */ + private List children; +} \ No newline at end of file diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerRelationController.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerRelationController.java new file mode 100644 index 0000000000..fa993d1f5d --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerRelationController.java @@ -0,0 +1,88 @@ +package com.epmet.controller; + +import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.aop.NoRepeatSubmit; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.ExcelUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.AssertUtils; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.commons.tools.validator.group.AddGroup; +import com.epmet.commons.tools.validator.group.UpdateGroup; +import com.epmet.commons.tools.validator.group.DefaultGroup; +import com.epmet.dto.CustomerRelationDTO; +import com.epmet.dto.result.CustomerRelationTreeDTO; +import com.epmet.service.CustomerRelationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + + +/** + * 客户关系表(01.14 add) + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-07-06 + */ +@RestController +@RequestMapping("customerRelation") +public class CustomerRelationController { + + @Autowired + private CustomerRelationService customerRelationService; + + @RequestMapping("page") + public Result> page(@RequestParam Map params) { + PageData page = customerRelationService.page(params); + return new Result>().ok(page); + } + + @RequestMapping(value = "{id}", method = {RequestMethod.POST, RequestMethod.GET}) + public Result get(@PathVariable("id") String id) { + CustomerRelationDTO data = customerRelationService.get(id); + return new Result().ok(data); + } + + @NoRepeatSubmit + @PostMapping("save") + public Result save(@RequestBody CustomerRelationDTO dto) { + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + customerRelationService.save(dto); + return new Result(); + } + + @NoRepeatSubmit + @PostMapping("update") + public Result update(@RequestBody CustomerRelationDTO dto) { + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + customerRelationService.update(dto); + return new Result(); + } + + @RequestMapping(value = "delete", method = {RequestMethod.POST, RequestMethod.DELETE}) + public Result delete(@RequestBody String[] ids) { + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + customerRelationService.delete(ids); + return new Result(); + } + + /** + * 客户树 + * + * @param + * @return com.epmet.commons.tools.utils.Result> + * @author zhy + * @date 2022/7/6 13:24 + */ + @PostMapping("customertree") + public Result> customerTree(@LoginUser TokenDto tokenDto) { + return new Result>().ok(customerRelationService.getCustomerTree(tokenDto)); + } +} diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerRelationDao.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerRelationDao.java index 948937062c..b935ef5b08 100644 --- a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerRelationDao.java +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerRelationDao.java @@ -19,8 +19,10 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.dto.CustomerRelationDTO; +import com.epmet.dto.result.CustomerRelationTreeDTO; import com.epmet.entity.CustomerRelationEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -48,4 +50,25 @@ public interface CustomerRelationDao extends BaseDao { * @return java.util.List */ List selectAllSubCustomerIds(String customerId); + + /** + * 客户树根节点 + * + * @param customerId + * @return java.util.List + * @author zhy + * @date 2022/7/6 13:32 + */ + List selectRootCustomerByCustomerId(@Param("customerId") String customerId); + + /** + * 客户树子节点 + * + * @param customerPid + * @return java.util.List + * @author zhy + * @date 2022/7/6 13:32 + */ + List selectSubCustomerByPid(@Param("customerPid") String customerPid); + } \ No newline at end of file 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 index 2776c8b0cf..37700b0ee5 100644 --- 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 @@ -19,7 +19,9 @@ package com.epmet.service; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.dto.CustomerRelationDTO; +import com.epmet.dto.result.CustomerRelationTreeDTO; import com.epmet.entity.CustomerRelationEntity; import java.util.List; @@ -121,4 +123,15 @@ public interface CustomerRelationService extends BaseService getAllSubCustomerIds(String customerId); + + /** + * 客户树 + * + * @param tokenDto + * @return java.util.List + * @author zhy + * @date 2022/7/6 13:32 + */ + List getCustomerTree(TokenDto tokenDto); + } \ No newline at end of file diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerRelationServiceImpl.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerRelationServiceImpl.java index 6a68df0455..6ae414d2e2 100644 --- a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerRelationServiceImpl.java +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerRelationServiceImpl.java @@ -25,10 +25,12 @@ 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.security.dto.TokenDto; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.dao.CustomerRelationDao; import com.epmet.dto.CustomerDTO; import com.epmet.dto.CustomerRelationDTO; +import com.epmet.dto.result.CustomerRelationTreeDTO; import com.epmet.entity.CustomerRelationEntity; import com.epmet.redis.CustomerRedis; import com.epmet.service.CustomerRelationService; @@ -75,8 +77,8 @@ public class CustomerRelationServiceImpl extends BaseServiceImpl getWrapper(Map params){ - String id = (String)params.get(FieldConstant.ID_HUMP); + 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); @@ -134,12 +136,12 @@ public class CustomerRelationServiceImpl extends BaseServiceImpl(); } + @Override + public List getCustomerTree(TokenDto tokenDto) { + List rootList = baseDao.selectRootCustomerByCustomerId(tokenDto.getCustomerId()); + if (!rootList.isEmpty()) { + rootList.forEach(this::getSubCustomer); + } + return rootList; + } + + /** + * 处理子客户 + * + * @param customer + * @return com.epmet.dto.result.CustomerRelationTreeDTO + * @author zhy + * @date 2022/7/6 13:54 + */ + private CustomerRelationTreeDTO getSubCustomer(CustomerRelationTreeDTO customer) { + List children = baseDao.selectSubCustomerByPid(customer.getCustomerId()); + customer.setChildren(children); + if (!children.isEmpty()) { + children.forEach(this::getSubCustomer); + } + return customer; + } + } 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 index f757a48b51..f23b339e58 100644 --- 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 @@ -23,4 +23,25 @@ cr.DEL_FLAG = '0' AND cr.PIDS like CONCAT(#{customerId},'%') + + + + + \ No newline at end of file