19 changed files with 678 additions and 10 deletions
@ -0,0 +1,21 @@ |
|||
package com.epmet.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 009、根据客户id查询根客户信息入参DTO |
|||
* |
|||
* @author yinzuomei@elink-cn.com |
|||
* @date 2021/2/2 22:25 |
|||
*/ |
|||
@Data |
|||
public class CustomerInfoQueryFormDTO { |
|||
|
|||
/** |
|||
* 客户id |
|||
*/ |
|||
@NotBlank(message = "客户id不能为空") |
|||
private String customerId; |
|||
} |
@ -0,0 +1,22 @@ |
|||
package com.epmet.dto.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 009、根据客户id查询根客户信息 返参DTO |
|||
* |
|||
* @author yinzuomei@elink-cn.com |
|||
* @date 2021/2/2 22:26 |
|||
*/ |
|||
@Data |
|||
public class CustomerInfoQueryResultDTO { |
|||
|
|||
/** |
|||
* 当前客户id的根级客户id,返回值0代表当前客户是根客户没有上级客户 |
|||
*/ |
|||
private String rootCustomerId; |
|||
/** |
|||
* 客户id |
|||
*/ |
|||
private String customerId; |
|||
} |
@ -0,0 +1,110 @@ |
|||
/** |
|||
* 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.dto; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
import lombok.Data; |
|||
|
|||
|
|||
/** |
|||
* 客户关系表(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; |
|||
|
|||
/** |
|||
* 当前客户类型取值: 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; |
|||
|
|||
} |
@ -0,0 +1,23 @@ |
|||
package com.epmet.dto.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 009、根据客户id查询根客户信息 返参DTO |
|||
* |
|||
* @author yinzuomei@elink-cn.com |
|||
* @date 2021/2/3 11:15 |
|||
*/ |
|||
@Data |
|||
public class CustomerRelationInfoResultDTO { |
|||
/** |
|||
* 客户id |
|||
*/ |
|||
private String customerId; |
|||
|
|||
/** |
|||
* 当前客户id的根级客户id,返回值0代表当前客户是根客户没有上级客户 |
|||
*/ |
|||
private String rootCustomerId; |
|||
|
|||
} |
@ -0,0 +1,35 @@ |
|||
/** |
|||
* 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; |
|||
|
|||
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<CustomerRelationEntity> { |
|||
|
|||
CustomerRelationDTO selectByCustomerId(String customerId); |
|||
} |
@ -0,0 +1,77 @@ |
|||
/** |
|||
* 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; |
|||
|
|||
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; |
|||
|
|||
} |
@ -0,0 +1,116 @@ |
|||
/** |
|||
* 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.service; |
|||
|
|||
import com.epmet.commons.mybatis.service.BaseService; |
|||
import com.epmet.commons.tools.page.PageData; |
|||
import com.epmet.dto.CustomerRelationDTO; |
|||
import com.epmet.entity.CustomerRelationEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 客户关系表(01.14 add) |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2021-02-03 |
|||
*/ |
|||
public interface CustomerRelationService extends BaseService<CustomerRelationEntity> { |
|||
|
|||
/** |
|||
* 默认分页 |
|||
* |
|||
* @param params |
|||
* @return PageData<CustomerRelationDTO> |
|||
* @author generator |
|||
* @date 2021-02-03 |
|||
*/ |
|||
PageData<CustomerRelationDTO> page(Map<String, Object> params); |
|||
|
|||
/** |
|||
* 默认查询 |
|||
* |
|||
* @param params |
|||
* @return java.util.List<CustomerRelationDTO> |
|||
* @author generator |
|||
* @date 2021-02-03 |
|||
*/ |
|||
List<CustomerRelationDTO> list(Map<String, Object> params); |
|||
|
|||
/** |
|||
* 单条查询 |
|||
* |
|||
* @param id |
|||
* @return CustomerRelationDTO |
|||
* @author generator |
|||
* @date 2021-02-03 |
|||
*/ |
|||
CustomerRelationDTO get(String id); |
|||
|
|||
/** |
|||
* 默认保存 |
|||
* |
|||
* @param dto |
|||
* @return void |
|||
* @author generator |
|||
* @date 2021-02-03 |
|||
*/ |
|||
void save(CustomerRelationDTO dto); |
|||
|
|||
/** |
|||
* 默认更新 |
|||
* |
|||
* @param dto |
|||
* @return void |
|||
* @author generator |
|||
* @date 2021-02-03 |
|||
*/ |
|||
void update(CustomerRelationDTO dto); |
|||
|
|||
/** |
|||
* 批量删除 |
|||
* |
|||
* @param ids |
|||
* @return void |
|||
* @author generator |
|||
* @date 2021-02-03 |
|||
*/ |
|||
void delete(String[] ids); |
|||
|
|||
/** |
|||
* 根据客户id,查询客户关系表 |
|||
* |
|||
* @param customerId |
|||
* @return void |
|||
* @author generator |
|||
* @date 2021-02-03 |
|||
*/ |
|||
CustomerRelationDTO getByCustomerId(String customerId); |
|||
|
|||
/** |
|||
* 获取某个客户的根客户id |
|||
* |
|||
* @param customerId |
|||
* @return void |
|||
* @author generator |
|||
* @date 2021-02-03 |
|||
*/ |
|||
String getRootCustomerId(String customerId); |
|||
|
|||
} |
@ -0,0 +1,140 @@ |
|||
/** |
|||
* 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.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<CustomerRelationDao, CustomerRelationEntity> implements CustomerRelationService { |
|||
|
|||
@Override |
|||
public PageData<CustomerRelationDTO> page(Map<String, Object> params) { |
|||
IPage<CustomerRelationEntity> page = baseDao.selectPage( |
|||
getPage(params, FieldConstant.CREATED_TIME, false), |
|||
getWrapper(params) |
|||
); |
|||
return getPageData(page, CustomerRelationDTO.class); |
|||
} |
|||
|
|||
@Override |
|||
public List<CustomerRelationDTO> list(Map<String, Object> params) { |
|||
List<CustomerRelationEntity> entityList = baseDao.selectList(getWrapper(params)); |
|||
|
|||
return ConvertUtils.sourceToTarget(entityList, CustomerRelationDTO.class); |
|||
} |
|||
|
|||
private QueryWrapper<CustomerRelationEntity> getWrapper(Map<String, Object> params){ |
|||
String id = (String)params.get(FieldConstant.ID_HUMP); |
|||
|
|||
QueryWrapper<CustomerRelationEntity> 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(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,16 @@ |
|||
<?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.CustomerRelationDao"> |
|||
|
|||
<select id="selectByCustomerId" resultType="com.epmet.dto.CustomerRelationDTO" parameterType="java.lang.String"> |
|||
SELECT |
|||
cr.* |
|||
FROM |
|||
customer_relation cr |
|||
WHERE |
|||
cr.DEL_FLAG = '0' |
|||
AND cr.CUSTOMER_ID =#{customerId} |
|||
</select> |
|||
|
|||
</mapper> |
Loading…
Reference in new issue