mirror of
https://gitee.com/ssssssss-team/magic-api.git
synced 2026-06-09 18:32:16 +08:00
Merge branch 'dev' of gitee.com:ssssssss-team/magic-api into dev
This commit is contained in:
@@ -222,7 +222,6 @@ public class MagicWorkbenchController extends MagicController implements MagicEx
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ public class NamedTable {
|
||||
|
||||
Object defaultPrimaryValue;
|
||||
|
||||
boolean useLogic = false;
|
||||
|
||||
Where where = new Where(this);
|
||||
|
||||
public NamedTable(String tableName, SQLModule sqlModule, Function<String, String> rowMapColumnMapper) {
|
||||
@@ -46,6 +48,12 @@ public class NamedTable {
|
||||
this.logicDeleteValue = sqlModule.getLogicDeleteValue();
|
||||
}
|
||||
|
||||
@Comment("使用逻辑删除")
|
||||
public NamedTable logic(){
|
||||
this.useLogic = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Comment("设置主键名,update时使用")
|
||||
public NamedTable primary(String primary) {
|
||||
return primary(primary, null);
|
||||
@@ -151,8 +159,13 @@ public class NamedTable {
|
||||
return sqlModule.insert(new BoundSql(builder.toString(), entries.stream().map(Map.Entry::getValue).collect(Collectors.toList()), sqlModule), this.primary);
|
||||
}
|
||||
|
||||
@Comment("执行delete语句(物理删除)")
|
||||
@Comment("执行delete语句")
|
||||
public int delete() {
|
||||
if(useLogic){
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put(logicDeleteColumn, logicDeleteValue);
|
||||
return update(dataMap);
|
||||
}
|
||||
if (where.isEmpty()) {
|
||||
throw new MagicAPIException("delete语句不能没有条件");
|
||||
}
|
||||
@@ -163,20 +176,6 @@ public class NamedTable {
|
||||
return sqlModule.update(new BoundSql(builder.toString(), where.getParams(), sqlModule));
|
||||
}
|
||||
|
||||
@Comment("执行delete语句")
|
||||
public int delete(@Comment("是否逻辑删除") boolean isLogicDelete) {
|
||||
if (where.isEmpty()) {
|
||||
throw new MagicAPIException("delete语句不能没有条件");
|
||||
}
|
||||
if (!isLogicDelete) {
|
||||
return delete();
|
||||
} else {
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put(logicDeleteColumn, logicDeleteValue);
|
||||
return update(dataMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Comment("保存到表中,当主键有值时则修改,否则插入")
|
||||
public Object save() {
|
||||
return this.save(null, false);
|
||||
@@ -227,26 +226,12 @@ public class NamedTable {
|
||||
return sqlModule.select(buildSelect());
|
||||
}
|
||||
|
||||
@Comment("执行`select`查询")
|
||||
public List<Map<String, Object>> select(@Comment("排除无效数据") boolean excludeInvalid) {
|
||||
return sqlModule.select(buildSelect(excludeInvalid));
|
||||
}
|
||||
|
||||
@Comment("执行`selectOne`查询")
|
||||
public Map<String, Object> selectOne() {
|
||||
return sqlModule.selectOne(buildSelect());
|
||||
}
|
||||
|
||||
@Comment("执行`selectOne`查询")
|
||||
public Map<String, Object> selectOne(@Comment("排除无效数据") boolean excludeInvalid) {
|
||||
return sqlModule.selectOne(buildSelect(excludeInvalid));
|
||||
}
|
||||
|
||||
private BoundSql buildSelect() {
|
||||
return buildSelect(false);
|
||||
}
|
||||
|
||||
private BoundSql buildSelect(boolean excludeInvalid) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("select ");
|
||||
if (this.fields.isEmpty()) {
|
||||
@@ -256,7 +241,7 @@ public class NamedTable {
|
||||
}
|
||||
builder.append(" from ").append(tableName);
|
||||
List<Object> params = new ArrayList<>();
|
||||
where.and(excludeInvalid, it -> where.ne(logicDeleteColumn, logicDeleteValue));
|
||||
where.and(useLogic, it -> where.ne(logicDeleteColumn, logicDeleteValue));
|
||||
if (!where.isEmpty()) {
|
||||
where.and();
|
||||
builder.append(where.getSql());
|
||||
@@ -278,11 +263,6 @@ public class NamedTable {
|
||||
return sqlModule.page(buildSelect());
|
||||
}
|
||||
|
||||
@Comment("执行分页查询")
|
||||
public Object page(@Comment("排除无效数据") boolean excludeInvalid) {
|
||||
return sqlModule.page(buildSelect(excludeInvalid));
|
||||
}
|
||||
|
||||
@Comment("执行update语句")
|
||||
public int update() {
|
||||
return update(null);
|
||||
|
||||
@@ -385,14 +385,11 @@ public class Where {
|
||||
return namedTable.delete();
|
||||
}
|
||||
|
||||
@Comment("执行delete语句")
|
||||
public int delete(@Comment("是否逻辑删除")boolean isLogicDelete) {
|
||||
return namedTable.delete(isLogicDelete);
|
||||
}
|
||||
@Comment("执行update语句")
|
||||
public int update(@Comment("各项列和值") Map<String, Object> data) {
|
||||
return namedTable.update(data);
|
||||
}
|
||||
|
||||
@Comment("执行update语句")
|
||||
public int update(@Comment("各项列和值") Map<String, Object> data,@Comment("是否更新空值字段") boolean isUpdateBlank) {
|
||||
return namedTable.update(data,isUpdateBlank);
|
||||
@@ -401,24 +398,14 @@ public class Where {
|
||||
public Object page() {
|
||||
return namedTable.page();
|
||||
}
|
||||
@Comment("执行分页查询")
|
||||
public Object page(@Comment("排除无效数据") boolean excludeInvalid) {
|
||||
return namedTable.page();
|
||||
}
|
||||
|
||||
@Comment("执行select查询")
|
||||
public List<Map<String, Object>> select() {
|
||||
return namedTable.select();
|
||||
}
|
||||
@Comment("执行select查询")
|
||||
public List<Map<String, Object>> select(@Comment("排除无效数据") boolean excludeInvalid) {
|
||||
return namedTable.select(excludeInvalid);
|
||||
}
|
||||
|
||||
@Comment("执行selectOne查询")
|
||||
public Map<String, Object> selectOne() {
|
||||
return namedTable.selectOne();
|
||||
}
|
||||
@Comment("执行selectOne查询")
|
||||
public Map<String, Object> selectOne(@Comment("排除无效数据") boolean excludeInvalid) {
|
||||
return namedTable.selectOne(excludeInvalid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,11 +179,18 @@ const findMethods = (clazz, sort) => {
|
||||
const getExtension = (clazz) => {
|
||||
return extensions[clazz]
|
||||
}
|
||||
|
||||
async function loadClass(className) {
|
||||
const findClass = (className) => {
|
||||
if (!className) {
|
||||
throw new Error('className is required');
|
||||
}
|
||||
let value = scriptClass[className]
|
||||
if(!value){
|
||||
let index = importClass.findIndex(it => it === className)
|
||||
value = importClass[index]
|
||||
}
|
||||
return value
|
||||
}
|
||||
async function loadClass(className) {
|
||||
let val = scriptClass[className];
|
||||
if (!val) {
|
||||
try {
|
||||
@@ -248,6 +255,7 @@ const exportValue = {
|
||||
findMethods,
|
||||
findFunction,
|
||||
loadClass,
|
||||
findClass,
|
||||
initClasses,
|
||||
initImportClass,
|
||||
getWrapperClass,
|
||||
|
||||
@@ -134,7 +134,15 @@ class VariableAccess extends Node {
|
||||
}
|
||||
|
||||
async getJavaType(env) {
|
||||
return (env && env[this.variable]) || 'java.lang.Object';
|
||||
// @import
|
||||
let value = (env && env[this.variable]);
|
||||
if(!value){
|
||||
let imports = env['@import']
|
||||
for(let i = imports.length - 1; i >= 0 && !value; i--){
|
||||
value = JavaClass.findClass(imports[i] + this.variable);
|
||||
}
|
||||
}
|
||||
return value|| 'java.lang.Object';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +249,15 @@ class NewStatement extends Node {
|
||||
}
|
||||
|
||||
async getJavaType(env) {
|
||||
return env[this.identifier] || 'java.lang.Object';
|
||||
let value = env[this.identifier];
|
||||
if(!value){
|
||||
let imports = env['@import']
|
||||
for(let i = imports.length - 1; i >= 0 && !value; i--){
|
||||
value = JavaClass.findClass(imports[i] + this.identifier);
|
||||
}
|
||||
console.log(imports,this.identifier, value)
|
||||
}
|
||||
return value|| 'java.lang.Object';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,8 +438,8 @@ class BinaryOperation extends Node {
|
||||
}
|
||||
|
||||
async getJavaType(env) {
|
||||
var lType = await this.left.getJavaType(env);
|
||||
var rType = await this.right.getJavaType(env);
|
||||
let lType = await this.left.getJavaType(env);
|
||||
let rType = await this.right.getJavaType(env);
|
||||
if (this.operator.type == TokenType.Plus || this.operator.type == TokenType.PlusEqual) {
|
||||
if (lType == 'string' || rType == 'string' || lType == 'java.lang.String' || rType == 'java.lang.String') {
|
||||
return 'java.lang.String';
|
||||
|
||||
@@ -35,7 +35,7 @@ import {
|
||||
LanguageExpression
|
||||
} from './ast.js'
|
||||
|
||||
export const keywords = ["import", "as", "var", "return", "break", "continue", "if", "for", "in", "new", "true", "false", "null", "else", "try", "catch", "finally", "async", "while"];
|
||||
export const keywords = ["import", "as", "var", "return", "break", "continue", "if", "for", "in", "new", "true", "false", "null", "else", "try", "catch", "finally", "async", "while", "exit", "and", "or"];
|
||||
export const linqKeywords = ["from", "join", "left", "group", "by", "as", "having", "and", "or", "in", "where", "on"];
|
||||
const binaryOperatorPrecedence = [
|
||||
[TokenType.Assignment],
|
||||
@@ -688,12 +688,13 @@ export class Parser {
|
||||
let env = {
|
||||
...defineEnvironment,
|
||||
...JavaClass.getAutoImportClass(),
|
||||
...JavaClass.getAutoImportModule()
|
||||
...JavaClass.getAutoImportModule(),
|
||||
'@import' : []
|
||||
}
|
||||
let expression;
|
||||
while (this.stream.hasMore()) {
|
||||
let token = this.stream.consume();
|
||||
var index = this.stream.makeIndex();
|
||||
let index = this.stream.makeIndex();
|
||||
try {
|
||||
if (token.type === TokenType.Identifier && token.getText() === 'var') {
|
||||
let varName = this.stream.consume().getText();
|
||||
@@ -724,7 +725,9 @@ export class Parser {
|
||||
varName = value.substring(index + 1)
|
||||
}
|
||||
}
|
||||
if (varName) {
|
||||
if(value.endsWith(".*")){
|
||||
env['@import'].push(value.substring(0,value.length - 1))
|
||||
}else if (varName) {
|
||||
env[varName] = value;
|
||||
}
|
||||
} else if (token.getTokenType() === TokenType.Assignment) {
|
||||
@@ -751,7 +754,7 @@ export class Parser {
|
||||
}
|
||||
|
||||
async completion(env) {
|
||||
var type = await this.preprocessComplection(true, env || {});
|
||||
let type = await this.preprocessComplection(true, env || {});
|
||||
return await JavaClass.loadClass(type);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user