Merge pull request #786 from e-mhui/fix-pg-sql-error

#785 fix pg ddl sql error
This commit is contained in:
ji
2023-11-09 21:13:03 +08:00
committed by GitHub
2 changed files with 38 additions and 34 deletions

View File

@ -16,25 +16,20 @@ public class SQLConst {
+ "array_to_string" + "array_to_string"
+ "(\n" + "(\n"
+ " array(\n" + " array(\n"
+ " select ' ' || concat_ws(' ',fieldName, fieldType, fieldLen, indexType, isNullStr, fieldComment" + " select ' ' || concat_ws(' ',fieldName, fieldType, defaultValue, isNullStr"
+ " ) as " + " ) as "
+ "column_line\n" + "column_line\n"
+ " from (\n" + " from (\n"
+ " select a.attname as fieldName,format_type(a.atttypid,a.atttypmod) as fieldType,(case when " + " select a.attname as fieldName,format_type(a.atttypid,a.atttypmod) as fieldType,"
+ "atttypmod-4>0 then\n" + " CASE WHEN \n"
+ " atttypmod-4 else 0 end) as fieldLen,\n" + " (SELECT substring(pg_catalog.pg_get_expr(B.adbin, B.adrelid) for 128)\n"
+ " (case when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum " + " FROM pg_catalog.pg_attrdef B WHERE B.adrelid = A.attrelid AND B.adnum = A.attnum AND A.atthasdef) IS NOT NULL THEN\n"
+ "and\n" + " 'DEFAULT '|| (SELECT substring(pg_catalog.pg_get_expr(B.adbin, B.adrelid) for 128)\n"
+ " contype='p')>0 then 'PRI'\n" + " FROM pg_catalog.pg_attrdef B WHERE B.adrelid = A.attrelid AND B.adnum = A.attnum AND A.atthasdef)\n"
+ " when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and " + " ELSE\n"
+ "contype='u')>0\n" + " ''\n"
+ " then 'UNI'\n" + " END as defaultValue,"
+ " when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and " + " (case when a.attnotnull=true then 'not null' else 'null' end) as isNullStr\n"
+ "contype='f')>0\n"
+ " then 'FRI'\n"
+ " else '' end) as indexType,\n"
+ " (case when a.attnotnull=true then 'not null' else 'null' end) as isNullStr,\n"
+ " ' comment ' || col_description(a.attrelid,a.attnum) as fieldComment\n"
+ " from pg_attribute a where attstattarget=-1 and attrelid = (select c.oid from pg_class c," + " from pg_attribute a where attstattarget=-1 and attrelid = (select c.oid from pg_class c,"
+ "pg_namespace n" + "pg_namespace n"
+ " where\n" + " where\n"
@ -114,13 +109,13 @@ public class SQLConst {
+ " -- COMMENT COMMENT ON COLUMN sys_activity.id IS '主键';\n" + " -- COMMENT COMMENT ON COLUMN sys_activity.id IS '主键';\n"
+ " tableScript:= tableScript || chr(13)||chr(10) || chr(13)||chr(10) || array_to_string(\n" + " tableScript:= tableScript || chr(13)||chr(10) || chr(13)||chr(10) || array_to_string(\n"
+ " array(\n" + " array(\n"
+ " SELECT 'COMMENT ON COLUMN' || tablename || '.' || a.attname ||' IS '|| ''''|| d.description " + " SELECT 'COMMENT ON COLUMN ' || 'namespace.tablename' || '.' || a.attname ||' IS '|| ''''|| d.description "
+ "||''''\n" + "||''''\n"
+ " FROM pg_class c\n" + " FROM pg_class c\n"
+ " JOIN pg_description d ON c.oid=d.objoid\n" + " JOIN pg_description d ON c.oid=d.objoid\n"
+ " JOIN pg_attribute a ON c.oid = a.attrelid\n" + " JOIN pg_attribute a ON c.oid = a.attrelid\n"
+ " WHERE c.relname=tablename\n" + " WHERE c.relname=tablename\n"
+ " AND a.attnum = d.objsubid),','|| chr(13)||chr(10)) ;\n" + " AND a.attnum = d.objsubid),';'|| chr(13)||chr(10)) ;\n"
+ "\n" + "\n"
+ " return tableScript;\n" + " return tableScript;\n"
+ "\n" + "\n"

View File

@ -18,6 +18,7 @@ import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaTokenConsts; import cn.dev33.satoken.util.SaTokenConsts;
import cn.hutool.crypto.digest.DigestUtil; import cn.hutool.crypto.digest.DigestUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -25,6 +26,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
/** /**
* 登录授权服务 * 登录授权服务
* *
@ -48,7 +51,27 @@ public class OauthController {
public DataResult login(@Validated @RequestBody LoginRequest request) { public DataResult login(@Validated @RequestBody LoginRequest request) {
// 查询用户 // 查询用户
User user = userService.query(request.getUserName()).getData(); User user = userService.query(request.getUserName()).getData();
if (user == null) { this.validateUser(user);
// Successfully logged in without modifying the administrator password
if (this.validateAdmin(user)) {
return DataResult.of(doLogin(user));
}
if (!DigestUtil.bcryptCheck(request.getPassword(), user.getPassword())) {
throw new BusinessException("oauth.passwordIncorrect");
}
return DataResult.of(doLogin(user));
}
private boolean validateAdmin(final @NotNull User user) {
return RoleCodeEnum.ADMIN.getDefaultUserId().equals(user.getId()) && RoleCodeEnum.ADMIN.getPassword().equals(
user.getPassword());
}
private void validateUser(final User user) {
if (Objects.isNull(user)) {
throw new BusinessException("oauth.userNameNotExits"); throw new BusinessException("oauth.userNameNotExits");
} }
if (!ValidStatusEnum.VALID.getCode().equals(user.getStatus())) { if (!ValidStatusEnum.VALID.getCode().equals(user.getStatus())) {
@ -57,16 +80,6 @@ public class OauthController {
if (RoleCodeEnum.DESKTOP.getDefaultUserId().equals(user.getId())) { if (RoleCodeEnum.DESKTOP.getDefaultUserId().equals(user.getId())) {
throw new BusinessException("oauth.IllegalUserName"); throw new BusinessException("oauth.IllegalUserName");
} }
// Successfully logged in without modifying the administrator password
if (RoleCodeEnum.ADMIN.getDefaultUserId().equals(user.getId()) && RoleCodeEnum.ADMIN.getPassword().equals(
user.getPassword())) {
return DataResult.of(doLogin(user));
}
if (!DigestUtil.bcryptCheck(request.getPassword(), user.getPassword())) {
throw new BusinessException("oauth.passwordIncorrect");
}
return DataResult.of(doLogin(user));
} }
private Object doLogin(User user) { private Object doLogin(User user) {
@ -106,11 +119,7 @@ public class OauthController {
} }
private LoginUser getLoginUser() { private LoginUser getLoginUser() {
LoginUser loginUser = ContextUtils.queryLoginUser(); return ContextUtils.queryLoginUser();
if (loginUser == null) {
return null;
}
return loginUser;
} }
} }