Skip to content

Commit

Permalink
ref: 重构模板文件
Browse files Browse the repository at this point in the history
  • Loading branch information
lltx authored Jul 14, 2024
1 parent f9cf8aa commit 77d2007
Show file tree
Hide file tree
Showing 25 changed files with 243 additions and 142 deletions.
114 changes: 114 additions & 0 deletions common/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import request from "/@/utils/request"

/**
* 根据分页查询参数获取列表数据。
* @param {Object} [query] - 查询参数。
* @returns {Promise} 请求的 Promise 分页对象。
*/
export function fetchList(query?: Object) {
return request({
url: '/${moduleName}/${functionName}/page',
method: 'get',
params: query
})
}

/**
* 添加一个新对象。
* @param {Object} [obj] - 要添加的对象。
* @returns {Promise} 请求的 Promise 对象 (true/false)。
*/
export function addObj(obj?: Object) {
return request({
url: '/${moduleName}/${functionName}',
method: 'post',
data: obj
})
}

/**
* 根据查询参数获取对象详情。
* @param {Object} [obj] - 查询参数。
* @returns {Promise} 请求的 Promise 对象数组。
*/
export function getObj(obj?: Object) {
return request({
url: '/${moduleName}/${functionName}/details',
method: 'get',
params: obj
})
}

/**
* 根据 ID 删除对象。
* @param {Object} [ids] - 要删除的对象 ID。
* @returns {Promise} 请求的 Promise 对象。
*/
export function delObjs(ids?: Object) {
return request({
url: '/${moduleName}/${functionName}',
method: 'delete',
data: ids
})
}

/**
* 更新一个已存在的对象。
* @param {Object} [obj] - 要更新的对象。
* @returns {Promise} 请求的 Promise 对象。
*/
export function putObj(obj?: Object) {
return request({
url: '/${moduleName}/${functionName}',
method: 'put',
data: obj
})
}

/**
* 验证某个字段的值是否已经存在。
* @param {Object} rule - 验证规则对象。
* @param {*} value - 要验证的值。
* @param {Function} callback - 验证完成后的回调函数。
* @param {boolean} isEdit - 当前操作是否为编辑。
*
* 示例用法:
* 字段名: [
* {
* validator: (rule, value, callback) => {
* validateExist(rule, value, callback, form.id !== '');
* },
* trigger: 'blur',
* },
* ]
*/
export function validateExist(rule: any, value: any, callback: any, isEdit: boolean) {
if (isEdit) {
return callback();
}

getObj({ [rule.field]: value }).then((response) => {
const result = response.data;
if (result !== null) {
callback(new Error('数据已经存在'));
} else {
callback();
}
});
}


#if($ChildClassName)
/**
* 删除子对象。
* @param {Object} [ids] - 要删除的子对象 ID。
* @returns {Promise} 请求的 Promise 对象。
*/
export function delChildObj(ids?: Object) {
return request({
url: '/${moduleName}/${functionName}/child',
method: 'delete',
data: ids
})
}
#end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 23 additions & 23 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,114 +3,114 @@
{
"templateName": "Controller",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/controller/${ClassName}Controller.java",
"templateFile": "temps/Controller"
"templateFile": "single/Controller.java"
},
{
"templateName": "Service",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/service/${ClassName}Service.java",
"templateFile": "temps/Service"
"templateFile": "single/Service.java"
},
{
"templateName": "ServiceImpl",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/service/impl/${ClassName}ServiceImpl.java",
"templateFile": "temps/ServiceImpl"
"templateFile": "single/ServiceImpl.java"
},
{
"templateName": "实体",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/entity/${ClassName}Entity.java",
"templateFile": "temps/实体"
"templateFile": "single/实体.java"
},
{
"templateName": "Mapper",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/mapper/${ClassName}Mapper.java",
"templateFile": "temps/Mapper"
"templateFile": "single/Mapper.java"
},
{
"templateName": "Mapper.xml",
"generatorPath": "${backendPath}/src/main/resources/mapper/${ClassName}Mapper.xml",
"templateFile": "temps/Mapper.xml"
"templateFile": "single/Mapper.xml"
},
{
"templateName": "权限菜单",
"generatorPath": "${backendPath}/menu/${functionName}_menu.sql",
"templateFile": "temps/权限菜单"
"templateFile": "common/权限菜单.sql"
},
{
"templateName": "api.ts",
"generatorPath": "${frontendPath}/src/api/${moduleName}/${functionName}.ts",
"templateFile": "temps/api.ts"
"templateFile": "common/api.ts"
},
{
"templateName": "表格",
"generatorPath": "${frontendPath}/src/views/${moduleName}/${functionName}/index.vue",
"templateFile": "temps/表格"
"templateFile": "single/表格.vue"
},
{
"templateName": "表单",
"generatorPath": "${frontendPath}/src/views/${moduleName}/${functionName}/form.vue",
"templateFile": "temps/表单"
"templateFile": "single/表单.vue"
}
],
"主子表增删改查": [
{
"templateName": "Service",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/service/${ClassName}Service.java",
"templateFile": "temps/Service"
"templateFile": "multiple/主子Service.java"
},
{
"templateName": "ServiceImpl",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/service/impl/${ClassName}ServiceImpl.java",
"templateFile": "temps/ServiceImpl"
"templateFile": "multiple/主子ServiceImpl.java"
},
{
"templateName": "实体",
"templateName": "主实体",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/entity/${ClassName}Entity.java",
"templateFile": "temps/实体"
"templateFile": "multiple/主实体.java"
},
{
"templateName": "Mapper",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/mapper/${ClassName}Mapper.java",
"templateFile": "temps/Mapper"
"templateFile": "single/Mapper.java"
},
{
"templateName": "Mapper.xml",
"generatorPath": "${backendPath}/src/main/resources/mapper/${ClassName}Mapper.xml",
"templateFile": "temps/Mapper.xml"
"templateFile": "single/Mapper.xml"
},
{
"templateName": "权限菜单",
"generatorPath": "${backendPath}/menu/${functionName}_menu.sql",
"templateFile": "temps/权限菜单"
"templateFile": "common/权限菜单.sql"
},
{
"templateName": "api.ts",
"generatorPath": "${frontendPath}/src/api/${moduleName}/${functionName}.ts",
"templateFile": "temps/api.ts"
"templateFile": "common/api.ts"
},
{
"templateName": "子实体",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/entity/${ChildClassName}Entity.java",
"templateFile": "temps/子实体"
"templateFile": "multiple/子实体.java"
},
{
"templateName": "主子Contoller",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/controller/${ClassName}Controller.java",
"templateFile": "temps/主子Contoller"
"templateFile": "multiple/主子Contoller.java"
},
{
"templateName": "主子表单",
"generatorPath": "${frontendPath}/src/views/${moduleName}/${functionName}/form.vue",
"templateFile": "temps/主子表单"
"templateFile": "multiple/主子表单.vue"
},
{
"templateName": "主子表格",
"generatorPath": "${frontendPath}/src/views/${moduleName}/${functionName}/index.vue",
"templateFile": "temps/主子表格"
"templateFile": "multiple/主子表格.vue"
},
{
"templateName": "子Mapper",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/mapper/${ChildClassName}Mapper.java",
"templateFile": "temps/子Mapper"
"templateFile": "multiple/子Mapper.java"
}
]
}
20 changes: 0 additions & 20 deletions gen.sh

This file was deleted.

15 changes: 8 additions & 7 deletions temps/主子Contoller → multiple/主子Contoller.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,17 @@ public class ${ClassName}Controller {
return R.ok(${className}Service.page(page, wrapper));
}


/**
* 通过id查询${tableComment}
* @param ${pk.attrName} id
* @return R
* 通过条件查询${tableComment}
* @param ${className} 查询条件
* @return R 对象列表
*/
@Operation(summary = "通过id查询" , description = "通过id查询" )
@GetMapping("/{${pk.attrName}}" )
@Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
@GetMapping("/details" )
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_view')" )
public R getById(@PathVariable("${pk.attrName}" ) ${pk.attrType} ${pk.attrName}) {
return R.ok(${className}Service.getByIdDeep(${pk.attrName}));
public R getDetails(@ParameterObject ${ClassName}Entity ${className}) {
return R.ok(${className}Service.listDeep(Wrappers.query(${className})}));
}

/**
Expand Down
9 changes: 0 additions & 9 deletions temps/Service → multiple/主子Service.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package ${package}.${moduleName}.service;

#if($ChildClassName)
import com.github.yulichang.extension.mapping.base.MPJDeepService;
import ${package}.${moduleName}.entity.${ChildClassName}Entity;
#else
import com.baomidou.mybatisplus.extension.service.IService;
#end
import ${package}.${moduleName}.entity.${ClassName}Entity;

#if($ChildClassName)
public interface ${ClassName}Service extends MPJDeepService<${ClassName}Entity> {
Boolean saveDeep(${ClassName}Entity ${className});

Expand All @@ -17,8 +12,4 @@ public interface ${ClassName}Service extends MPJDeepService<${ClassName}Entity>
Boolean removeDeep(Long[] ids);

Boolean removeChild(Long[] ids);
#else
public interface ${ClassName}Service extends IService<${ClassName}Entity> {
#end

}
8 changes: 2 additions & 6 deletions temps/ServiceImpl → multiple/主子ServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,24 @@
import ${package}.${moduleName}.mapper.${ClassName}Mapper;
import ${package}.${moduleName}.service.${ClassName}Service;
import org.springframework.stereotype.Service;
#if($ChildClassName)
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import ${package}.${moduleName}.entity.${ChildClassName}Entity;
import ${package}.${moduleName}.mapper.${ChildClassName}Mapper;
import org.springframework.transaction.annotation.Transactional;
import lombok.RequiredArgsConstructor;
import java.util.Objects;
#end

/**
* ${tableComment}
*
* @author ${author}
* @date ${datetime}
*/
@Service
#if($ChildClassName)
@RequiredArgsConstructor
#end
public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}Entity> implements ${ClassName}Service {
#if($ChildClassName)

private final ${ChildClassName}Mapper ${childClassName}Mapper;

@Override
Expand Down Expand Up @@ -70,5 +67,4 @@ public Boolean removeChild(Long[] ids) {
${childClassName}Mapper.deleteBatchIds(CollUtil.toList(ids));
return Boolean.TRUE;
}
#end
}
4 changes: 2 additions & 2 deletions temps/主子表单 → multiple/主子表单.vue
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ const deleteChild = async (obj: { $childPkName: string }) => {
// 初始化表单数据
const get${ClassName}Data = (id: string) => {
// 获取数据
getObj(id).then((res: any) => {
Object.assign(form, res.data)
getObj({${pk.attrName}: id).then((res: any) => {
Object.assign(form, res.data[0])
})
};
Expand Down
5 changes: 2 additions & 3 deletions temps/主子表格 → multiple/主子表格.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
<el-form-item label="#if(${field.fieldComment})${field.fieldComment}#else ${field.attrName}#end" prop="${field.attrName}">
<el-radio-group v-model="state.queryForm.${field.attrName}">
#if($field.fieldDict)
<el-radio :label="item.value" v-for="(item, index) in ${field.fieldDict}" border :key="index">{{ item.label }}
</el-radio>
<el-radio :label="item.value" v-for="(item, index) in ${field.fieldDict}" border :key="index">{{ item.label }}</el-radio>
#else
<el-radio label="${field.fieldComment}" border>${field.fieldComment}</el-radio>
<el-radio label="${field.fieldComment}" border>${field.fieldComment}</el-radio>
#end
</el-radio-group>
</el-form-item>
Expand Down
Loading

0 comments on commit 77d2007

Please sign in to comment.