|
@@ -1,10 +1,13 @@
|
|
|
package cn.cslg.permission.service;
|
|
|
|
|
|
+import cn.cslg.permission.common.model.Records;
|
|
|
import cn.cslg.permission.common.model.dto.ClientDTO;
|
|
|
import cn.cslg.permission.common.model.vo.PersonnelVO;
|
|
|
+import cn.cslg.permission.common.model.vo.TenantClientVO;
|
|
|
import cn.cslg.permission.common.utils.*;
|
|
|
import cn.cslg.permission.domain.Client;
|
|
|
import cn.cslg.permission.domain.Personnel;
|
|
|
+import cn.cslg.permission.domain.Tenant;
|
|
|
import cn.cslg.permission.mapper.ClientMapper;
|
|
|
import cn.cslg.permission.service.associate.AssoTenantClientService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -37,6 +40,7 @@ public class ClientService extends ServiceImpl<ClientMapper, Client> {
|
|
|
private final PersonnelService personnelService;
|
|
|
private final AssoTenantClientService assoTenantClientService;
|
|
|
private final CacheUtils cacheUtils;
|
|
|
+ private final TenantService tenantService;
|
|
|
|
|
|
/**
|
|
|
* @param params
|
|
@@ -199,16 +203,64 @@ public class ClientService extends ServiceImpl<ClientMapper, Client> {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public IPage<Client> getTenantClients(ClientDTO params) {
|
|
|
+ public Records getTenantClients(ClientDTO params) {
|
|
|
+ Records records = new Records();
|
|
|
+ records.setCurrent(Long.parseLong(params.getCurrent().toString()));
|
|
|
+ records.setSize(Long.parseLong(params.getSize().toString()));
|
|
|
+ List<TenantClientVO> tenantClientVOS = new ArrayList<>();
|
|
|
//获取登陆人信息,获得租户id
|
|
|
if (params.getTenantId() == null) {
|
|
|
PersonnelVO personnel = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
params.setTenantId(personnel.getTenantId());
|
|
|
}
|
|
|
- IPage<Client> lst = this.baseMapper.getTenantClients(new Page<>(params.getCurrent(), params.getSize()), params);
|
|
|
- List<Client> list = lst.getRecords();
|
|
|
- this.loadClient(list);
|
|
|
- lst.setRecords(list);
|
|
|
- return lst;
|
|
|
+
|
|
|
+ List<Integer> tenantIds = new ArrayList<>();
|
|
|
+ List<Integer> ids = this.baseMapper.getTenantClients(params);
|
|
|
+ if (ids != null && ids.size() > 0) {
|
|
|
+ tenantIds.addAll(ids);
|
|
|
+ }
|
|
|
+ if (params.getTenantId() != null) {
|
|
|
+ tenantIds.add(params.getTenantId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ids.size() > 0) {
|
|
|
+ LambdaQueryWrapper<Tenant> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(Tenant::getId, ids);
|
|
|
+ if (params.getName() != null) {
|
|
|
+ queryWrapper.like(Tenant::getTenantName, params.getName());
|
|
|
+ }
|
|
|
+ IPage<Tenant> tenantIPage = tenantService.page(new Page<Tenant>(params.getCurrent(), params.getSize()), queryWrapper);
|
|
|
+ Long total = tenantIPage.getTotal();
|
|
|
+ List<Tenant> tenants =tenantIPage.getRecords();
|
|
|
+ tenantClientVOS=this.loadTenantClient(tenants);
|
|
|
+ records.setRecords(tenantClientVOS);
|
|
|
+ records.setTotal(total);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ records.setRecords(tenantClientVOS);
|
|
|
+ records.setTotal(0L);
|
|
|
+ }
|
|
|
+
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @author 李仁杰
|
|
|
+ * @description 装载客户
|
|
|
+ */
|
|
|
+ public List<TenantClientVO> loadTenantClient(List<Tenant> tenants) {
|
|
|
+ List<TenantClientVO> tenantClientVOS = new ArrayList<>();
|
|
|
+ if (tenants == null || tenants.size() == 0) {
|
|
|
+ return tenantClientVOS;
|
|
|
+ }
|
|
|
+ for (Tenant tenant : tenants) {
|
|
|
+ TenantClientVO tenantClientVO = new TenantClientVO();
|
|
|
+ tenantClientVO.setTenantId(tenant.getId());
|
|
|
+ tenantClientVO.setName(tenant.getTenantName());
|
|
|
+ tenantClientVOS.add(tenantClientVO);
|
|
|
+ }
|
|
|
+ ;
|
|
|
+ return tenantClientVOS;
|
|
|
}
|
|
|
}
|