|
|
@ -17,7 +17,6 @@ |
|
|
|
|
|
|
|
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; |
|
|
@ -63,185 +62,181 @@ import java.util.stream.Collectors; |
|
|
|
@Service |
|
|
|
public class CustomerFunctionServiceImpl extends BaseServiceImpl<CustomerFunctionDao, CustomerFunctionEntity> implements CustomerFunctionService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CustomerFunctionRedis customerFunctionRedis; |
|
|
|
@Autowired |
|
|
|
private FunctionDao functionDao; |
|
|
|
@Autowired |
|
|
|
private OperCrmFeignClient operCrmFeignClient; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<CustomerFunctionDTO> page(Map<String, Object> params) { |
|
|
|
IPage<CustomerFunctionEntity> page = baseDao.selectPage( |
|
|
|
getPage(params, FieldConstant.CREATED_TIME, false), |
|
|
|
getWrapper(params) |
|
|
|
); |
|
|
|
return getPageData(page, CustomerFunctionDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<CustomerFunctionDTO> list(Map<String, Object> params) { |
|
|
|
List<CustomerFunctionEntity> entityList = baseDao.selectList(getWrapper(params)); |
|
|
|
|
|
|
|
return ConvertUtils.sourceToTarget(entityList, CustomerFunctionDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
private QueryWrapper<CustomerFunctionEntity> getWrapper(Map<String, Object> params){ |
|
|
|
String id = (String)params.get(FieldConstant.ID_HUMP); |
|
|
|
|
|
|
|
QueryWrapper<CustomerFunctionEntity> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|
|
|
|
|
|
|
return wrapper; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public CustomerFunctionDTO get(String id) { |
|
|
|
CustomerFunctionEntity entity = baseDao.selectById(id); |
|
|
|
return ConvertUtils.sourceToTarget(entity, CustomerFunctionDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(CustomerFunctionDTO dto) { |
|
|
|
CustomerFunctionEntity entity = ConvertUtils.sourceToTarget(dto, CustomerFunctionEntity.class); |
|
|
|
insert(entity); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(CustomerFunctionDTO dto) { |
|
|
|
CustomerFunctionEntity entity = ConvertUtils.sourceToTarget(dto, CustomerFunctionEntity.class); |
|
|
|
updateById(entity); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void delete(String[] ids) { |
|
|
|
// 逻辑删除(@TableLogic 注解)
|
|
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
|
* @Author sun |
|
|
|
* @Description 运营端-获取客户功能(已勾选、未勾选)详情列表 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public CustomerFunctionListResultDTO customerFunctionList(CustomerFunctionListFormDTO formDTO) { |
|
|
|
CustomerFunctionListResultDTO resultDTO = new CustomerFunctionListResultDTO(); |
|
|
|
//1:调用oper-crm服务。查询客户基本信息
|
|
|
|
Result<CustomerDTO> result = operCrmFeignClient.queryCustomerInfo(formDTO.getCustomerId()); |
|
|
|
if (!result.success() || null == result.getData()) { |
|
|
|
throw new RenException(CustomerFunctionConstant.SELECT_CUSTOMER_EXCEPTION); |
|
|
|
} |
|
|
|
CustomerDTO customerDTO = result.getData(); |
|
|
|
resultDTO.setCustomerId(customerDTO.getId()); |
|
|
|
resultDTO.setCustomerName(customerDTO.getCustomerName()); |
|
|
|
resultDTO.setLogo(customerDTO.getLogo()); |
|
|
|
|
|
|
|
//2:查询所有已上架功能列表(默认、定制功能)
|
|
|
|
List<FunctionDTO> funList = functionDao.selectShopFunctionList(NumConstant.ONE); |
|
|
|
if(null==funList||funList.size()<NumConstant.ONE){ |
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
//3:查询当前客户已拥有的功能
|
|
|
|
List<CustomerFunctionDTO> csList = baseDao.selectCustomerFunctionList(formDTO.getCustomerId()); |
|
|
|
|
|
|
|
//4:封装数据,客户已拥有但已下架的功能不展示
|
|
|
|
List<DefaultFunctionListResultDTO> defaultFunctionList = new ArrayList<>(); |
|
|
|
List<CustomizedFunctionListResultDTO> customizedFunctionList = new ArrayList<>(); |
|
|
|
funList.forEach(fun -> { |
|
|
|
//默认功能
|
|
|
|
if (fun.getFunctionGroup() == NumConstant.ZERO) { |
|
|
|
DefaultFunctionListResultDTO df = new DefaultFunctionListResultDTO(); |
|
|
|
df.setFunctionId(fun.getId()); |
|
|
|
df.setFunctionName(fun.getFunctionName()); |
|
|
|
csList.forEach(cs -> { |
|
|
|
if (fun.getId().equals(cs.getFunctionId())) { |
|
|
|
df.setFlag(true); |
|
|
|
} |
|
|
|
}); |
|
|
|
defaultFunctionList.add(df); |
|
|
|
} |
|
|
|
//定制功能
|
|
|
|
if (fun.getFunctionGroup() == NumConstant.ONE) { |
|
|
|
CustomizedFunctionListResultDTO cf = new CustomizedFunctionListResultDTO(); |
|
|
|
cf.setFunctionId(fun.getId()); |
|
|
|
cf.setFunctionName(fun.getFunctionName()); |
|
|
|
csList.forEach(cs -> { |
|
|
|
if (fun.getId().equals(cs.getFunctionId())) { |
|
|
|
cf.setFlag(true); |
|
|
|
} |
|
|
|
}); |
|
|
|
customizedFunctionList.add(cf); |
|
|
|
} |
|
|
|
}); |
|
|
|
resultDTO.setDefaultFunctionList(defaultFunctionList); |
|
|
|
resultDTO.setCustomizedFunctionList(customizedFunctionList); |
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
|
* @Author sun |
|
|
|
* @Description 运营端-保存客户功能关系数据 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void saveCustomerFunction(SaveCustomerFunctionFormDTO formDTO) { |
|
|
|
//1:逻辑删除旧的客户功能关联数据
|
|
|
|
baseDao.updateByCustomerId(formDTO.getCustomerId()); |
|
|
|
|
|
|
|
//2:批量新增新的客户功能关系数据
|
|
|
|
List<CustomerFunctionEntity> entityList = new ArrayList<>(); |
|
|
|
formDTO.getDefaultFunctionList().forEach(dfId -> { |
|
|
|
CustomerFunctionEntity entity = new CustomerFunctionEntity(); |
|
|
|
entity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
entity.setFunctionId(dfId); |
|
|
|
entityList.add(entity); |
|
|
|
}); |
|
|
|
formDTO.getCustomizedFunctionList().forEach(cfId -> { |
|
|
|
CustomerFunctionEntity entity = new CustomerFunctionEntity(); |
|
|
|
entity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
entity.setFunctionId(cfId); |
|
|
|
entityList.add(entity); |
|
|
|
}); |
|
|
|
insertBatch(entityList); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<DefaultFunctionListResultDTO> getOpenedFunctionList(CustomerFunctionListFormDTO formDTO) { |
|
|
|
if (StringUtils.isBlank(formDTO.getCustomerId())){ |
|
|
|
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getMsg()); |
|
|
|
} |
|
|
|
List<DefaultFunctionListResultDTO> result = new ArrayList<>(); |
|
|
|
//查询所有已上架功能列表(默认、定制功能)
|
|
|
|
List<FunctionDTO> funList = functionDao.selectFunctionList(); |
|
|
|
if(CollectionUtils.isEmpty(funList)){ |
|
|
|
return result; |
|
|
|
} |
|
|
|
//查询当前客户已拥有的功能
|
|
|
|
List<CustomerFunctionDTO> openedList = baseDao.selectCustomerFunctionList(formDTO.getCustomerId()); |
|
|
|
if(CollectionUtils.isEmpty(openedList)){ |
|
|
|
log.warn("getOpenedFunctionList customerId:{} have any function",formDTO.getCustomerId()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
Set<String> openedFunIdSet = openedList.stream().map(CustomerFunctionDTO::getFunctionId).collect(Collectors.toSet()); |
|
|
|
for (FunctionDTO function : funList) { |
|
|
|
if (openedFunIdSet.contains(function.getId())) { |
|
|
|
DefaultFunctionListResultDTO resultDTO = ConvertUtils.sourceToTarget(function, DefaultFunctionListResultDTO.class); |
|
|
|
if (resultDTO == null) { |
|
|
|
log.error("getOpenedFunctionList convert return null,function:{}", JSON.toJSONString(function)); |
|
|
|
continue; |
|
|
|
} |
|
|
|
result.add(resultDTO); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
@Autowired |
|
|
|
private CustomerFunctionRedis customerFunctionRedis; |
|
|
|
@Autowired |
|
|
|
private FunctionDao functionDao; |
|
|
|
@Autowired |
|
|
|
private OperCrmFeignClient operCrmFeignClient; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<CustomerFunctionDTO> page(Map<String, Object> params) { |
|
|
|
IPage<CustomerFunctionEntity> page = baseDao.selectPage( |
|
|
|
getPage(params, FieldConstant.CREATED_TIME, false), |
|
|
|
getWrapper(params) |
|
|
|
); |
|
|
|
return getPageData(page, CustomerFunctionDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<CustomerFunctionDTO> list(Map<String, Object> params) { |
|
|
|
List<CustomerFunctionEntity> entityList = baseDao.selectList(getWrapper(params)); |
|
|
|
|
|
|
|
return ConvertUtils.sourceToTarget(entityList, CustomerFunctionDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
private QueryWrapper<CustomerFunctionEntity> getWrapper(Map<String, Object> params) { |
|
|
|
String id = (String) params.get(FieldConstant.ID_HUMP); |
|
|
|
|
|
|
|
QueryWrapper<CustomerFunctionEntity> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|
|
|
|
|
|
|
return wrapper; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public CustomerFunctionDTO get(String id) { |
|
|
|
CustomerFunctionEntity entity = baseDao.selectById(id); |
|
|
|
return ConvertUtils.sourceToTarget(entity, CustomerFunctionDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(CustomerFunctionDTO dto) { |
|
|
|
CustomerFunctionEntity entity = ConvertUtils.sourceToTarget(dto, CustomerFunctionEntity.class); |
|
|
|
insert(entity); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(CustomerFunctionDTO dto) { |
|
|
|
CustomerFunctionEntity entity = ConvertUtils.sourceToTarget(dto, CustomerFunctionEntity.class); |
|
|
|
updateById(entity); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void delete(String[] ids) { |
|
|
|
// 逻辑删除(@TableLogic 注解)
|
|
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
|
* @Author sun |
|
|
|
* @Description 运营端-获取客户功能(已勾选、未勾选)详情列表 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public CustomerFunctionListResultDTO customerFunctionList(CustomerFunctionListFormDTO formDTO) { |
|
|
|
CustomerFunctionListResultDTO resultDTO = new CustomerFunctionListResultDTO(); |
|
|
|
//1:调用oper-crm服务。查询客户基本信息
|
|
|
|
Result<CustomerDTO> result = operCrmFeignClient.queryCustomerInfo(formDTO.getCustomerId()); |
|
|
|
if (!result.success() || null == result.getData()) { |
|
|
|
throw new RenException(CustomerFunctionConstant.SELECT_CUSTOMER_EXCEPTION); |
|
|
|
} |
|
|
|
CustomerDTO customerDTO = result.getData(); |
|
|
|
resultDTO.setCustomerId(customerDTO.getId()); |
|
|
|
resultDTO.setCustomerName(customerDTO.getCustomerName()); |
|
|
|
resultDTO.setLogo(customerDTO.getLogo()); |
|
|
|
|
|
|
|
//2:查询所有已上架功能列表(默认、定制功能)
|
|
|
|
List<FunctionDTO> funList = functionDao.selectShopFunctionList(NumConstant.ONE); |
|
|
|
if (null == funList || funList.size() < NumConstant.ONE) { |
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
//3:查询当前客户已拥有的功能
|
|
|
|
List<CustomerFunctionDTO> csList = baseDao.selectCustomerFunctionList(formDTO.getCustomerId()); |
|
|
|
|
|
|
|
//4:封装数据,客户已拥有但已下架的功能不展示
|
|
|
|
List<DefaultFunctionListResultDTO> defaultFunctionList = new ArrayList<>(); |
|
|
|
List<CustomizedFunctionListResultDTO> customizedFunctionList = new ArrayList<>(); |
|
|
|
funList.forEach(fun -> { |
|
|
|
//默认功能
|
|
|
|
if (fun.getFunctionGroup() == NumConstant.ZERO) { |
|
|
|
DefaultFunctionListResultDTO df = new DefaultFunctionListResultDTO(); |
|
|
|
df.setFunctionId(fun.getId()); |
|
|
|
df.setFunctionName(fun.getFunctionName()); |
|
|
|
csList.forEach(cs -> { |
|
|
|
if (fun.getId().equals(cs.getFunctionId())) { |
|
|
|
df.setFlag(true); |
|
|
|
} |
|
|
|
}); |
|
|
|
defaultFunctionList.add(df); |
|
|
|
} |
|
|
|
//定制功能
|
|
|
|
if (fun.getFunctionGroup() == NumConstant.ONE) { |
|
|
|
CustomizedFunctionListResultDTO cf = new CustomizedFunctionListResultDTO(); |
|
|
|
cf.setFunctionId(fun.getId()); |
|
|
|
cf.setFunctionName(fun.getFunctionName()); |
|
|
|
csList.forEach(cs -> { |
|
|
|
if (fun.getId().equals(cs.getFunctionId())) { |
|
|
|
cf.setFlag(true); |
|
|
|
} |
|
|
|
}); |
|
|
|
customizedFunctionList.add(cf); |
|
|
|
} |
|
|
|
}); |
|
|
|
resultDTO.setDefaultFunctionList(defaultFunctionList); |
|
|
|
resultDTO.setCustomizedFunctionList(customizedFunctionList); |
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
|
* @Author sun |
|
|
|
* @Description 运营端-保存客户功能关系数据 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void saveCustomerFunction(SaveCustomerFunctionFormDTO formDTO) { |
|
|
|
//1:逻辑删除旧的客户功能关联数据
|
|
|
|
baseDao.updateByCustomerId(formDTO.getCustomerId()); |
|
|
|
|
|
|
|
//2:批量新增新的客户功能关系数据
|
|
|
|
List<CustomerFunctionEntity> entityList = new ArrayList<>(); |
|
|
|
formDTO.getDefaultFunctionList().forEach(dfId -> { |
|
|
|
CustomerFunctionEntity entity = new CustomerFunctionEntity(); |
|
|
|
entity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
entity.setFunctionId(dfId); |
|
|
|
entityList.add(entity); |
|
|
|
}); |
|
|
|
formDTO.getCustomizedFunctionList().forEach(cfId -> { |
|
|
|
CustomerFunctionEntity entity = new CustomerFunctionEntity(); |
|
|
|
entity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
entity.setFunctionId(cfId); |
|
|
|
entityList.add(entity); |
|
|
|
}); |
|
|
|
insertBatch(entityList); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<DefaultFunctionListResultDTO> getOpenedFunctionList(CustomerFunctionListFormDTO formDTO) { |
|
|
|
if (StringUtils.isBlank(formDTO.getCustomerId())) { |
|
|
|
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getMsg()); |
|
|
|
} |
|
|
|
List<DefaultFunctionListResultDTO> result = new ArrayList<>(); |
|
|
|
//查询所有已上架功能列表(默认、定制功能)
|
|
|
|
List<FunctionDTO> funList = functionDao.selectFunctionList(); |
|
|
|
if (CollectionUtils.isEmpty(funList)) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
//查询当前客户已拥有的功能
|
|
|
|
List<CustomerFunctionDTO> openedList = baseDao.selectCustomerFunctionList(formDTO.getCustomerId()); |
|
|
|
if (CollectionUtils.isEmpty(openedList)) { |
|
|
|
log.warn("getOpenedFunctionList customerId:{} have any function", formDTO.getCustomerId()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
Set<String> openedFunIdSet = openedList.stream().map(CustomerFunctionDTO::getFunctionId).collect(Collectors.toSet()); |
|
|
|
return funList.stream().filter(fun -> openedFunIdSet.contains(fun.getId())) |
|
|
|
.map(fun -> { |
|
|
|
DefaultFunctionListResultDTO resultDTO = new DefaultFunctionListResultDTO(); |
|
|
|
resultDTO.setFunctionId(fun.getId()); |
|
|
|
resultDTO.setFunctionName(fun.getFunctionName()); |
|
|
|
return resultDTO; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
} |