Browse Source

新增更新租户状态接口(根据有效期基本判断是否可以启禁用)

tags/v2.4.1
xiaoying 1 year ago
parent
commit
8def64bc71
9 changed files with 95 additions and 14 deletions
  1. +34
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/common/ServiceExceptionEnum.java
  2. +4
    -6
      tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/TenantController.java
  3. +5
    -1
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/param/CreateClientTenantDto.java
  4. +2
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/po/TenantPo.java
  5. +5
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/TenantService.java
  6. +41
    -5
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/TenantServiceImpl.java
  7. +0
    -1
      tuoheng_oidc_admin/src/main/resources/mapper/ClientUserMapper.xml
  8. +4
    -1
      tuoheng_oidc_admin/src/main/resources/mapper/TenantMapper.xml
  9. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/model/po/ClientUserRolePo.class

+ 34
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/common/ServiceExceptionEnum.java View File

@@ -0,0 +1,34 @@
package com.tuoheng.common;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* 业务异常 枚举
*
* @Author xiaoying
* @Date 2023/3/10 9:33
*/
@AllArgsConstructor
public enum ServiceExceptionEnum implements ExceptionInterface {

/**
* 未查询到数据
*/
GET_NO_DATA(10001, "未查到该记录!"),
/**
* 参数为空
*/
PARAMETER_IS_NULL(10002, "参数为空!"),
/**
* 有效期已过
*/
EXPIRATION_DATE(11111, "该账号已过有效期,请先更改有效期再启用账号");


@Getter
private final int code;

@Getter
private final String message;
}

+ 4
- 6
tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/TenantController.java View File

@@ -77,14 +77,12 @@ public class TenantController {
}

/**
* 删除租户(逻辑删除)
*
* 更新租户状态(1 启用 0禁用)
* @return
*/
@PostMapping("/delete")
public JsonResult delete(@RequestBody CreateClientTenantDto dto, @CurrentUser LoginUser loginUser) {
return tenantService.deleteTenant(dto, loginUser);
@PostMapping("/status")
public JsonResult updateStatus(@RequestBody CreateClientTenantDto dto, @CurrentUser LoginUser loginUser) {
return tenantService.updateStatus(dto, loginUser);
}


}

+ 5
- 1
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/param/CreateClientTenantDto.java View File

@@ -45,7 +45,7 @@ public class CreateClientTenantDto {
*/
private String provinceName;
/**
*市区编号
* 市区编号
*/
private String cityCode;
/**
@@ -74,5 +74,9 @@ public class CreateClientTenantDto {
private String lng;

private String lat;
/**
* 1 启用 0禁用
*/
private Integer status;

}

+ 2
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/po/TenantPo.java View File

@@ -58,4 +58,6 @@ public class TenantPo extends BasePo {
private String lng;

private String lat;

private Integer status;
}

+ 5
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/TenantService.java View File

@@ -45,4 +45,9 @@ public interface TenantService {
* @return
*/
JsonResult getDetaile(TenantQuery query);
/**
* 更新租户状态(1 启用 0禁用)
* @return
*/
JsonResult updateStatus(CreateClientTenantDto dto, LoginUser loginUser);
}

+ 41
- 5
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/TenantServiceImpl.java View File

@@ -1,6 +1,7 @@
package com.tuoheng.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
@@ -10,7 +11,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tuoheng.common.CommonConfig;
import com.tuoheng.common.ServiceException;
import com.tuoheng.common.ServiceExceptionEnum;
import com.tuoheng.constant.*;
import com.tuoheng.enums.MarkTypeEnum;
import com.tuoheng.mapper.*;
import com.tuoheng.model.dto.*;
import com.tuoheng.model.entity.TenantEmploy;
@@ -40,10 +43,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

/**
@@ -208,7 +208,7 @@ public class TenantServiceImpl implements TenantService {
//暂时河湖长,动态匹配其他平台
case HhzUrlConstant.HHZ_CLIENT:
addClientRoleDtoList(HhzUrlConstant.HHZ_CLIENT_MP, dto, clientRoleDtoList);
addClientRoleDtoList(HhzUrlConstant.HHZ_CLIENT_ADMIN,dto, clientRoleDtoList);
addClientRoleDtoList(HhzUrlConstant.HHZ_CLIENT_ADMIN, dto, clientRoleDtoList);
break;
case PilotConstant.PILOT_CLIENT:
addClientRoleDtoList(PilotConstant.PILOT_CLIENT_ADMIN, dto, clientRoleDtoList);
@@ -420,6 +420,42 @@ public class TenantServiceImpl implements TenantService {
return JsonResult.success(dto);
}

/**
* 更新租户状态(1 启用 0禁用)
*
* @param dto
* @param loginUser
* @return
*/
@Override
public JsonResult updateStatus(CreateClientTenantDto dto, LoginUser loginUser) {

if (ObjectUtil.isNull(dto.getId())) {
return JsonResult.error("租户id不能为空");
}
TenantPo tenantPo = tenantMapper.selectById(dto.getId());

if (CommonConstant.ONE.equals(dto.getStatus())) {
//启用 ->判断当前需要启用的系统是否过了有效期
TenantItem tenantItem = tenantItemMapper.selectOne(Wrappers.<TenantItem>lambdaQuery().eq(TenantItem::getTenantId, dto.getId()));
//超过有效期则为flase
boolean flag = tenantItem.getEndTime().after(DateUtil.date());
//则不给启用
if (!flag) {
//有效期已过
return JsonResult.error(ServiceExceptionEnum.EXPIRATION_DATE.getMessage());
}
}
UserPo userPo = clientUserMapper.selectByUserId(tenantPo.getUserId());
//1正常 0禁用
userPo.setEnabled(dto.getStatus());
clientUserMapper.updatePass(userPo);
tenantPo.setStatus(dto.getStatus());
tenantMapper.updateById(tenantPo);

return JsonResult.success();
}


/**
* 封装返回展示类

+ 0
- 1
tuoheng_oidc_admin/src/main/resources/mapper/ClientUserMapper.xml View File

@@ -29,7 +29,6 @@
is_tenant
FROM users
WHERE id = #{userId}
and enabled = 1
</select>
<select id="selectByTenantId" resultType="com.tuoheng.model.po.UserPo">
SELECT *

+ 4
- 1
tuoheng_oidc_admin/src/main/resources/mapper/TenantMapper.xml View File

@@ -22,6 +22,9 @@
<if test="enabled != null">
enabled = #{enabled},
</if>
<if test="status != null">
status = #{status},
</if>
province_code=#{provinceCode},
province_name=#{provinceName},
city_code =#{cityCode},
@@ -48,7 +51,7 @@
,t.province_code,t.province_name,t.city_code,t.city_name,t.district_code,t.district_name,u.username
username,t.update_time updateTime,t.create_time createTime
FROM t_tenant t,users u
WHERE t.enabled = 1 and u.enabled =1 and t.user_id =u.id
WHERE t.enabled = 1 and t.user_id =u.id
<if test="query.tenantName != null and query.tenantName != ''">
and t.name LIKE concat('%',#{query.tenantName},'%')
</if>

BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/model/po/ClientUserRolePo.class View File


Loading…
Cancel
Save