|
|
@@ -4,18 +4,26 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.dromara.common.core.constant.CacheNames;
|
|
|
+import org.dromara.common.core.service.CustomerService;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.redis.utils.CacheUtils;
|
|
|
import org.dromara.system.domain.SysCustomer;
|
|
|
import org.dromara.system.domain.bo.SysCustomerBo;
|
|
|
import org.dromara.system.domain.vo.SysCustomerVo;
|
|
|
import org.dromara.system.mapper.SysCustomerMapper;
|
|
|
import org.dromara.system.service.ISysCustomerService;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import org.dromara.yingpaipay.api.erp.CommonErpClientService;
|
|
|
+
|
|
|
import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 客户管理 Service业务层处理
|
|
|
@@ -24,16 +32,19 @@ import java.util.Collection;
|
|
|
*/
|
|
|
@RequiredArgsConstructor
|
|
|
@Service
|
|
|
-public class SysCustomerServiceImpl implements ISysCustomerService {
|
|
|
+public class SysCustomerServiceImpl implements ISysCustomerService, CustomerService {
|
|
|
|
|
|
private final SysCustomerMapper baseMapper;
|
|
|
+ private final CommonErpClientService commonErpClientService;
|
|
|
|
|
|
/**
|
|
|
* 查询客户
|
|
|
*/
|
|
|
@Override
|
|
|
public SysCustomerVo queryById(Long id) {
|
|
|
- return baseMapper.selectVoById(id);
|
|
|
+ SysCustomerVo vo = baseMapper.selectVoById(id);
|
|
|
+ fillAuthClientName(vo);
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -43,9 +54,44 @@ public class SysCustomerServiceImpl implements ISysCustomerService {
|
|
|
public TableDataInfo<SysCustomerVo> queryPageList(SysCustomerBo bo, PageQuery pageQuery) {
|
|
|
LambdaQueryWrapper<SysCustomer> lqw = buildQueryWrapper(bo);
|
|
|
Page<SysCustomerVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ fillAuthClientName(result.getRecords());
|
|
|
return TableDataInfo.build(result);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量填充授权客户名称
|
|
|
+ */
|
|
|
+ private void fillAuthClientName(List<SysCustomerVo> list) {
|
|
|
+ if (StringUtils.isEmpty(list)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<String> authClientFNums = list.stream()
|
|
|
+ .map(SysCustomerVo::getAuthClientFNum)
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
+ .distinct()
|
|
|
+ .toList();
|
|
|
+ if (StringUtils.isEmpty(authClientFNums)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, String> nameMap = commonErpClientService.selectNameByFNums(authClientFNums);
|
|
|
+ list.forEach(vo -> {
|
|
|
+ if (StringUtils.isNotBlank(vo.getAuthClientFNum())) {
|
|
|
+ vo.setAuthClientName(nameMap.get(vo.getAuthClientFNum()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单个填充授权客户名称
|
|
|
+ */
|
|
|
+ private void fillAuthClientName(SysCustomerVo vo) {
|
|
|
+ if (vo == null || StringUtils.isBlank(vo.getAuthClientFNum())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, String> nameMap = commonErpClientService.selectNameByFNums(List.of(vo.getAuthClientFNum()));
|
|
|
+ vo.setAuthClientName(nameMap.get(vo.getAuthClientFNum()));
|
|
|
+ }
|
|
|
+
|
|
|
private LambdaQueryWrapper<SysCustomer> buildQueryWrapper(SysCustomerBo bo) {
|
|
|
LambdaQueryWrapper<SysCustomer> lqw = Wrappers.lambdaQuery();
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getUserName()), SysCustomer::getUserName, bo.getUserName());
|
|
|
@@ -61,7 +107,11 @@ public class SysCustomerServiceImpl implements ISysCustomerService {
|
|
|
@Override
|
|
|
public Boolean updateByBo(SysCustomerBo bo) {
|
|
|
SysCustomer update = MapstructUtils.convert(bo, SysCustomer.class);
|
|
|
- return baseMapper.updateById(update) > 0;
|
|
|
+ boolean result = baseMapper.updateById(update) > 0;
|
|
|
+ if (result && bo.getId() != null) {
|
|
|
+ CacheUtils.evict(CacheNames.SYS_CUSTOMER_NAME, bo.getId());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -87,4 +137,15 @@ public class SysCustomerServiceImpl implements ISysCustomerService {
|
|
|
.eq(SysCustomer::getWechatOpenid, wechatOpenid)
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ @Cacheable(cacheNames = CacheNames.SYS_CUSTOMER_NAME, key = "#customerId")
|
|
|
+ @Override
|
|
|
+ public String selectUserNameById(Long customerId) {
|
|
|
+ SysCustomer customer = baseMapper.selectOne(
|
|
|
+ Wrappers.lambdaQuery(SysCustomer.class)
|
|
|
+ .select(SysCustomer::getUserName)
|
|
|
+ .eq(SysCustomer::getId, customerId)
|
|
|
+ );
|
|
|
+ return customer != null ? customer.getUserName() : null;
|
|
|
+ }
|
|
|
}
|