add: 新增代码生成器
This commit is contained in:
@@ -55,10 +55,10 @@ public class CodeGenerator {
|
||||
mpg.setGlobalConfig(gc);
|
||||
// 数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl("jdbc:mysql://192.168.81.252:3306/nl-sso-server?setUnicode=true&characterEncoding=utf8");
|
||||
dsc.setUrl("jdbc:mysql://127.0.0.1:3306/stand_lms?setUnicode=true&characterEncoding=utf8");
|
||||
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
||||
dsc.setUsername("root");
|
||||
dsc.setPassword("Root.123456");
|
||||
dsc.setPassword("12356");
|
||||
mpg.setDataSource(dsc);
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.nl.config.mybatis;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: ID自动生成策略
|
||||
* @Date: 2023/5/4
|
||||
*/
|
||||
@Component
|
||||
public class CustomIdGenerator implements IdentifierGenerator {
|
||||
@Override
|
||||
public Number nextId(Object entity) {
|
||||
return IdUtil.getSnowflake(1,1).nextId();
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package org.nl.modules.common.generator.domain;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.nl.modules.common.generator.utils.GenUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author: lyd
|
||||
* @description:
|
||||
* @Date: 2022/12/2
|
||||
*/
|
||||
@Data
|
||||
public class ColumnInfo implements Serializable {
|
||||
|
||||
/** 防止精度丢失 */
|
||||
@JsonSerialize(using= ToStringSerializer.class)
|
||||
private Long column_id;
|
||||
|
||||
@ApiModelProperty(value = "表名")
|
||||
private String table_name;
|
||||
|
||||
@ApiModelProperty(value = "数据库字段名称")
|
||||
private String column_name;
|
||||
|
||||
@ApiModelProperty(value = "数据库字段类型")
|
||||
private String column_type;
|
||||
|
||||
@ApiModelProperty(value = "数据库字段键类型")
|
||||
private String key_type;
|
||||
|
||||
@ApiModelProperty(value = "字段额外的参数")
|
||||
private String extra;
|
||||
|
||||
@ApiModelProperty(value = "数据库字段描述")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "是否必填")
|
||||
private String not_null;
|
||||
|
||||
@ApiModelProperty(value = "是否在列表显示")
|
||||
private String list_show;
|
||||
|
||||
@ApiModelProperty(value = "是否表单显示")
|
||||
private String form_show;
|
||||
|
||||
@ApiModelProperty(value = "表单类型")
|
||||
private String form_type;
|
||||
|
||||
@ApiModelProperty(value = "查询 1:模糊 2:精确")
|
||||
private String query_type;
|
||||
|
||||
@ApiModelProperty(value = "字典名称")
|
||||
private String dict_name;
|
||||
|
||||
@ApiModelProperty(value = "日期注解")
|
||||
private String date_annotation;
|
||||
|
||||
public ColumnInfo(String tableName, Long column_id, String columnName, Boolean notNull, String columnType, String remark, String keyType, String extra) {
|
||||
this.table_name = tableName;
|
||||
this.column_id = column_id;
|
||||
this.column_name = columnName;
|
||||
this.column_type = columnType;
|
||||
this.key_type = keyType;
|
||||
this.extra = extra;
|
||||
this.not_null = notNull?"1":"0";
|
||||
if(GenUtil.PK.equalsIgnoreCase(keyType) && GenUtil.EXTRA.equalsIgnoreCase(extra)){
|
||||
this.not_null = "0";
|
||||
}
|
||||
this.remark = remark;
|
||||
this.list_show = "1";
|
||||
this.form_show = "1";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package org.nl.modules.common.generator.domain;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author: lyd
|
||||
* @description: code_gen_config
|
||||
* @Date: 2022/12/2
|
||||
*/
|
||||
@Data
|
||||
public class GenConfig implements Serializable {
|
||||
public GenConfig(String tableName) {
|
||||
this.table_name = tableName;
|
||||
}
|
||||
/** 防止精度丢失 */
|
||||
@JsonSerialize(using= ToStringSerializer.class)
|
||||
private Long config_id;
|
||||
|
||||
@NotBlank
|
||||
@ApiModelProperty(value = "表名")
|
||||
private String table_name;
|
||||
|
||||
@ApiModelProperty(value = "接口名称")
|
||||
private String api_alias;
|
||||
|
||||
@NotBlank
|
||||
@ApiModelProperty(value = "包路径")
|
||||
private String pack;
|
||||
|
||||
@NotBlank
|
||||
@ApiModelProperty(value = "模块名")
|
||||
private String module_name;
|
||||
|
||||
@NotBlank
|
||||
@ApiModelProperty(value = "前端文件路径")
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty(value = "前端文件路径")
|
||||
private String api_path;
|
||||
|
||||
@ApiModelProperty(value = "作者")
|
||||
private String author;
|
||||
|
||||
@ApiModelProperty(value = "表前缀")
|
||||
private String prefix;
|
||||
|
||||
@ApiModelProperty(value = "是否覆盖")
|
||||
private String cover = "0";
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package org.nl.modules.common.generator.domain.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author: lyd
|
||||
* @description: 表的数据信息
|
||||
* @Date: 2022/12/2
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TableInfo {
|
||||
|
||||
/** 表名称 */
|
||||
private Object tableName;
|
||||
|
||||
/** 创建日期 */
|
||||
private Object createTime;
|
||||
|
||||
/** 数据库引擎 */
|
||||
private Object engine;
|
||||
|
||||
/** 编码集 */
|
||||
private Object coding;
|
||||
|
||||
/** 备注 */
|
||||
private Object remark;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package org.nl.modules.common.generator.rest;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.common.generator.service.GenConfigService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author: lyd
|
||||
* @description: 代码生成器配置管理
|
||||
* @Date: 2022/12/2
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/genConfig")
|
||||
@Api(tags = "系统:代码生成器配置管理")
|
||||
public class GenConfigController {
|
||||
private final GenConfigService genConfigService;
|
||||
|
||||
@ApiOperation("查询")
|
||||
@GetMapping(value = "/{tableName}")
|
||||
public ResponseEntity<Object> query(@PathVariable String tableName){
|
||||
return new ResponseEntity<>(genConfigService.find(tableName), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("修改")
|
||||
@PutMapping
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody JSONObject genConfig){
|
||||
return new ResponseEntity<>(genConfigService.update(genConfig),HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package org.nl.modules.common.generator.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* @author: lyd
|
||||
* @description:
|
||||
* @Date: 2022/12/2
|
||||
*/
|
||||
public interface GenConfigService {
|
||||
/**
|
||||
* 查询表配置
|
||||
* @param tableName 表名
|
||||
* @return 表配置
|
||||
*/
|
||||
JSONObject find(String tableName);
|
||||
|
||||
/**
|
||||
* 更新表配置
|
||||
* @param genConfig 表配置
|
||||
* @return 表配置
|
||||
*/
|
||||
JSONObject update(JSONObject genConfig);
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package org.nl.modules.common.generator.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.modules.common.generator.domain.ColumnInfo;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: lyd
|
||||
* @description:
|
||||
* @Date: 2022/12/2
|
||||
*/
|
||||
public interface GeneratorService {
|
||||
|
||||
/**
|
||||
* 查询数据库元数据
|
||||
* @param name 表名
|
||||
* @param pageable 分页参数
|
||||
* @return /
|
||||
*/
|
||||
Object getTables(String name, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 得到数据表的元数据
|
||||
* @param name 表名
|
||||
* @return /
|
||||
*/
|
||||
JSONObject getColumns(String name);
|
||||
|
||||
/**
|
||||
* 同步表数据
|
||||
* @param columnInfos / content
|
||||
* @param columnInfoList /
|
||||
*/
|
||||
@Async
|
||||
void sync(JSONObject columnInfos, JSONArray columnInfoList);
|
||||
|
||||
/**
|
||||
* 获取所有table
|
||||
* @return /
|
||||
*/
|
||||
Object getTables();
|
||||
|
||||
/**
|
||||
* 查询数据库的表字段数据数据
|
||||
* @param table /
|
||||
* @return /
|
||||
*/
|
||||
JSONArray query(String table);
|
||||
|
||||
/**
|
||||
* 保存字段
|
||||
* @param columnInfos
|
||||
*/
|
||||
void save(JSONArray columnInfos);
|
||||
|
||||
/**
|
||||
* 预览
|
||||
* @param genConfig 配置信息
|
||||
* @param columns 字段信息 数组存在content
|
||||
* @return /
|
||||
*/
|
||||
ResponseEntity<Object> preview(JSONObject genConfig, JSONObject columns);
|
||||
|
||||
/**
|
||||
* 代码生成
|
||||
* @param genConfig 配置信息
|
||||
* @param columns 字段信息 数组存在content
|
||||
*/
|
||||
void generator(JSONObject genConfig, JSONObject columns);
|
||||
|
||||
/**
|
||||
* 打包下载
|
||||
* @param genConfig 配置信息
|
||||
* @param columns 字段信息 数组存在content
|
||||
* @param request /
|
||||
* @param response /
|
||||
*/
|
||||
void download(JSONObject genConfig, JSONObject columns, HttpServletRequest request, HttpServletResponse response);
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package org.nl.modules.common.generator.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.common.generator.domain.GenConfig;
|
||||
import org.nl.modules.common.generator.service.GenConfigService;
|
||||
import org.nl.modules.wql.core.bean.WQLObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author: lyd
|
||||
* @description:
|
||||
* @Date: 2022/12/2
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GenConfigServiceImpl implements GenConfigService {
|
||||
/**
|
||||
* 查询表配置
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @return 表配置
|
||||
*/
|
||||
@Override
|
||||
public JSONObject find(String tableName) {
|
||||
WQLObject genTab = WQLObject.getWQLObject("code_gen_config");
|
||||
JSONObject jsonObject = genTab.query("table_name = '" + tableName + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(jsonObject))
|
||||
return JSONObject.parseObject(JSONObject.toJSONString(new GenConfig(tableName)));
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新表配置
|
||||
*
|
||||
* @param genConfig 表名 + 表配置
|
||||
* @return 表配置
|
||||
*/
|
||||
@Override
|
||||
public JSONObject update(JSONObject genConfig) {
|
||||
WQLObject genTab = WQLObject.getWQLObject("code_gen_config");
|
||||
if (ObjectUtil.isEmpty(genConfig.getString("config_id"))) {
|
||||
// 创建
|
||||
genConfig.put("config_id", IdUtil.getSnowflake(1, 1).nextId());
|
||||
genTab.insert(genConfig);
|
||||
} else {
|
||||
// 更新
|
||||
genTab.update(genConfig);
|
||||
}
|
||||
return genConfig;
|
||||
}
|
||||
}
|
||||
@@ -1,241 +0,0 @@
|
||||
package org.nl.modules.common.generator.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.generator.domain.ColumnInfo;
|
||||
import org.nl.modules.common.generator.service.GeneratorService;
|
||||
import org.nl.modules.common.generator.utils.GenUtil;
|
||||
import org.nl.modules.common.utils.FileUtil;
|
||||
import org.nl.modules.wql.WQL;
|
||||
import org.nl.modules.wql.core.bean.WQLObject;
|
||||
import org.nl.modules.wql.util.WqlUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author: lyd
|
||||
* @description:
|
||||
* @Date: 2022/12/2
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GeneratorServiceImpl implements GeneratorService {
|
||||
private static final Logger log = LoggerFactory.getLogger(GeneratorServiceImpl.class);
|
||||
|
||||
/**
|
||||
* 查询数据库元数据
|
||||
*
|
||||
* @param name 表名
|
||||
* @param pageable 分页参数
|
||||
* @return /
|
||||
*/
|
||||
@Override
|
||||
public Object getTables(String name, Pageable pageable) {
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("flag", "1");
|
||||
if (ObjectUtil.isNotEmpty(name))
|
||||
map.put("table_name", name);
|
||||
JSONObject json = WQL.getWO("Generator").addParamMap(map).pageQuery(WqlUtil.getHttpContext(pageable), "create_time desc");
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到数据表的元数据
|
||||
*
|
||||
* @param name 表名
|
||||
* @return /
|
||||
*/
|
||||
@Override
|
||||
public JSONObject getColumns(String name) {
|
||||
WQLObject colTab = WQLObject.getWQLObject("code_column_config");
|
||||
JSONObject content = new JSONObject();
|
||||
JSONArray array = colTab.query("table_name = '" + name + "'").getResultJSONArray(0);
|
||||
if (ObjectUtil.isEmpty(array)) {
|
||||
array = query(name);
|
||||
// 保存
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject jsonObject = array.getJSONObject(i);
|
||||
colTab.insert(jsonObject);
|
||||
}
|
||||
}
|
||||
content.put("content", array);
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步表数据
|
||||
*
|
||||
* @param content /
|
||||
* @param columnInfoList /
|
||||
*/
|
||||
@Override
|
||||
public void sync(JSONObject content, JSONArray columnInfoList) {
|
||||
WQLObject colTab = WQLObject.getWQLObject("code_column_config");
|
||||
JSONArray columnInfos = content.getJSONArray("content");
|
||||
// 第一种情况,数据库类字段改变或者新增字段
|
||||
for (int i = 0; i < columnInfoList.size(); i++) {
|
||||
JSONObject columnInfoObj = columnInfoList.getJSONObject(i);
|
||||
JSONArray columns = new JSONArray();
|
||||
for (int j = 0; j < columnInfos.size(); j++) {
|
||||
JSONObject columnInfosObj = columnInfos.getJSONObject(j);
|
||||
if (columnInfoObj.getString("column_name").equals(columnInfosObj.getString("column_name"))) {
|
||||
columns.add(columnInfosObj);
|
||||
}
|
||||
}
|
||||
// 如果能找到,就修改部分可能被字段
|
||||
if (CollectionUtil.isNotEmpty(columns)) {
|
||||
JSONObject column = columns.getJSONObject(0);
|
||||
column.put("column_type", columnInfoObj.getString("column_type"));
|
||||
column.put("extra", columnInfoObj.getString("extra"));
|
||||
column.put("key_type", columnInfoObj.getString("key_type"));
|
||||
if (StrUtil.isEmpty(column.getString("remark"))) {
|
||||
column.put("remark", columnInfoObj.getString("remark"));
|
||||
}
|
||||
colTab.update(column);
|
||||
} else {
|
||||
// 如果找不到,则保存新字段信息
|
||||
colTab.insert(columnInfoObj);
|
||||
}
|
||||
}
|
||||
// 第二种情况,数据库字段删除了
|
||||
for (int k = 0; k < columnInfos.size(); k++) {
|
||||
JSONArray columns = new JSONArray();
|
||||
JSONObject columnInfo = columnInfos.getJSONObject(k);
|
||||
for (int l = 0; l < columnInfoList.size(); l++) {
|
||||
JSONObject c = columnInfoList.getJSONObject(l);
|
||||
if (columnInfo.getString("column_name").equals(c.getString("column_name"))) {
|
||||
columns.add(c);
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isEmpty(columnInfo)) colTab.delete(columnInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONArray query(String tableName) {
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("flag", "2");
|
||||
map.put("table_name", tableName);
|
||||
JSONArray generator = WQL.getWO("Generator").addParamMap(map).process().getResultJSONArray(0);
|
||||
JSONArray columnInfos = new JSONArray();
|
||||
for (int i = 0; i < generator.size(); i++) {
|
||||
JSONObject obj = generator.getJSONObject(i);
|
||||
columnInfos.add(
|
||||
JSONObject.parseObject(JSON.toJSONString(new ColumnInfo(
|
||||
tableName,
|
||||
IdUtil.getSnowflake(1,1).nextId(),
|
||||
obj.getString("column_name"),
|
||||
"NO".equals(obj.getString("is_nullable")),
|
||||
obj.getString("data_type"),
|
||||
ObjectUtil.isNotEmpty(obj.getString("column_comment")) ? obj.getString("column_comment") : null,
|
||||
ObjectUtil.isNotEmpty(obj.getString("column_key")) ? obj.getString("column_key") : null,
|
||||
ObjectUtil.isNotEmpty(obj.getString("extra")) ? obj.getString("extra") : null
|
||||
)))
|
||||
);
|
||||
}
|
||||
return columnInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存字段
|
||||
*
|
||||
* @param columnInfos
|
||||
*/
|
||||
@Override
|
||||
public void save(JSONArray columnInfos) {
|
||||
WQLObject colTab = WQLObject.getWQLObject("code_column_config");
|
||||
for (int i = 0; i < columnInfos.size(); i++) {
|
||||
JSONObject object = columnInfos.getJSONObject(i);
|
||||
colTab.update(object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览
|
||||
*
|
||||
* @param genConfig 配置信息
|
||||
* @param columns 字段信息 数组存在content
|
||||
* @return /
|
||||
*/
|
||||
@Override
|
||||
public ResponseEntity<Object> preview(JSONObject genConfig, JSONObject columns) {
|
||||
JSONArray column = columns.getJSONArray("content");
|
||||
if (ObjectUtil.isEmpty(genConfig.getString("config_id"))) throw new BadRequestException("请先配置生成器");
|
||||
JSONArray genList = GenUtil.preview(column, genConfig);
|
||||
return new ResponseEntity<>(genList, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码生成
|
||||
*
|
||||
* @param genConfig 配置信息
|
||||
* @param columns 字段信息 数组存在content
|
||||
*/
|
||||
@Override
|
||||
public void generator(JSONObject genConfig, JSONObject columns) {
|
||||
JSONArray column = columns.getJSONArray("content");
|
||||
if (ObjectUtil.isEmpty(genConfig.getString("config_id"))) throw new BadRequestException("请先配置生成器");
|
||||
try {
|
||||
GenUtil.generatorCode(column, genConfig);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new BadRequestException("生成失败,请手动处理已生成的文件");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打包下载
|
||||
*
|
||||
* @param genConfig 配置信息
|
||||
* @param columns 字段信息 数组存在content
|
||||
* @param request /
|
||||
* @param response /
|
||||
*/
|
||||
@Override
|
||||
public void download(JSONObject genConfig, JSONObject columns, HttpServletRequest request, HttpServletResponse response) {
|
||||
JSONArray column = columns.getJSONArray("content");
|
||||
if (ObjectUtil.isEmpty(genConfig.getString("config_id"))) throw new BadRequestException("请先配置生成器");
|
||||
try {
|
||||
File file = new File(GenUtil.download(column, genConfig));
|
||||
String zipPath = file.getPath() + ".zip";
|
||||
ZipUtil.zip(file.getPath(), zipPath);
|
||||
FileUtil.downloadFile(request, response, new File(zipPath), true);
|
||||
} catch (IOException e) {
|
||||
throw new BadRequestException("下载失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有table
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@Override
|
||||
public Object getTables() {
|
||||
// 使用预编译防止sql注入
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("flag", "1");
|
||||
JSONArray generator = WQL.getWO("Generator").addParamMap(map).process().getResultJSONArray(0);
|
||||
return generator;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
[交易说明]
|
||||
交易名: 任务分页查询
|
||||
所属模块:
|
||||
功能简述:
|
||||
版权所有:
|
||||
表引用:
|
||||
版本经历:
|
||||
|
||||
[数据库]
|
||||
--指定数据库,为空采用默认值,默认为db.properties中列出的第一个库
|
||||
|
||||
[IO定义]
|
||||
#################################################
|
||||
## 表字段对应输入参数
|
||||
#################################################
|
||||
输入.flag TYPEAS s_string
|
||||
输入.table_name TYPEAS s_string
|
||||
|
||||
[临时表]
|
||||
--这边列出来的临时表就会在运行期动态创建
|
||||
|
||||
[临时变量]
|
||||
--所有中间过程变量均可在此处定义
|
||||
|
||||
[业务过程]
|
||||
|
||||
##########################################
|
||||
# 1、输入输出检查 #
|
||||
##########################################
|
||||
|
||||
|
||||
##########################################
|
||||
# 2、主过程前处理 #
|
||||
##########################################
|
||||
|
||||
|
||||
##########################################
|
||||
# 3、业务主过程 #
|
||||
##########################################
|
||||
|
||||
IF 输入.flag = "1"
|
||||
PAGEQUERY
|
||||
SELECT
|
||||
table_name,
|
||||
DATE_FORMAT(now(),"%Y-%m-%d %T") create_time,
|
||||
ENGINE,
|
||||
table_collation as coding,
|
||||
table_comment as remark
|
||||
FROM
|
||||
information_schema.TABLES
|
||||
WHERE
|
||||
table_schema = (SELECT DATABASE())
|
||||
OPTION 输入.table_name <> ""
|
||||
table_name like "%" 输入.table_name "%"
|
||||
ENDOPTION
|
||||
ENDSELECT
|
||||
ENDPAGEQUERY
|
||||
ENDIF
|
||||
|
||||
IF 输入.flag = "2"
|
||||
PAGEQUERY
|
||||
SELECT
|
||||
column_name,
|
||||
is_nullable,
|
||||
data_type,
|
||||
column_comment,
|
||||
column_key,
|
||||
extra
|
||||
FROM
|
||||
information_schema.COLUMNS
|
||||
WHERE
|
||||
table_schema = (
|
||||
SELECT DATABASE
|
||||
())
|
||||
OPTION 输入.table_name <> ""
|
||||
table_name = 输入.table_name
|
||||
ENDOPTION
|
||||
ORDER BY
|
||||
ordinal_position
|
||||
ENDSELECT
|
||||
ENDPAGEQUERY
|
||||
ENDIF
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.nl.modules.common.generator.utils;
|
||||
package org.nl.modules.common.utils;
|
||||
|
||||
import org.apache.commons.configuration.Configuration;
|
||||
import org.apache.commons.configuration.ConfigurationException;
|
||||
@@ -1,12 +1,10 @@
|
||||
package org.nl.modules.common.generator.utils;
|
||||
package org.nl.modules.common.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.template.*;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.modules.common.utils.FileUtil;
|
||||
import org.nl.modules.common.utils.StringUtils;
|
||||
import org.nl.system.service.generator.dao.CodeColumnConfig;
|
||||
import org.nl.system.service.generator.dao.CodeGenConfig;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -46,11 +44,12 @@ public class GenUtil {
|
||||
*/
|
||||
private static List<String> getAdminTemplateNames() {
|
||||
List<String> templateNames = new ArrayList<>();
|
||||
// templateNames.add("Entity");
|
||||
templateNames.add("Entity");
|
||||
templateNames.add("MySQLMapper");
|
||||
templateNames.add("Dto");
|
||||
// templateNames.add("Mapper");
|
||||
templateNames.add("Mapper");
|
||||
templateNames.add("Controller");
|
||||
//templateNames.add("QueryCriteria");
|
||||
templateNames.add("QueryCriteria");
|
||||
templateNames.add("Service");
|
||||
templateNames.add("ServiceImpl");
|
||||
// templateNames.add("Repository");
|
||||
@@ -69,13 +68,13 @@ public class GenUtil {
|
||||
return templateNames;
|
||||
}
|
||||
|
||||
public static JSONArray preview(JSONArray columns, JSONObject genConfig) {
|
||||
JSONObject genMap = getGenMap(columns, genConfig);
|
||||
JSONArray genList = new JSONArray();
|
||||
public static List<Map<String, Object>> preview(List<CodeColumnConfig> columns, CodeGenConfig genConfig) {
|
||||
Map<String, Object> genMap = getGenMap(columns, genConfig); // 获取参数
|
||||
List<Map<String, Object>> genList = new ArrayList<>();
|
||||
// 获取后端模版
|
||||
List<String> templates = getAdminTemplateNames();
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||
for (String templateName : templates) {
|
||||
for (String templateName : templates) { // 创建模板
|
||||
Map<String, Object> map = new HashMap<>(1);
|
||||
Template template = engine.getTemplate("generator/admin/" + templateName + ".ftl");
|
||||
map.put("content", template.render(genMap));
|
||||
@@ -95,137 +94,61 @@ public class GenUtil {
|
||||
return genList;
|
||||
}
|
||||
|
||||
public static void generatorCode(JSONArray columns, JSONObject genConfig) throws IOException {
|
||||
JSONObject genMap = getGenMap(columns, genConfig);
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||
// 生成后端代码
|
||||
List<String> templates = getAdminTemplateNames();
|
||||
for (String templateName : templates) {
|
||||
Template template = engine.getTemplate("generator/admin/" + templateName + ".ftl");
|
||||
String filePath = getAdminFilePath(templateName, genConfig, genMap.get("className").toString(), System.getProperty("user.dir"));
|
||||
|
||||
assert filePath != null;
|
||||
File file = new File(filePath);
|
||||
|
||||
// 如果非覆盖生成
|
||||
if (!genConfig.getString("cover").equals("1") && FileUtil.exist(file)) {
|
||||
continue;
|
||||
}
|
||||
// 生成代码
|
||||
genFile(file, template, genMap);
|
||||
}
|
||||
// 生成前端代码
|
||||
templates = getFrontTemplateNames();
|
||||
for (String templateName : templates) {
|
||||
Template template = engine.getTemplate("generator/front/" + templateName + ".ftl");
|
||||
// api 和 vue文件都放一起,所以这里不需要传api_path
|
||||
String filePath = getFrontFilePath(templateName, genConfig.getString("path"), genConfig.getString("path"), genMap.get("changeClassName").toString());
|
||||
|
||||
assert filePath != null;
|
||||
File file = new File(filePath);
|
||||
|
||||
// 如果非覆盖生成
|
||||
if (!genConfig.getString("cover").equals("1") && FileUtil.exist(file)) {
|
||||
continue;
|
||||
}
|
||||
// 生成代码
|
||||
genFile(file, template, genMap);
|
||||
}
|
||||
}
|
||||
|
||||
// 下载
|
||||
public static String download(JSONArray columns, JSONObject genConfig) throws IOException {
|
||||
// 拼接的路径:/tmpnladmin-gen-temp/,这个路径在Linux下需要root用户才有权限创建,非root用户会权限错误而失败,更改为: /tmp/nladmin-gen-temp/
|
||||
// String tempPath =SYS_TEM_DIR + "nladmin-gen-temp" + File.separator + genConfig.getTableName() + File.separator;
|
||||
String tempPath = SYS_TEM_DIR + "nladmin-gen-temp" + File.separator + genConfig.getString("table_name") + File.separator;
|
||||
JSONObject genMap = getGenMap(columns, genConfig);
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||
// 生成后端代码
|
||||
List<String> templates = getAdminTemplateNames();
|
||||
for (String templateName : templates) {
|
||||
Template template = engine.getTemplate("generator/admin/" + templateName + ".ftl");
|
||||
String filePath = getAdminFilePath(templateName, genConfig, genMap.get("className").toString(), tempPath + "eladmin" + File.separator);
|
||||
assert filePath != null;
|
||||
File file = new File(filePath);
|
||||
// 如果非覆盖生成
|
||||
if (!genConfig.getString("cover").equals("1") && FileUtil.exist(file)) {
|
||||
continue;
|
||||
}
|
||||
// 生成代码
|
||||
genFile(file, template, genMap);
|
||||
}
|
||||
// 生成前端代码
|
||||
templates = getFrontTemplateNames();
|
||||
for (String templateName : templates) {
|
||||
Template template = engine.getTemplate("generator/front/" + templateName + ".ftl");
|
||||
// api 和 vue文件都放一起,所以这里不需要传api_path
|
||||
String filePath = getFrontFilePath(templateName, genConfig.getString("path"), genConfig.getString("path"), genMap.get("changeClassName").toString());
|
||||
|
||||
assert filePath != null;
|
||||
File file = new File(filePath);
|
||||
|
||||
// 如果非覆盖生成
|
||||
if (!genConfig.getString("cover").equals("1") && FileUtil.exist(file)) {
|
||||
continue;
|
||||
}
|
||||
// 生成代码
|
||||
genFile(file, template, genMap);
|
||||
}
|
||||
return tempPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义后端文件路径以及名称
|
||||
*/
|
||||
private static String getAdminFilePath(String templateName, JSONObject genConfig, String className, String rootPath) {
|
||||
// projectPath: rootPath(项目绝对路径到项目名)+File.separator(\)+genConfig.getString("module_name")(前端输入的模块名)
|
||||
// eg: D:\code\work\nl-sso-server\nladmin-system\nlsso-server
|
||||
String projectPath = rootPath + File.separator + genConfig.getString("module_name");
|
||||
// packagePath: 包路径
|
||||
// eg:D:\code\work\nl-sso-server\nladmin-system\nlsso-server\src\main\java\输入的包名
|
||||
String packagePath = projectPath + File.separator + "src" + File.separator + "main" + File.separator + "java" + File.separator;
|
||||
if (!ObjectUtils.isEmpty(genConfig.getString("pack"))) { // 将点转成\
|
||||
packagePath += genConfig.getString("pack").replace(".", File.separator) + File.separator;
|
||||
private static String getAdminFilePath(String templateName, CodeGenConfig genConfig, String className, String rootPath) {
|
||||
String projectPath = rootPath + File.separator + "nlsso-server" + File.separator;
|
||||
String packagePath = projectPath + "src" + File.separator + "main"
|
||||
+ File.separator + "java" + File.separator + "org"
|
||||
+ File.separator + "nl" + File.separator + genConfig.getModuleName() + File.separator;
|
||||
String packageName = null;
|
||||
if (!ObjectUtils.isEmpty(genConfig.getPack())) {
|
||||
packageName = genConfig.getPack().replace(".", File.separator);
|
||||
}
|
||||
|
||||
if ("Entity".equals(templateName)) {
|
||||
return packagePath + "domain" + File.separator + className + ".java";
|
||||
return packagePath + "service" + File.separator + packageName + File.separator + "dao" + File.separator + className + ".java";
|
||||
}
|
||||
|
||||
if ("Controller".equals(templateName)) {
|
||||
return packagePath + "rest" + File.separator + className + "Controller.java";
|
||||
return packagePath + "controller" + File.separator + packageName + File.separator + className + "Controller.java";
|
||||
}
|
||||
|
||||
if ("Service".equals(templateName)) {
|
||||
return packagePath + "service" + File.separator + className + "Service.java";
|
||||
return packagePath + "service" + File.separator + packageName + File.separator + "I" + className + "Service.java";
|
||||
}
|
||||
|
||||
if ("ServiceImpl".equals(templateName)) {
|
||||
return packagePath + "service" + File.separator + "impl" + File.separator + className + "ServiceImpl.java";
|
||||
return packagePath + "service" + File.separator + packageName + File.separator + "impl" + File.separator + className + "ServiceImpl.java";
|
||||
}
|
||||
|
||||
if ("Dto".equals(templateName)) {
|
||||
return packagePath + "service" + File.separator + "dto" + File.separator + className + "Dto.java";
|
||||
return packagePath + "service" + File.separator + packageName + File.separator + "dto" + File.separator + className + "Dto.java";
|
||||
}
|
||||
|
||||
if ("QueryCriteria".equals(templateName)) {
|
||||
return packagePath + "service" + File.separator + "dto" + File.separator + className + "QueryCriteria.java";
|
||||
return packagePath + "service" + File.separator + packageName + File.separator + "dto" + File.separator + className + "Query.java";
|
||||
}
|
||||
|
||||
if ("Mapper".equals(templateName)) {
|
||||
return packagePath + "service" + File.separator + "mapstruct" + File.separator + className + "Mapper.java";
|
||||
return packagePath + "service" + File.separator + packageName + File.separator + "dao" + File.separator + "mapper" + File.separator + className + "Mapper.java";
|
||||
}
|
||||
|
||||
if ("Repository".equals(templateName)) {
|
||||
return packagePath + "repository" + File.separator + className + "Repository.java";
|
||||
if ("MySQLMapper".equals(templateName)) {
|
||||
return packagePath + "service" + File.separator + packageName + File.separator + "dao" + File.separator + "mapper" + File.separator + className + "Mapper.xml";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义前端文件路径以及名称
|
||||
*/
|
||||
private static String getFrontFilePath(String templateName, String apiPath, String path, String apiName) {
|
||||
|
||||
if ("api".equals(templateName)) {
|
||||
return apiPath + File.separator + apiName + ".js";
|
||||
return path + File.separator + apiName + ".js";
|
||||
}
|
||||
|
||||
if ("index".equals(templateName)) {
|
||||
@@ -235,34 +158,33 @@ public class GenUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// 获取模版数据
|
||||
private static JSONObject getGenMap(JSONArray columnInfos, JSONObject genConfig) {
|
||||
private static Map<String, Object> getGenMap(List<CodeColumnConfig> columnInfos, CodeGenConfig genConfig) {
|
||||
// 存储模版字段数据
|
||||
JSONObject genMap = new JSONObject(16);
|
||||
Map<String, Object> genMap = new HashMap<>(16);
|
||||
// 接口别名
|
||||
genMap.put("apiAlias", genConfig.getString("api_alias"));
|
||||
genMap.put("apiAlias", genConfig.getApiAlias());
|
||||
// 包名称
|
||||
genMap.put("package", genConfig.getString("pack"));
|
||||
genMap.put("package", genConfig.getPack());
|
||||
// 模块名称
|
||||
genMap.put("moduleName", genConfig.getString("module_name"));
|
||||
genMap.put("moduleName", genConfig.getModuleName());
|
||||
// 作者
|
||||
genMap.put("author", genConfig.getString("author"));
|
||||
genMap.put("author", genConfig.getAuthor());
|
||||
// 创建日期
|
||||
genMap.put("date", LocalDate.now().toString());
|
||||
// 表名
|
||||
genMap.put("tableName", genConfig.getString("table_name"));
|
||||
genMap.put("tableName", genConfig.getTableName());
|
||||
// 大写开头的类名
|
||||
String className = StringUtils.toCapitalizeCamelCase(genConfig.getString("table_name"));
|
||||
String className = StringUtils.toCapitalizeCamelCase(genConfig.getTableName());
|
||||
// 小写开头的类名
|
||||
String changeClassName = StringUtils.toCamelCase(genConfig.getString("table_name"));
|
||||
String changeClassName = StringUtils.toCamelCase(genConfig.getTableName());
|
||||
// 判断是否去除表前缀
|
||||
if (StrUtil.isNotEmpty(genConfig.getString("prefix"))) {
|
||||
className = StringUtils.toCapitalizeCamelCase(StrUtil.removePrefix(genConfig.getString("table_name"), genConfig.getString("prefix")));
|
||||
changeClassName = StringUtils.toCamelCase(StrUtil.removePrefix(genConfig.getString("table_name"), genConfig.getString("prefix")));
|
||||
if (StrUtil.isNotEmpty(genConfig.getPrefix())) {
|
||||
className = StringUtils.toCapitalizeCamelCase(StrUtil.removePrefix(genConfig.getTableName(), genConfig.getPrefix()));
|
||||
changeClassName = StringUtils.toCamelCase(StrUtil.removePrefix(genConfig.getTableName(), genConfig.getPrefix()));
|
||||
}
|
||||
// 保存类名
|
||||
genMap.put("className", className);
|
||||
genMap.put("className", className); // 驼峰命名
|
||||
// 保存小写开头的类名
|
||||
genMap.put("changeClassName", changeClassName);
|
||||
// 存在 Timestamp 字段
|
||||
@@ -275,20 +197,15 @@ public class GenUtil {
|
||||
genMap.put("queryHasBigDecimal", false);
|
||||
// 是否需要创建查询
|
||||
genMap.put("hasQuery", false);
|
||||
// 是否有主键
|
||||
genMap.put("hasPk", false);
|
||||
// 自增主键
|
||||
genMap.put("auto", false);
|
||||
// 存储主键类型(未标明主键)
|
||||
genMap.put("pkColumnType", "Long");
|
||||
// 存储小写开头的字段名(未标明主键)
|
||||
genMap.put("pkChangeColName", "id");
|
||||
// 存储大写开头的字段名(未标明主键)
|
||||
genMap.put("pkCapitalColName", "Id");
|
||||
genMap.put("hasDate", false);
|
||||
// 存在字典
|
||||
genMap.put("hasDict", false);
|
||||
// 存在日期注解
|
||||
genMap.put("hasDateAnnotation", false);
|
||||
// 日期包
|
||||
genMap.put("hasDate", false);
|
||||
// 保存字段信息
|
||||
List<Map<String, Object>> columns = new ArrayList<>();
|
||||
// 保存查询字段的信息
|
||||
@@ -300,21 +217,20 @@ public class GenUtil {
|
||||
// 存储不为空的字段信息
|
||||
List<Map<String, Object>> isNotNullColumns = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < columnInfos.size(); i++) {
|
||||
JSONObject column = columnInfos.getJSONObject(i);
|
||||
JSONObject listMap = new JSONObject(16);
|
||||
for (CodeColumnConfig column : columnInfos) { // 遍历所有字段
|
||||
Map<String, Object> listMap = new HashMap<>(16);
|
||||
// 字段描述
|
||||
listMap.put("remark", column.getString("remark"));
|
||||
listMap.put("remark", column.getRemark());
|
||||
// 字段类型
|
||||
listMap.put("columnKey", column.getString("key_type"));
|
||||
listMap.put("columnKey", column.getKeyType());
|
||||
// 主键类型
|
||||
String colType = ColUtil.cloToJava(column.getString("column_type"));
|
||||
// 小写开头的字段名
|
||||
//String changeColumnName = StringUtils.toCamelCase(column.getColumnName());
|
||||
String changeColumnName = column.getString("column_name");
|
||||
String colType = ColUtil.cloToJava(column.getColumnType());
|
||||
// 小写开头的字段名 - 转驼峰
|
||||
String changeColumnName = StringUtils.toCamelCase(column.getColumnName());
|
||||
// 大写开头的字段名
|
||||
String capitalColumnName = StringUtils.toCapitalizeCamelCase(column.getString("column_name"));
|
||||
if (PK.equals(column.getString("key_type"))) {
|
||||
String capitalColumnName = StringUtils.toCapitalizeCamelCase(column.getColumnName());
|
||||
if (PK.equals(column.getKeyType())) { // 如果是主键
|
||||
genMap.put("hasPk", true);
|
||||
// 存储主键类型
|
||||
genMap.put("pkColumnType", colType);
|
||||
// 存储小写开头的字段名
|
||||
@@ -326,55 +242,51 @@ public class GenUtil {
|
||||
if (TIMESTAMP.equals(colType)) {
|
||||
genMap.put("hasTimestamp", true);
|
||||
}
|
||||
// 是否存在 Timestamp 类型的字段
|
||||
if (Date.equals(colType)) {
|
||||
genMap.put("hasDate", true);
|
||||
}
|
||||
// 是否存在 BigDecimal 类型的字段
|
||||
if (BIGDECIMAL.equals(colType)) {
|
||||
genMap.put("hasBigDecimal", true);
|
||||
}
|
||||
// 主键是否自增
|
||||
if (EXTRA.equals(column.getString("extra"))) {
|
||||
if (EXTRA.equals(column.getExtra())) {
|
||||
genMap.put("auto", true);
|
||||
}
|
||||
// 主键存在字典
|
||||
if (StrUtil.isNotEmpty(column.getString("dict_name"))) {
|
||||
if (StrUtil.isNotEmpty(column.getDictName())) {
|
||||
genMap.put("hasDict", true);
|
||||
dicts.add(column.getString("dict_name"));
|
||||
dicts.add(column.getDictName());
|
||||
}
|
||||
|
||||
// 存储字段类型
|
||||
listMap.put("columnType", colType);
|
||||
// 存储字原始段名称
|
||||
listMap.put("columnName", column.getString("column_name"));
|
||||
listMap.put("columnName", column.getColumnName());
|
||||
// 不为空
|
||||
listMap.put("istNotNull", (column.getString("not_null").equals("1"))?true:false);
|
||||
listMap.put("istNotNull", column.getNotNull());
|
||||
// 字段列表显示
|
||||
listMap.put("columnShow", (column.getString("list_show").equals("1"))?true:false);
|
||||
listMap.put("columnShow", column.getListShow());
|
||||
// 表单显示
|
||||
listMap.put("formShow", (column.getString("form_show").equals("1"))?true:false);
|
||||
listMap.put("formShow", column.getFormShow());
|
||||
// 表单组件类型
|
||||
listMap.put("formType", StrUtil.isNotEmpty(column.getString("form_type")) ? column.getString("form_type") : "Input");
|
||||
// 小写开头的字段名称
|
||||
listMap.put("formType", StrUtil.isNotEmpty(column.getFormType()) ? column.getFormType() : "Input");
|
||||
// 小写开头的字段名称 驼峰转换
|
||||
listMap.put("changeColumnName", changeColumnName);
|
||||
//大写开头的字段名称
|
||||
//大写开头的字段名称 驼峰转换
|
||||
listMap.put("capitalColumnName", capitalColumnName);
|
||||
// 字典名称
|
||||
listMap.put("dictName", column.getString("dict_name"));
|
||||
listMap.put("dictName", column.getDictName());
|
||||
// 日期注解
|
||||
listMap.put("dateAnnotation", column.getString("date_annotation"));
|
||||
if (StrUtil.isNotEmpty(column.getString("date_annotation"))) {
|
||||
listMap.put("dateAnnotation", column.getDateAnnotation());
|
||||
if (StrUtil.isNotEmpty(column.getDateAnnotation())) {
|
||||
genMap.put("hasDateAnnotation", true);
|
||||
}
|
||||
// 添加非空字段信息
|
||||
if (column.getString("not_null").equals("1")) {
|
||||
if (column.getNotNull()) {
|
||||
isNotNullColumns.add(listMap);
|
||||
}
|
||||
// 判断是否有查询,如有则把查询的字段set进columnQuery
|
||||
if (!StrUtil.isEmpty(column.getString("query_type"))) {
|
||||
if (!StrUtil.isEmpty(column.getQueryType())) {
|
||||
// 查询类型
|
||||
listMap.put("queryType", column.getString("query_type"));
|
||||
listMap.put("queryType", column.getQueryType());
|
||||
// 是否存在查询
|
||||
genMap.put("hasQuery", true);
|
||||
if (TIMESTAMP.equals(colType)) {
|
||||
@@ -385,7 +297,7 @@ public class GenUtil {
|
||||
// 查询中存储 BigDecimal 类型
|
||||
genMap.put("queryHasBigDecimal", true);
|
||||
}
|
||||
if ("between".equalsIgnoreCase(column.getString("query_type"))) {
|
||||
if ("between".equalsIgnoreCase(column.getQueryType())) {
|
||||
betweens.add(listMap);
|
||||
} else {
|
||||
// 添加到查询列表中
|
||||
@@ -408,7 +320,60 @@ public class GenUtil {
|
||||
return genMap;
|
||||
}
|
||||
|
||||
// 生成文件
|
||||
/**
|
||||
* 打包下载
|
||||
* @param columns
|
||||
* @param genConfig
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String download(List<CodeColumnConfig> columns, CodeGenConfig genConfig) throws IOException {
|
||||
// 拼接的路径:/tmpnladmin-gen-temp/,这个路径在Linux下需要root用户才有权限创建,非root用户会权限错误而失败,更改为: /tmp/nladmin-gen-temp/
|
||||
// String tempPath =SYS_TEM_DIR + "nladmin-gen-temp" + File.separator + genConfig.getTableName() + File.separator;
|
||||
String tempPath = SYS_TEM_DIR + "nladmin-gen-temp" + File.separator + genConfig.getTableName() + File.separator;
|
||||
Map<String, Object> genMap = getGenMap(columns, genConfig);
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||
// 生成后端代码
|
||||
List<String> templates = getAdminTemplateNames();
|
||||
for (String templateName : templates) {
|
||||
Template template = engine.getTemplate("generator/admin/" + templateName + ".ftl");
|
||||
String filePath = getAdminFilePath(templateName, genConfig, genMap.get("className").toString(), tempPath + "eladmin" + File.separator);
|
||||
assert filePath != null;
|
||||
File file = new File(filePath);
|
||||
// 如果非覆盖生成
|
||||
if (!genConfig.getCover() && FileUtil.exist(file)) {
|
||||
continue;
|
||||
}
|
||||
// 生成代码
|
||||
genFile(file, template, genMap);
|
||||
}
|
||||
// 生成前端代码
|
||||
templates = getFrontTemplateNames();
|
||||
for (String templateName : templates) {
|
||||
Template template = engine.getTemplate("generator/front/" + templateName + ".ftl");
|
||||
String path = tempPath + "nladmin-web" + File.separator;
|
||||
String apiPath = path + "src" + File.separator + "api" + File.separator;
|
||||
String srcPath = path + "src" + File.separator + "views" + File.separator + genMap.get("changeClassName").toString() + File.separator;
|
||||
String filePath = getFrontFilePath(templateName, apiPath, srcPath, genMap.get("changeClassName").toString());
|
||||
assert filePath != null;
|
||||
File file = new File(filePath);
|
||||
// 如果非覆盖生成
|
||||
if (!genConfig.getCover() && FileUtil.exist(file)) {
|
||||
continue;
|
||||
}
|
||||
// 生成代码
|
||||
genFile(file, template, genMap);
|
||||
}
|
||||
return tempPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成文件
|
||||
* @param file
|
||||
* @param template
|
||||
* @param map
|
||||
* @throws IOException
|
||||
*/
|
||||
private static void genFile(File file, Template template, Map<String, Object> map) throws IOException {
|
||||
// 生成目标文件
|
||||
Writer writer = null;
|
||||
@@ -423,4 +388,48 @@ public class GenUtil {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成代码
|
||||
* @param columnInfos
|
||||
* @param genConfig
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void generatorCode(List<CodeColumnConfig> columnInfos, CodeGenConfig genConfig) throws IOException {
|
||||
Map<String, Object> genMap = getGenMap(columnInfos, genConfig);
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||
// 生成后端代码
|
||||
List<String> templates = getAdminTemplateNames();
|
||||
for (String templateName : templates) {
|
||||
Template template = engine.getTemplate("generator/admin/" + templateName + ".ftl");
|
||||
String filePath = getAdminFilePath(templateName, genConfig, genMap.get("className").toString(), System.getProperty("user.dir"));
|
||||
|
||||
assert filePath != null;
|
||||
File file = new File(filePath);
|
||||
|
||||
// 如果非覆盖生成
|
||||
if (!genConfig.getCover() && FileUtil.exist(file)) {
|
||||
continue;
|
||||
}
|
||||
// 生成代码
|
||||
genFile(file, template, genMap);
|
||||
}
|
||||
|
||||
// 生成前端代码
|
||||
templates = getFrontTemplateNames();
|
||||
for (String templateName : templates) {
|
||||
Template template = engine.getTemplate("generator/front/" + templateName + ".ftl");
|
||||
String filePath = getFrontFilePath(templateName, genConfig.getApiPath(), genConfig.getPath(), genMap.get("changeClassName").toString());
|
||||
|
||||
assert filePath != null;
|
||||
File file = new File(filePath);
|
||||
|
||||
// 如果非覆盖生成
|
||||
if (!genConfig.getCover() && FileUtil.exist(file)) {
|
||||
continue;
|
||||
}
|
||||
// 生成代码
|
||||
genFile(file, template, genMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,15 +21,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.PageUtil;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.modules.system.domain.Dept;
|
||||
import org.nl.modules.system.domain.vo.DeptVo;
|
||||
import org.nl.modules.system.util.CopyUtil;
|
||||
import org.nl.system.service.dept.ISysDeptService;
|
||||
import org.nl.system.service.dept.dao.SysDept;
|
||||
import org.nl.system.service.dept.dto.DeptQuery;
|
||||
|
||||
@@ -10,8 +10,6 @@ import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.system.service.dict.ISysDictService;
|
||||
import org.nl.system.service.dict.dao.Dict;
|
||||
import org.nl.system.service.dict.dto.DictQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -45,6 +43,13 @@ public class SysDictController {
|
||||
return new ResponseEntity<>(TableDataInfo.build(dictService.queryAll(whereJson,pageable)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询所有字典信息")
|
||||
@GetMapping(value = "/all")
|
||||
// @SaCheckPermission("dict:list")
|
||||
public ResponseEntity<Object> queryAll(){
|
||||
return new ResponseEntity<>(dictService.queryAll(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增字典")
|
||||
@PostMapping
|
||||
@ApiOperation("新增字典")
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.nl.system.controller.generator;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.system.service.generator.ICodeGenConfigService;
|
||||
import org.nl.system.service.generator.dao.CodeGenConfig;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成配置表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author lyd
|
||||
* @since 2023-05-03
|
||||
*/
|
||||
@SaIgnore
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "系统:代码生成管理")
|
||||
@RequestMapping("api/genConfig")
|
||||
public class CodeGenConfigController {
|
||||
private final ICodeGenConfigService genConfigService;
|
||||
|
||||
@ApiOperation("查询表数据")
|
||||
@GetMapping(value = "/{tableName}")
|
||||
public ResponseEntity<Object> query(@PathVariable String tableName){
|
||||
return new ResponseEntity<>(genConfigService.findByTableName(tableName), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("修改")
|
||||
@PutMapping
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody CodeGenConfig genConfig){
|
||||
return new ResponseEntity<>(genConfigService.update(genConfig.getTableName(), genConfig),HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package org.nl.modules.common.generator.rest;
|
||||
package org.nl.system.controller.generator;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.generator.domain.ColumnInfo;
|
||||
import org.nl.modules.common.generator.service.GenConfigService;
|
||||
import org.nl.modules.common.generator.service.GeneratorService;
|
||||
import org.nl.modules.common.utils.PageUtil;
|
||||
import org.nl.modules.system.service.dto.UserQueryCriteria;
|
||||
import org.nl.system.service.generator.ICodeGenConfigService;
|
||||
import org.nl.system.service.generator.ICodeGeneratorService;
|
||||
import org.nl.system.service.generator.dao.CodeColumnConfig;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -21,44 +21,41 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: lyd
|
||||
* @description: 代码生成管理
|
||||
* @Date: 2022/12/2
|
||||
* <p>
|
||||
* 列的数据信息表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author lyd
|
||||
* @since 2023-05-03
|
||||
*/
|
||||
@SaIgnore
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/generator")
|
||||
@Api(tags = "系统:代码生成管理")
|
||||
public class GeneratorController {
|
||||
private final GeneratorService generatorService;
|
||||
private final GenConfigService genConfigService;
|
||||
public class CodeGeneratorController {
|
||||
private final ICodeGeneratorService generatorService;
|
||||
private final ICodeGenConfigService genConfigService;
|
||||
|
||||
@Value("${generator.enabled}")
|
||||
private Boolean generatorEnabled;
|
||||
|
||||
@ApiOperation("查询数据库数据")
|
||||
@GetMapping(value = "/tables/all")
|
||||
public ResponseEntity<Object> queryTables(){
|
||||
return new ResponseEntity<>(generatorService.getTables(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询数据库数据")
|
||||
@GetMapping(value = "/tables")
|
||||
public ResponseEntity<Object> queryTables(@RequestParam(defaultValue = "") String name,
|
||||
Pageable pageable){
|
||||
return new ResponseEntity<>(generatorService.getTables(name,pageable), HttpStatus.OK);
|
||||
public ResponseEntity<Object> queryTables(@RequestParam(defaultValue = "") String name, PageQuery pageable){
|
||||
return new ResponseEntity<>(TableDataInfo.build(generatorService.getTables(name, pageable)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询字段数据")
|
||||
@GetMapping(value = "/columns")
|
||||
public ResponseEntity<Object> queryColumns(@RequestParam String tableName){
|
||||
return new ResponseEntity<>(generatorService.getColumns(tableName), HttpStatus.OK);
|
||||
return new ResponseEntity<>(TableDataInfo.build(generatorService.getColumns(tableName)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("保存字段数据")
|
||||
@ApiOperation("批量修改字段数据")
|
||||
@PutMapping
|
||||
public ResponseEntity<HttpStatus> save(@RequestBody JSONArray columnInfos){
|
||||
generatorService.save(columnInfos);
|
||||
public ResponseEntity<HttpStatus> save(@RequestBody List<CodeColumnConfig> columnInfos){
|
||||
generatorService.updateBatchById(columnInfos);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -79,16 +76,16 @@ public class GeneratorController {
|
||||
}
|
||||
switch (type){
|
||||
// 生成代码
|
||||
case 0: generatorService.generator(genConfigService.find(tableName), generatorService.getColumns(tableName));
|
||||
case 0: generatorService.generator(genConfigService.findByTableName(tableName), generatorService.getColumns(tableName));
|
||||
break;
|
||||
// 预览
|
||||
case 1: return generatorService.preview(genConfigService.find(tableName), generatorService.getColumns(tableName));
|
||||
// 下载
|
||||
case 2: generatorService.download(genConfigService.find(tableName), generatorService.getColumns(tableName), request, response);
|
||||
case 1: return generatorService.preview(genConfigService.findByTableName(tableName), generatorService.getColumns(tableName));
|
||||
// 打包
|
||||
case 2: generatorService.download(genConfigService.findByTableName(tableName), generatorService.getColumns(tableName), request, response);
|
||||
break;
|
||||
default: throw new BadRequestException("没有这个选项");
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.nl.system.service.generator;
|
||||
|
||||
import org.nl.system.service.generator.dao.CodeGenConfig;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成配置表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author lyd
|
||||
* @since 2023-05-03
|
||||
*/
|
||||
public interface ICodeGenConfigService extends IService<CodeGenConfig> {
|
||||
|
||||
/**
|
||||
* 根据表名查找
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
CodeGenConfig findByTableName(String tableName);
|
||||
|
||||
/**
|
||||
* 根据表名更新
|
||||
* @param tableName
|
||||
* @param genConfig
|
||||
* @return
|
||||
*/
|
||||
CodeGenConfig update(String tableName, CodeGenConfig genConfig);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package org.nl.system.service.generator;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.system.service.generator.dao.CodeColumnConfig;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.system.service.generator.dao.CodeGenConfig;
|
||||
import org.nl.system.service.generator.dto.TablesInfo;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 列的数据信息表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author lyd
|
||||
* @since 2023-05-03
|
||||
*/
|
||||
public interface ICodeGeneratorService extends IService<CodeColumnConfig> {
|
||||
|
||||
/**
|
||||
* 获得所有的表格信息
|
||||
* @return
|
||||
*/
|
||||
IPage<TablesInfo> getTables(String name, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 得到数据表的元数据
|
||||
* @param tableName 表名
|
||||
* @return /
|
||||
*/
|
||||
IPage<CodeColumnConfig> getColumns(String tableName);
|
||||
|
||||
/**
|
||||
* 根据表名查询表字段
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
List<CodeColumnConfig> query(String tableName);
|
||||
|
||||
/**
|
||||
* 同步表数据
|
||||
* @param columnInfos /
|
||||
* @param columnInfoList /
|
||||
*/
|
||||
@Async
|
||||
void sync(IPage<CodeColumnConfig> columnInfos, List<CodeColumnConfig> columnInfoList);
|
||||
|
||||
ResponseEntity<Object> preview(CodeGenConfig byTableName, IPage<CodeColumnConfig> columns);
|
||||
|
||||
/**
|
||||
* 打包下载
|
||||
* @param genConfig 配置信息
|
||||
* @param columnsPage 字段信息分页数据
|
||||
* @param request /
|
||||
* @param response /
|
||||
*/
|
||||
void download(CodeGenConfig genConfig, IPage<CodeColumnConfig> columnsPage, HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 代码生成
|
||||
* @param genConfig 配置信息
|
||||
* @param columnsPage 字段信息分页数据
|
||||
*/
|
||||
void generator(CodeGenConfig genConfig, IPage<CodeColumnConfig> columnsPage);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.nl.system.service.generator.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 列的数据信息表
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2023-05-03
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("code_column_config")
|
||||
public class CodeColumnConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 标识
|
||||
*/
|
||||
@TableId(value = "column_id", type = IdType.ASSIGN_ID)
|
||||
private String columnId;
|
||||
|
||||
@ApiModelProperty(value = "表名")
|
||||
private String tableName;
|
||||
|
||||
@ApiModelProperty(value = "数据库字段名称")
|
||||
private String columnName;
|
||||
|
||||
@ApiModelProperty(value = "数据库字段类型")
|
||||
private String columnType;
|
||||
|
||||
@ApiModelProperty(value = "数据库字段键类型")
|
||||
private String keyType;
|
||||
|
||||
@ApiModelProperty(value = "字段额外的参数")
|
||||
private String extra;
|
||||
|
||||
@ApiModelProperty(value = "数据库字段描述")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "是否必填")
|
||||
private Boolean notNull;
|
||||
|
||||
@ApiModelProperty(value = "是否在列表显示")
|
||||
private Boolean listShow;
|
||||
|
||||
@ApiModelProperty(value = "是否表单显示")
|
||||
private Boolean formShow;
|
||||
|
||||
@ApiModelProperty(value = "表单类型")
|
||||
private String formType;
|
||||
|
||||
@ApiModelProperty(value = "查询 1:模糊 2:精确")
|
||||
private String queryType;
|
||||
|
||||
@ApiModelProperty(value = "字典名称")
|
||||
private String dictName;
|
||||
|
||||
@ApiModelProperty(value = "日期注解")
|
||||
private String dateAnnotation;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package org.nl.system.service.generator.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成配置表
|
||||
* </p>
|
||||
*
|
||||
* @author lyd
|
||||
* @since 2023-05-03
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("code_gen_config")
|
||||
public class CodeGenConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CodeGenConfig(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId(value = "config_id")
|
||||
private String configId;
|
||||
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 作者
|
||||
*/
|
||||
private String author;
|
||||
|
||||
/**
|
||||
* 是否覆盖
|
||||
*/
|
||||
private Boolean cover;
|
||||
|
||||
/**
|
||||
* 模块名称
|
||||
*/
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 包名
|
||||
*/
|
||||
private String pack;
|
||||
|
||||
/**
|
||||
* 路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* api路径
|
||||
*/
|
||||
private String apiPath;
|
||||
|
||||
/**
|
||||
* 表前缀
|
||||
*/
|
||||
private String prefix;
|
||||
|
||||
/**
|
||||
* 接口名称
|
||||
*/
|
||||
private String apiAlias;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.nl.system.service.generator.dao.mapper;
|
||||
|
||||
import org.nl.system.service.generator.dao.CodeColumnConfig;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.nl.system.service.generator.dto.ColumnInfo;
|
||||
import org.nl.system.service.generator.dto.TablesInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 列的数据信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author lyd
|
||||
* @since 2023-05-03
|
||||
*/
|
||||
public interface CodeColumnConfigMapper extends BaseMapper<CodeColumnConfig> {
|
||||
|
||||
/**
|
||||
* 分页查找
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
List<TablesInfo> getTables(String name, int pageSize, int offset);
|
||||
|
||||
/**
|
||||
* 分页查询的总数
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
long getTablesTotal(String name);
|
||||
|
||||
List<ColumnInfo> getTablesByTableName(String tableName);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.system.service.generator.dao.mapper.CodeColumnConfigMapper">
|
||||
|
||||
<select id="getTables" resultType="org.nl.system.service.generator.dto.TablesInfo">
|
||||
SELECT
|
||||
table_name,
|
||||
create_time,
|
||||
engine,
|
||||
table_collation AS coding,
|
||||
table_comment AS remark
|
||||
FROM
|
||||
information_schema.tables
|
||||
WHERE
|
||||
table_schema = (SELECT database())
|
||||
<if test="name != null and name != ''">
|
||||
AND table_name LIKE #{name}
|
||||
</if>
|
||||
ORDER BY create_time DESC
|
||||
LIMIT #{pageSize} OFFSET #{offset}
|
||||
</select>
|
||||
<select id="getTablesTotal" resultType="java.lang.Long">
|
||||
SELECT count(*)
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = (select database())
|
||||
<if test="name != null and name != ''">
|
||||
AND table_name LIKE #{name}
|
||||
</if>
|
||||
</select>
|
||||
<select id="getTablesByTableName" resultType="org.nl.system.service.generator.dto.ColumnInfo">
|
||||
SELECT
|
||||
column_name as columnName,
|
||||
is_nullable as isNull,
|
||||
data_type as columnType,
|
||||
column_comment as remark,
|
||||
column_key as keyType,
|
||||
extra
|
||||
FROM information_schema.columns
|
||||
WHERE
|
||||
table_schema = (SELECT database())
|
||||
<if test="tableName != null and tableName != ''">
|
||||
AND table_name = #{tableName}
|
||||
</if>
|
||||
ORDER BY ordinal_position
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.nl.system.service.generator.dao.mapper;
|
||||
|
||||
import org.nl.system.service.generator.dao.CodeGenConfig;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成配置表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2023-05-03
|
||||
*/
|
||||
public interface CodeGenConfigMapper extends BaseMapper<CodeGenConfig> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.system.service.generator.dao.mapper.CodeGenConfigMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.nl.system.service.generator.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: 字段信息
|
||||
* @Date: 2023/5/3
|
||||
*/
|
||||
@Data
|
||||
public class ColumnInfo {
|
||||
@ApiModelProperty(value = "数据库字段名称")
|
||||
private String columnName;
|
||||
|
||||
@ApiModelProperty(value = "数据库字段类型")
|
||||
private String columnType;
|
||||
|
||||
@ApiModelProperty(value = "数据库字段键类型")
|
||||
private String keyType;
|
||||
|
||||
@ApiModelProperty(value = "字段额外的参数")
|
||||
private String extra;
|
||||
|
||||
@ApiModelProperty(value = "数据库字段描述")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "是否必填")
|
||||
private Boolean notNull;
|
||||
|
||||
@ApiModelProperty(value = "是否在列表显示")
|
||||
private Boolean listShow;
|
||||
|
||||
@ApiModelProperty(value = "是否表单显示")
|
||||
private Boolean formShow;
|
||||
|
||||
@ApiModelProperty(value = "表单类型")
|
||||
private String formType;
|
||||
|
||||
@ApiModelProperty(value = "查询 1:模糊 2:精确")
|
||||
private String queryType;
|
||||
|
||||
@ApiModelProperty(value = "字典名称")
|
||||
private String dictName;
|
||||
|
||||
@ApiModelProperty(value = "日期注解")
|
||||
private String dateAnnotation;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.nl.system.service.generator.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: 表的数据信息
|
||||
* @Date: 2023/5/3
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TablesInfo {
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 引擎
|
||||
*/
|
||||
private String ENGINE;
|
||||
|
||||
/**
|
||||
* 字符序
|
||||
*/
|
||||
private String coding;
|
||||
|
||||
/**
|
||||
* 注释
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package org.nl.system.service.generator.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.system.service.generator.dao.CodeGenConfig;
|
||||
import org.nl.system.service.generator.dao.mapper.CodeGenConfigMapper;
|
||||
import org.nl.system.service.generator.ICodeGenConfigService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成配置表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author lyd
|
||||
* @since 2023-05-03
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CodeGenConfigServiceImpl extends ServiceImpl<CodeGenConfigMapper, CodeGenConfig> implements ICodeGenConfigService {
|
||||
|
||||
private final CodeGenConfigMapper codeGenConfigMapper;
|
||||
|
||||
@Override
|
||||
public CodeGenConfig findByTableName(String tableName) {
|
||||
CodeGenConfig codeGenConfig = codeGenConfigMapper.selectOne(new LambdaQueryWrapper<CodeGenConfig>()
|
||||
.eq(CodeGenConfig::getTableName, tableName));
|
||||
if (ObjectUtil.isEmpty(codeGenConfig)) {
|
||||
return new CodeGenConfig(tableName);
|
||||
}
|
||||
return codeGenConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodeGenConfig update(String tableName, CodeGenConfig genConfig) {
|
||||
// 如果 api 路径为空,则自动生成路径
|
||||
if(StrUtil.isEmpty(genConfig.getApiPath())){
|
||||
String separator = File.separator;
|
||||
String[] paths;
|
||||
String symbol = "\\";
|
||||
if (symbol.equals(separator)) {
|
||||
paths = genConfig.getPath().split("\\\\");
|
||||
} else {
|
||||
paths = genConfig.getPath().split(File.separator);
|
||||
}
|
||||
StringBuilder api = new StringBuilder();
|
||||
for (String path : paths) {
|
||||
api.append(path);
|
||||
api.append(separator);
|
||||
if ("src".equals(path)) {
|
||||
api.append("api");
|
||||
break;
|
||||
}
|
||||
}
|
||||
genConfig.setApiPath(api.toString());
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(genConfig.getConfigId())) {
|
||||
codeGenConfigMapper.updateById(genConfig);
|
||||
} else {
|
||||
genConfig.setConfigId(IdUtil.getSnowflake(1,1).nextIdStr());
|
||||
codeGenConfigMapper.insert(genConfig);
|
||||
}
|
||||
return genConfig;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package org.nl.system.service.generator.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.FileUtil;
|
||||
import org.nl.modules.common.utils.GenUtil;
|
||||
import org.nl.system.service.generator.ICodeGeneratorService;
|
||||
import org.nl.system.service.generator.dao.CodeColumnConfig;
|
||||
import org.nl.system.service.generator.dao.CodeGenConfig;
|
||||
import org.nl.system.service.generator.dao.mapper.CodeColumnConfigMapper;
|
||||
import org.nl.system.service.generator.dto.ColumnInfo;
|
||||
import org.nl.system.service.generator.dto.TablesInfo;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 列的数据信息表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author lyd
|
||||
* @since 2023-05-03
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CodeGeneratorServiceImpl extends ServiceImpl<CodeColumnConfigMapper, CodeColumnConfig> implements ICodeGeneratorService {
|
||||
|
||||
private final CodeColumnConfigMapper columnConfigMapper;
|
||||
|
||||
@Override
|
||||
public IPage<TablesInfo> getTables(String name, PageQuery pageQuery) {
|
||||
IPage<TablesInfo> pages = new Page<>();
|
||||
int page = pageQuery.getPage();
|
||||
int pageSize = pageQuery.getSize();
|
||||
int offset = page * pageSize;
|
||||
List<TablesInfo> tableInfos = columnConfigMapper.getTables(name, pageSize, offset);
|
||||
long num = columnConfigMapper.getTablesTotal(name);
|
||||
pages.setRecords(tableInfos);
|
||||
pages.setCurrent(page + 1);
|
||||
pages.setSize(pageSize);
|
||||
pages.setTotal(num);
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<CodeColumnConfig> getColumns(String tableName) {
|
||||
IPage<CodeColumnConfig> pages = new Page<>();
|
||||
// 查找行列数据表
|
||||
List<CodeColumnConfig> codeColumnConfigs = columnConfigMapper
|
||||
.selectList(new LambdaQueryWrapper<CodeColumnConfig>()
|
||||
.eq(CodeColumnConfig::getTableName, tableName));
|
||||
if (ObjectUtil.isEmpty(codeColumnConfigs)) {
|
||||
// 为空查找全新的数据
|
||||
codeColumnConfigs = query(tableName);
|
||||
// 保存
|
||||
this.saveBatch(codeColumnConfigs);
|
||||
}
|
||||
pages.setRecords(codeColumnConfigs);
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CodeColumnConfig> query(String tableName) {
|
||||
List<ColumnInfo> columnConfigList = columnConfigMapper.getTablesByTableName(tableName);
|
||||
// 设置默认值
|
||||
List<CodeColumnConfig> columnInfos = columnConfigList.stream()
|
||||
.map(config -> CodeColumnConfig
|
||||
.builder()
|
||||
.columnId(IdUtil.getSnowflake(1,1).nextIdStr())
|
||||
.tableName(tableName)
|
||||
.columnName(config.getColumnName())
|
||||
.columnType(config.getColumnType())
|
||||
.keyType(config.getKeyType())
|
||||
.extra(config.getExtra())
|
||||
.notNull((ObjectUtil.isNotEmpty(config.getKeyType())
|
||||
&&ObjectUtil.isNotEmpty(config.getExtra())
|
||||
&&GenUtil.PK.equalsIgnoreCase(config.getKeyType())
|
||||
&&GenUtil.EXTRA.equalsIgnoreCase(config.getExtra()))
|
||||
?false:ObjectUtil.isNotEmpty(config.getNotNull())?config.getNotNull():false)
|
||||
.remark(ObjectUtil.isNotEmpty(config.getRemark())?config.getRemark():null)
|
||||
.listShow(true)
|
||||
.formShow(true)
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
return columnInfos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sync(IPage<CodeColumnConfig> columnInfos, List<CodeColumnConfig> columnInfoList) {
|
||||
List<CodeColumnConfig> records = columnInfos.getRecords();
|
||||
// 第一种情况,数据库类字段改变或者新增字段
|
||||
for (CodeColumnConfig columnInfo : columnInfoList) {
|
||||
// 根据字段名称查找
|
||||
List<CodeColumnConfig> columns = records.stream().filter(c -> c.getColumnName().equals(columnInfo.getColumnName())).collect(Collectors.toList());
|
||||
// 如果能找到,就修改部分可能被字段
|
||||
if (CollectionUtil.isNotEmpty(columns)) {
|
||||
CodeColumnConfig column = columns.get(0);
|
||||
column.setColumnType(columnInfo.getColumnType());
|
||||
column.setExtra(columnInfo.getExtra());
|
||||
column.setKeyType(columnInfo.getKeyType());
|
||||
if (StrUtil.isEmpty(column.getRemark())) {
|
||||
column.setRemark(columnInfo.getRemark());
|
||||
}
|
||||
columnConfigMapper.updateById(column);
|
||||
} else {
|
||||
// 如果找不到,则保存新字段信息
|
||||
columnConfigMapper.insert(columnInfo);
|
||||
}
|
||||
}
|
||||
// 第二种情况,数据库字段删除了
|
||||
for (CodeColumnConfig columnInfo : records) {
|
||||
// 根据字段名称查找
|
||||
List<CodeColumnConfig> columns = columnInfoList.stream().filter(c -> c.getColumnName().equals(columnInfo.getColumnName())).collect(Collectors.toList());
|
||||
// 如果找不到,就代表字段被删除了,则需要删除该字段
|
||||
if (CollectionUtil.isEmpty(columns)) {
|
||||
columnConfigMapper.deleteById(columnInfo.getColumnId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Object> preview(CodeGenConfig genConfig, IPage<CodeColumnConfig> columns) {
|
||||
List<CodeColumnConfig> columnsRecords = columns.getRecords();
|
||||
if (genConfig.getConfigId() == null) {
|
||||
throw new BadRequestException("请先配置生成器");
|
||||
}
|
||||
List<Map<String, Object>> genList = GenUtil.preview(columnsRecords, genConfig);
|
||||
return new ResponseEntity<>(genList, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(CodeGenConfig genConfig, IPage<CodeColumnConfig> columnsPage, HttpServletRequest request, HttpServletResponse response) {
|
||||
List<CodeColumnConfig> columns = columnsPage.getRecords();
|
||||
if (genConfig.getConfigId() == null) {
|
||||
throw new BadRequestException("请先配置生成器");
|
||||
}
|
||||
try {
|
||||
File file = new File(GenUtil.download(columns, genConfig));
|
||||
String zipPath = file.getPath() + ".zip";
|
||||
ZipUtil.zip(file.getPath(), zipPath);
|
||||
FileUtil.downloadFile(request, response, new File(zipPath), true);
|
||||
} catch (IOException e) {
|
||||
throw new BadRequestException("打包失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generator(CodeGenConfig genConfig, IPage<CodeColumnConfig> columnsPage) {
|
||||
List<CodeColumnConfig> columns = columnsPage.getRecords();
|
||||
if (genConfig.getConfigId() == null) {
|
||||
throw new BadRequestException("请先配置生成器");
|
||||
}
|
||||
try {
|
||||
GenUtil.generatorCode(columns, genConfig);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new BadRequestException("生成失败,请手动处理已生成的文件");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.nl.wms.controller.basedata;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.wms.service.basedata.IWorkshopService;
|
||||
import org.nl.wms.service.basedata.dao.Workshop;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
/**
|
||||
* @author lyd
|
||||
* @date 2023-05-04
|
||||
**/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "车间基础信息管理")
|
||||
@RequestMapping("/api/workshop")
|
||||
public class WorkshopController {
|
||||
|
||||
private final IWorkshopService workshopService;
|
||||
|
||||
@GetMapping
|
||||
@Log("查询车间基础信息")
|
||||
@ApiOperation("查询车间基础信息")
|
||||
//@SaCheckPermission("@el.check('workshop:list')")
|
||||
public ResponseEntity<Object> query(Map whereJson, PageQuery page){
|
||||
return new ResponseEntity<>(TableDataInfo.build(workshopService.queryAll(whereJson,page)),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增车间基础信息")
|
||||
@ApiOperation("新增车间基础信息")
|
||||
//@SaCheckPermission("@el.check('workshop:add')")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody Workshop entity){
|
||||
workshopService.create(entity);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改车间基础信息")
|
||||
@ApiOperation("修改车间基础信息")
|
||||
//@SaCheckPermission("@el.check('workshop:edit')")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody Workshop entity){
|
||||
workshopService.update(entity);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除车间基础信息")
|
||||
@ApiOperation("删除车间基础信息")
|
||||
//@SaCheckPermission("@el.check('workshop:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<String> ids) {
|
||||
workshopService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.nl.wms.service.basedata;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.wms.service.basedata.dao.Workshop;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @description 服务接口
|
||||
* @author lyd
|
||||
* @date 2023-05-04
|
||||
**/
|
||||
public interface IWorkshopService extends IService<Workshop> {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param whereJson 条件
|
||||
* @param pageable 分页参数
|
||||
* @return IPage<Workshop>
|
||||
*/
|
||||
IPage<Workshop> queryAll(Map whereJson, PageQuery pageable);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param entity /
|
||||
*/
|
||||
void create(Workshop entity);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param entity /
|
||||
*/
|
||||
void update(Workshop entity);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(Set<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.nl.wms.service.basedata.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @description /
|
||||
* @author lyd
|
||||
* @date 2023-05-04
|
||||
**/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name="md_base_workshop")
|
||||
public class Workshop implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "workshop_code", type = IdType.NONE)
|
||||
@ApiModelProperty(value = "车间编码")
|
||||
private String workshopCode;
|
||||
|
||||
@ApiModelProperty(value = "车间名称 ")
|
||||
private String workshopName;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "是否启用")
|
||||
private String isUsed;
|
||||
|
||||
@ApiModelProperty(value = "是否删除")
|
||||
private String isDelete;
|
||||
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private String createId;
|
||||
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private String createName;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private String createTime;
|
||||
|
||||
@ApiModelProperty(value = "修改人")
|
||||
private String updateId;
|
||||
|
||||
@ApiModelProperty(value = "修改人")
|
||||
private String updateName;
|
||||
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
private String updateTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.nl.wms.service.basedata.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.nl.wms.service.basedata.dao.Workshop;
|
||||
|
||||
/**
|
||||
* @author lyd
|
||||
* @date 2023-05-04
|
||||
**/
|
||||
public interface WorkshopMapper extends BaseMapper<Workshop> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.wms.service.basedata.dao.mapper.WorkshopMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.nl.wms.service.basedata.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @description /
|
||||
* @author lyd
|
||||
* @date 2023-05-04
|
||||
**/
|
||||
@Data
|
||||
public class WorkshopDto implements Serializable {
|
||||
|
||||
/** 车间编码 */
|
||||
private String workshopCode;
|
||||
|
||||
/** 车间名称 */
|
||||
private String workshopName;
|
||||
|
||||
/** 备注 */
|
||||
private String remark;
|
||||
|
||||
/** 是否启用 */
|
||||
private String isUsed;
|
||||
|
||||
/** 是否删除 */
|
||||
private String isDelete;
|
||||
|
||||
/** 创建人 */
|
||||
private Long createId;
|
||||
|
||||
/** 创建人 */
|
||||
private String createName;
|
||||
|
||||
/** 创建时间 */
|
||||
private String createTime;
|
||||
|
||||
/** 修改人 */
|
||||
private Long updateId;
|
||||
|
||||
/** 修改人 */
|
||||
private String updateName;
|
||||
|
||||
/** 修改时间 */
|
||||
private String updateTime;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.nl.wms.service.basedata.dto;
|
||||
|
||||
import org.nl.common.domain.query.BaseQuery;
|
||||
import org.nl.wms.service.basedata.dao.Workshop;
|
||||
|
||||
/**
|
||||
* @author lyd
|
||||
* @date 2023-05-04
|
||||
**/
|
||||
public class WorkshopQuery extends BaseQuery<Workshop> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package org.nl.wms.service.basedata.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.wms.service.basedata.IWorkshopService;
|
||||
import org.nl.wms.service.basedata.dao.Workshop;
|
||||
import org.nl.wms.service.basedata.dao.mapper.WorkshopMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* @description 服务实现
|
||||
* @author lyd
|
||||
* @date 2023-05-04
|
||||
**/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class WorkshopServiceImpl extends ServiceImpl< WorkshopMapper, Workshop> implements IWorkshopService {
|
||||
|
||||
private final WorkshopMapper workshopMapper;
|
||||
|
||||
@Override
|
||||
public IPage<Workshop> queryAll(Map whereJson, PageQuery page){
|
||||
LambdaQueryWrapper<Workshop> lam = new LambdaQueryWrapper<>();
|
||||
IPage<Workshop> pages = new Page<>(page.getPage() + 1, page.getSize());
|
||||
workshopMapper.selectPage(pages, lam);
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(Workshop entity) {
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
|
||||
entity.setWorkshopCode(IdUtil.getSnowflake(1, 1).nextIdStr());
|
||||
entity.setCreateId(currentUserId);
|
||||
entity.setCreateName(nickName);
|
||||
entity.setCreateTime(now);
|
||||
entity.setUpdateId(currentUserId);
|
||||
entity.setUpdateName(nickName);
|
||||
entity.setUpdateTime(now);
|
||||
workshopMapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(Workshop entity) {
|
||||
Workshop dto = workshopMapper.selectById(entity.getWorkshopCode());
|
||||
if (dto == null) throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
entity.setUpdateId(currentUserId);
|
||||
entity.setUpdateName(nickName);
|
||||
entity.setUpdateTime(now);
|
||||
|
||||
workshopMapper.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAll(Set<String> ids) {
|
||||
// 真删除
|
||||
workshopMapper.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +1,48 @@
|
||||
package org.nl.${moduleName}.controller.${package};
|
||||
|
||||
package ${package}.rest;
|
||||
|
||||
import ${package}.service.${className}Service;
|
||||
import ${package}.service.dto.${className}Dto;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.${moduleName}.service.${package}.I${className}Service;
|
||||
import org.nl.${moduleName}.service.${package}.dao.${className};
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
/**
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "${apiAlias}管理")
|
||||
@RequestMapping("/api/${changeClassName}")
|
||||
@Slf4j
|
||||
public class ${className}Controller {
|
||||
|
||||
private final ${className}Service ${changeClassName}Service;
|
||||
private final I${className}Service ${changeClassName}Service;
|
||||
|
||||
@GetMapping
|
||||
@Log("查询${apiAlias}")
|
||||
@ApiOperation("查询${apiAlias}")
|
||||
//@SaCheckPermission("@el.check('${changeClassName}:list')")
|
||||
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page){
|
||||
return new ResponseEntity<>(${changeClassName}Service.queryAll(whereJson,page),HttpStatus.OK);
|
||||
public ResponseEntity<Object> query(Map whereJson, PageQuery page){
|
||||
return new ResponseEntity<>(TableDataInfo.build(${changeClassName}Service.queryAll(whereJson,page)),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增${apiAlias}")
|
||||
@ApiOperation("新增${apiAlias}")
|
||||
//@SaCheckPermission("@el.check('${changeClassName}:add')")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody ${className}Dto dto){
|
||||
${changeClassName}Service.create(dto);
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody ${className} entity){
|
||||
${changeClassName}Service.create(entity);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@@ -49,8 +50,8 @@ public class ${className}Controller {
|
||||
@Log("修改${apiAlias}")
|
||||
@ApiOperation("修改${apiAlias}")
|
||||
//@SaCheckPermission("@el.check('${changeClassName}:edit')")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody ${className}Dto dto){
|
||||
${changeClassName}Service.update(dto);
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody ${className} entity){
|
||||
${changeClassName}Service.update(entity);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@@ -58,7 +59,7 @@ public class ${className}Controller {
|
||||
@ApiOperation("删除${apiAlias}")
|
||||
//@SaCheckPermission("@el.check('${changeClassName}:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<String> ids) {
|
||||
${changeClassName}Service.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
package ${package}.service.dto;
|
||||
package org.nl.${moduleName}.service.${package}.dto;
|
||||
|
||||
import lombok.Data;
|
||||
<#if hasTimestamp>
|
||||
import java.sql.Timestamp;
|
||||
</#if>
|
||||
<#if hasDate>
|
||||
import java.util.Date;
|
||||
</#if>
|
||||
<#if hasBigDecimal>
|
||||
import java.math.BigDecimal;
|
||||
</#if>
|
||||
import java.io.Serializable;
|
||||
<#if !auto && pkColumnType = 'Long'>
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
</#if>
|
||||
|
||||
/**
|
||||
* @description /
|
||||
|
||||
@@ -1,24 +1,15 @@
|
||||
package ${package}.domain;
|
||||
package org.nl.${moduleName}.service.${package}.dao;
|
||||
|
||||
import lombok.Data;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
<#if hasPk>
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
</#if>
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import javax.persistence.*;
|
||||
<#if isNotNullColumns??>
|
||||
import javax.validation.constraints.*;
|
||||
</#if>
|
||||
<#if hasDateAnnotation>
|
||||
import javax.persistence.Entity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.persistence.Table;
|
||||
import org.hibernate.annotations.*;
|
||||
</#if>
|
||||
<#if hasDate>
|
||||
import java.util.Date;
|
||||
</#if>
|
||||
<#if hasBigDecimal>
|
||||
import java.math.BigDecimal;
|
||||
</#if>
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -26,33 +17,17 @@ import java.io.Serializable;
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="${tableName}")
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("${tableName}")
|
||||
public class ${className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
|
||||
<#if column.columnKey = 'PRI'>
|
||||
@Id
|
||||
<#if auto>
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
</#if>
|
||||
</#if>
|
||||
@Column(name = "${column.columnName}"<#if column.columnKey = 'UNI'>,unique = true</#if><#if column.istNotNull && column.columnKey != 'PRI'>,nullable = false</#if>)
|
||||
<#if column.istNotNull && column.columnKey != 'PRI'>
|
||||
<#if column.columnType = 'String'>
|
||||
@NotBlank
|
||||
<#else>
|
||||
@NotNull
|
||||
</#if>
|
||||
</#if>
|
||||
<#if (column.dateAnnotation)?? && column.dateAnnotation != ''>
|
||||
<#if column.dateAnnotation = 'CreationDate'>
|
||||
|
||||
<#else>
|
||||
@UpdateDate
|
||||
</#if>
|
||||
@TableId(value = "${column.columnName}", type = <#if auto>IdType.AUTO<#else>IdType.NONE</#if>)
|
||||
</#if>
|
||||
<#if column.remark != ''>
|
||||
@ApiModelProperty(value = "${column.remark}")
|
||||
@@ -60,10 +35,7 @@ public class ${className} implements Serializable {
|
||||
@ApiModelProperty(value = "${column.changeColumnName}")
|
||||
</#if>
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
public void copy(${className} source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
package ${package}.service.mapstruct;
|
||||
package org.nl.${moduleName}.service.${package}.dao.mapper;
|
||||
|
||||
import BaseMapper;
|
||||
import ${package}.domain.${className};
|
||||
import ${package}.service.dto.${className}Dto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.nl.${moduleName}.service.${package}.dao.${className};
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface ${className}Mapper extends BaseMapper<${className}Dto, ${className}> {
|
||||
public interface ${className}Mapper extends BaseMapper<${className}> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.${moduleName}.service.${package}.dao.mapper.${className}Mapper">
|
||||
|
||||
</mapper>
|
||||
@@ -1,66 +1,12 @@
|
||||
package org.nl.${moduleName}.service.${package}.dto;
|
||||
|
||||
package ${package}.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
<#if queryHasDate>
|
||||
import java.util.Date;
|
||||
</#if>
|
||||
<#if queryHasBigDecimal>
|
||||
import java.math.BigDecimal;
|
||||
</#if>
|
||||
<#if betweens??>
|
||||
import java.util.List;
|
||||
</#if>
|
||||
<#if queryColumns??>
|
||||
import Query;
|
||||
</#if>
|
||||
import org.nl.common.domain.query.BaseQuery;
|
||||
import org.nl.${moduleName}.service.${package}.dao.${className};
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
@Data
|
||||
public class ${className}QueryCriteria{
|
||||
<#if queryColumns??>
|
||||
<#list queryColumns as column>
|
||||
public class ${className}Query extends BaseQuery<${className}> {
|
||||
|
||||
<#if column.queryType = '='>
|
||||
/** 精确 */
|
||||
@Query
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
<#if column.queryType = 'Like'>
|
||||
/** 模糊 */
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
<#if column.queryType = '!='>
|
||||
/** 不等于 */
|
||||
@Query(type = Query.Type.NOT_EQUAL)
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
<#if column.queryType = 'NotNull'>
|
||||
/** 不为空 */
|
||||
@Query(type = Query.Type.NOT_NULL)
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
<#if column.queryType = '>='>
|
||||
/** 大于等于 */
|
||||
@Query(type = Query.Type.GREATER_THAN)
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
<#if column.queryType = '<='>
|
||||
/** 小于等于 */
|
||||
@Query(type = Query.Type.LESS_THAN)
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
<#if betweens??>
|
||||
<#list betweens as column>
|
||||
/** BETWEEN */
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<${column.columnType}> ${column.changeColumnName};
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
||||
|
||||
@@ -1,64 +1,43 @@
|
||||
package ${package}.service;
|
||||
package org.nl.${moduleName}.service.${package};
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.${moduleName}.service.${package}.dao.${className};
|
||||
|
||||
import ${package}.service.dto.${className}Dto;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @description 服务接口
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
public interface ${className}Service {
|
||||
public interface I${className}Service extends IService<${className}> {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param whereJson 条件
|
||||
* @param page 分页参数
|
||||
* @return Map<String,Object>
|
||||
* @param pageable 分页参数
|
||||
* @return IPage<${className}>
|
||||
*/
|
||||
Map<String,Object> queryAll(Map whereJson, Pageable page);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param whereJson 条件参数
|
||||
* @return List<${className}Dto>
|
||||
*/
|
||||
List<${className}Dto> queryAll(Map whereJson);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param ${pkChangeColName} ID
|
||||
* @return ${className}
|
||||
*/
|
||||
${className}Dto findById(${pkColumnType} ${pkChangeColName});
|
||||
|
||||
/**
|
||||
* 根据编码查询
|
||||
* @param code code
|
||||
* @return ${className}
|
||||
*/
|
||||
${className}Dto findByCode(String code);
|
||||
|
||||
IPage<${className}> queryAll(Map whereJson, PageQuery pageable);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param dto /
|
||||
* @param entity /
|
||||
*/
|
||||
void create(${className}Dto dto);
|
||||
void create(${className} entity);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param dto /
|
||||
* @param entity /
|
||||
*/
|
||||
void update(${className}Dto dto);
|
||||
void update(${className} entity);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(${pkColumnType}[] ids);
|
||||
void deleteAll(Set<String> ids);
|
||||
}
|
||||
|
||||
@@ -1,131 +1,84 @@
|
||||
|
||||
package ${package}.service.impl;
|
||||
|
||||
import ${package}.service.${className}Service;
|
||||
import ${package}.service.dto.${className}Dto;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
package org.nl.${moduleName}.service.${package}.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.modules.wql.core.bean.ResultBean;
|
||||
import org.nl.modules.wql.core.bean.WQLObject;
|
||||
import org.nl.modules.wql.util.WqlUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.${moduleName}.service.${package}.I${className}Service;
|
||||
import org.nl.${moduleName}.service.${package}.dao.mapper.${className}Mapper;
|
||||
import org.nl.${moduleName}.service.${package}.dao.${className};
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* @description 服务实现
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
**/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class ${className}ServiceImpl implements ${className}Service {
|
||||
public class ${className}ServiceImpl extends ServiceImpl<${className}Mapper, ${className}> implements I${className}Service {
|
||||
|
||||
private final ${className}Mapper ${changeClassName}Mapper;
|
||||
|
||||
@Override
|
||||
public Map<String,Object> queryAll(Map whereJson, Pageable page){
|
||||
WQLObject wo = WQLObject.getWQLObject("${tableName}");
|
||||
ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "1=1", "update_time desc");
|
||||
final JSONObject json = rb.pageResult();
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<${className}Dto> queryAll(Map whereJson){
|
||||
WQLObject wo = WQLObject.getWQLObject("${tableName}");
|
||||
JSONArray arr = wo.query().getResultJSONArray(0);
|
||||
if (ObjectUtil.isNotEmpty(arr)) return arr.toJavaList(${className}Dto.class);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ${className}Dto findById(${pkColumnType} ${pkChangeColName}) {
|
||||
WQLObject wo = WQLObject.getWQLObject("${tableName}");
|
||||
JSONObject json = wo.query("${pkChangeColName} = '" + ${pkChangeColName} + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(json)){
|
||||
return json.toJavaObject( ${className}Dto.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ${className}Dto findByCode(String code) {
|
||||
WQLObject wo = WQLObject.getWQLObject("${tableName}");
|
||||
JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(json)){
|
||||
return json.toJavaObject( ${className}Dto.class);
|
||||
}
|
||||
return null;
|
||||
public IPage<${className}> queryAll(Map whereJson, PageQuery page){
|
||||
LambdaQueryWrapper<${className}> lam = new LambdaQueryWrapper<>();
|
||||
IPage<${className}> pages = new Page<>(page.getPage() + 1, page.getSize());
|
||||
${changeClassName}Mapper.selectPage(pages, lam);
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(${className}Dto dto) {
|
||||
public void create(${className} entity) {
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
|
||||
dto.set${pkChangeColName ? cap_first }(IdUtil.getSnowflake(1, 1).nextId());
|
||||
dto.setCreate_id(currentUserId);
|
||||
dto.setCreate_name(nickName);
|
||||
dto.setUpdate_id(currentUserId);
|
||||
dto.setUpdate_optname(nickName);
|
||||
dto.setUpdate_time(now);
|
||||
dto.setCreate_time(now);
|
||||
|
||||
WQLObject wo = WQLObject.getWQLObject("${tableName}");
|
||||
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
|
||||
wo.insert(json);
|
||||
entity.set${pkChangeColName ? cap_first }(IdUtil.getSnowflake(1, 1).nextId());
|
||||
entity.setCreateId(currentUserId);
|
||||
entity.setCreateName(nickName);
|
||||
entity.setCreateTime(now);
|
||||
entity.setUpdateId(currentUserId);
|
||||
entity.setUpdateName(nickName);
|
||||
entity.setUpdateTime(now);
|
||||
${changeClassName}Mapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(${className}Dto dto) {
|
||||
${className}Dto entity = this.findById(dto.get${pkChangeColName ? cap_first }());
|
||||
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
public void update(${className} entity) {
|
||||
${className} dto = ${changeClassName}Mapper.selectById(entity.get${pkChangeColName ? cap_first }());
|
||||
if (dto == null) throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
|
||||
String now = DateUtil.now();
|
||||
dto.setUpdate_time(now);
|
||||
dto.setUpdate_id(currentUserId);
|
||||
dto.setUpdate_optname(nickName);
|
||||
entity.setUpdateId(currentUserId);
|
||||
entity.setUpdateName(nickName);
|
||||
entity.setUpdateTime(now);
|
||||
|
||||
WQLObject wo = WQLObject.getWQLObject("${tableName}");
|
||||
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
|
||||
wo.update(json);
|
||||
${changeClassName}Mapper.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAll(${pkColumnType}[] ids) {
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
|
||||
WQLObject wo = WQLObject.getWQLObject("${tableName}");
|
||||
for (${pkColumnType} ${pkChangeColName}: ids) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("${pkChangeColName}", String.valueOf(${pkChangeColName}));
|
||||
param.put("is_delete", "1");
|
||||
param.put("update_id", currentUserId);
|
||||
param.put("update_optname", nickName);
|
||||
param.put("update_time", now);
|
||||
wo.update(param);
|
||||
}
|
||||
public void deleteAll(Set<String> ids) {
|
||||
// 真删除
|
||||
${changeClassName}Mapper.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
<modules>
|
||||
<module>nlsso-server</module>
|
||||
<module>nlsso-client</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
<groupId>org.nl</groupId>
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
</div>
|
||||
<el-form size="mini" label-width="90px">
|
||||
<el-table v-loading="loading" :data="data" :max-height="tableHeight" size="mini" style="width: 100%;margin-bottom: 15px">
|
||||
<el-table-column prop="column_name" label="字段名称" />
|
||||
<el-table-column prop="column_type" label="字段类型" />
|
||||
<el-table-column prop="columnName" label="字段名称" />
|
||||
<el-table-column prop="columnType" label="字段类型" />
|
||||
<el-table-column prop="remark" label="字段描述">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model="data[scope.$index].remark" size="mini" class="edit-input" />
|
||||
@@ -43,34 +43,22 @@
|
||||
</el-table-column>
|
||||
<el-table-column align="center" label="必填" width="70px">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox
|
||||
v-model="data[scope.$index].not_null"
|
||||
true-label="1"
|
||||
false-label="0"
|
||||
/>
|
||||
<el-checkbox v-model="data[scope.$index].notNull" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" label="列表" width="70px">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox
|
||||
v-model="data[scope.$index].list_show"
|
||||
true-label="1"
|
||||
false-label="0"
|
||||
/>
|
||||
<el-checkbox v-model="data[scope.$index].listShow" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" label="表单" width="70px">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox
|
||||
v-model="data[scope.$index].form_show"
|
||||
true-label="1"
|
||||
false-label="0"
|
||||
/>
|
||||
<el-checkbox v-model="data[scope.$index].formShow" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="表单类型">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="data[scope.$index].form_type" filterable class="edit-input" clearable size="mini" placeholder="请选择">
|
||||
<el-select v-model="data[scope.$index].formType" filterable class="edit-input" clearable size="mini" placeholder="请选择">
|
||||
<el-option
|
||||
label="文本框"
|
||||
value="Input"
|
||||
@@ -96,7 +84,7 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="查询方式">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="data[scope.$index].query_type" filterable class="edit-input" clearable size="mini" placeholder="请选择">
|
||||
<el-select v-model="data[scope.$index].queryType" filterable class="edit-input" clearable size="mini" placeholder="请选择">
|
||||
<el-option
|
||||
label="="
|
||||
value="="
|
||||
@@ -130,7 +118,7 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="日期注解">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="data[scope.$index].date_annotation" filterable class="edit-input" clearable size="mini" placeholder="请选择">
|
||||
<el-select v-model="data[scope.$index].dateAnnotation" filterable class="edit-input" clearable size="mini" placeholder="请选择">
|
||||
<el-option
|
||||
label="自动创建时间"
|
||||
value="CreationTimestamp"
|
||||
@@ -144,8 +132,11 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="关联字典">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="data[scope.$index].dict_name" filterable class="edit-input" clearable size="mini" placeholder="请选择">
|
||||
<el-option v-for="item in dicts" :key="item.id" :label="item.remark === '' ? item.name : item.remark" :value="item.name" />
|
||||
<el-select v-model="data[scope.$index].dictName" filterable class="edit-input" clearable size="mini" placeholder="请选择">
|
||||
<el-option v-for="item in dicts" :key="item.dictId" :label="item.code === '' ? item.name : item.code" :value="item.code">
|
||||
<span style="float: left">{{ item.code }}</span>
|
||||
<span style="float: right; color: #8492a6; font-size: 13px">{{ item.name }}</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -171,21 +162,21 @@
|
||||
<el-input v-model="form.author" style="width: 40%" />
|
||||
<span style="color: #C0C0C0;margin-left: 10px;">类上面的作者名称</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="模块名称" prop="module_name">
|
||||
<el-input v-model="form.module_name" style="width: 40%" />
|
||||
<el-form-item label="模块名称" prop="moduleName">
|
||||
<el-input v-model="form.moduleName" style="width: 40%" />
|
||||
<span style="color: #C0C0C0;margin-left: 10px;">模块的名称,请选择项目中已存在的模块</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="至于包下" prop="pack">
|
||||
<el-input v-model="form.pack" style="width: 40%" />
|
||||
<span style="color: #C0C0C0;margin-left: 10px;">项目包的名称,生成的代码放到哪个包里面</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="接口名称" prop="api_alias">
|
||||
<el-input v-model="form.api_alias" style="width: 40%" />
|
||||
<el-form-item label="接口名称" prop="apiAlias">
|
||||
<el-input v-model="form.apiAlias" style="width: 40%" />
|
||||
<span style="color: #C0C0C0;margin-left: 10px;">接口的名称,用于控制器与接口文档中</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="前端路径" prop="path">
|
||||
<el-input v-model="form.path" style="width: 40%" />
|
||||
<span style="color: #C0C0C0;margin-left: 10px;">输入views文件夹下的绝对路径,不存在即创建</span>
|
||||
<span style="color: #C0C0C0;margin-left: 10px;">输入views文件夹下的目录,不存在即创建</span>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item label="接口目录">-->
|
||||
<!-- <el-input v-model="form.apiPath" style="width: 40%" />-->
|
||||
@@ -197,8 +188,8 @@
|
||||
</el-form-item>
|
||||
<el-form-item label="是否覆盖" prop="cover">
|
||||
<el-radio-group v-model="form.cover" size="mini" style="width: 40%">
|
||||
<el-radio-button label="1">是</el-radio-button>
|
||||
<el-radio-button label="0">否</el-radio-button>
|
||||
<el-radio-button label="true">是</el-radio-button>
|
||||
<el-radio-button label="false">否</el-radio-button>
|
||||
</el-radio-group>
|
||||
<span style="color: #C0C0C0;margin-left: 10px;">谨防误操作,请慎重选择</span>
|
||||
</el-form-item>
|
||||
@@ -221,7 +212,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
activeName: 'first', tableName: '', tableHeight: 550, columnLoading: false, configLoading: false, dicts: [], syncLoading: false, genLoading: false,
|
||||
form: { config_id: null, tableName: '', author: '', pack: '', path: '', moduleName: '', cover: '0', apiPath: '', prefix: '', apiAlias: null },
|
||||
form: { id: null, tableName: '', author: '', pack: '', path: '', moduleName: '', cover: 'false', apiPath: '', prefix: '', apiAlias: null },
|
||||
rules: {
|
||||
author: [
|
||||
{ required: true, message: '作者不能为空', trigger: 'blur' }
|
||||
@@ -229,13 +220,13 @@ export default {
|
||||
pack: [
|
||||
{ required: true, message: '包路径不能为空', trigger: 'blur' }
|
||||
],
|
||||
module_name: [
|
||||
moduleName: [
|
||||
{ required: true, message: '包路径不能为空', trigger: 'blur' }
|
||||
],
|
||||
path: [
|
||||
{ required: true, message: '前端路径不能为空', trigger: 'blur' }
|
||||
],
|
||||
api_alias: [
|
||||
apiAlias: [
|
||||
{ required: true, message: '接口名称不能为空', trigger: 'blur' }
|
||||
],
|
||||
cover: [
|
||||
@@ -249,8 +240,7 @@ export default {
|
||||
this.tableName = this.$route.params.tableName
|
||||
this.$nextTick(() => {
|
||||
this.init()
|
||||
get(this.tableName).then(data => {
|
||||
console.log(data)
|
||||
get(this.tableName).then(data => { // 获取作者等信息
|
||||
this.form = data
|
||||
this.form.cover = this.form.cover.toString()
|
||||
})
|
||||
|
||||
@@ -23,29 +23,29 @@
|
||||
<!--表格渲染-->
|
||||
<el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column show-overflow-tooltip prop="table_name" label="表名" />
|
||||
<el-table-column show-overflow-tooltip prop="tableName" label="表名" />
|
||||
<el-table-column show-overflow-tooltip prop="engine" label="数据库引擎" />
|
||||
<el-table-column show-overflow-tooltip prop="coding" label="字符编码集" />
|
||||
<el-table-column show-overflow-tooltip prop="remark" label="备注" />
|
||||
<el-table-column prop="create_time" label="创建日期">
|
||||
<el-table-column prop="createTime" label="创建日期">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ parseTime(scope.row.create_time) }}</span>
|
||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="160px" align="center" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button size="mini" style="margin-right: 2px" type="text">
|
||||
<router-link :to="'/sys-tools/generator/preview/' + scope.row.table_name">
|
||||
<router-link :to="'/sys-tools/generator/preview/' + scope.row.tableName">
|
||||
预览
|
||||
</router-link>
|
||||
</el-button>
|
||||
<el-button size="mini" style="margin-left: -1px;margin-right: 2px" type="text" @click="toDownload(scope.row.table_name)">下载</el-button>
|
||||
<el-button size="mini" style="margin-left: -1px;margin-right: 2px" type="text" @click="toDownload(scope.row.tableName)">下载</el-button>
|
||||
<el-button size="mini" style="margin-left: -1px;margin-right: 2px" type="text">
|
||||
<router-link :to="'/sys-tools/generator/config/' + scope.row.table_name">
|
||||
<router-link :to="'/sys-tools/generator/config/' + scope.row.tableName">
|
||||
配置
|
||||
</router-link>
|
||||
</el-button>
|
||||
<el-button type="text" style="margin-left: -1px" size="mini" @click="toGen(scope.row.table_name)">生成</el-button>
|
||||
<el-button type="text" style="margin-left: -1px" size="mini" @click="toGen(scope.row.tableName)">生成</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
114
nladmin-ui/src/views/wms/basedata/index.vue
Normal file
114
nladmin-ui/src/views/wms/basedata/index.vue
Normal file
@@ -0,0 +1,114 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<!--工具栏-->
|
||||
<div class="head-container">
|
||||
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
||||
<crudOperation :permission="permission"/>
|
||||
<!--表单组件-->
|
||||
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"
|
||||
:title="crud.status.title" width="500px"
|
||||
>
|
||||
<el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
|
||||
<el-form-item label="车间编码">
|
||||
<el-input v-model="form.workshopCode" style="width: 370px;"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="车间名称 ">
|
||||
<el-input v-model="form.workshopName" style="width: 370px;"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="form.remark" style="width: 370px;"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否启用">
|
||||
<el-input v-model="form.isUsed" style="width: 370px;"/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="text" @click="crud.cancelCU">取消</el-button>
|
||||
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
<!--表格渲染-->
|
||||
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="mini" style="width: 100%;"
|
||||
@selection-change="crud.selectionChangeHandler"
|
||||
>
|
||||
<el-table-column type="selection" width="55"/>
|
||||
<el-table-column prop="workshopCode" label="车间编码"
|
||||
:min-width="flexWidth('workshopCode',crud.data,'车间编码')"
|
||||
/>
|
||||
<el-table-column prop="workshopName" label="车间名称 "
|
||||
:min-width="flexWidth('workshopName',crud.data,'车间名称 ')"
|
||||
/>
|
||||
<el-table-column prop="remark" label="备注" :min-width="flexWidth('remark',crud.data,'备注')"/>
|
||||
<el-table-column prop="isUsed" label="是否启用" :min-width="flexWidth('isUsed',crud.data,'是否启用')"/>
|
||||
<el-table-column prop="isDelete" label="是否删除" :min-width="flexWidth('isDelete',crud.data,'是否删除')"/>
|
||||
<el-table-column prop="createName" label="创建人" :min-width="flexWidth('createName',crud.data,'创建人')"/>
|
||||
<el-table-column prop="createTime" label="创建时间" :min-width="flexWidth('createTime',crud.data,'创建时间')"/>
|
||||
<el-table-column prop="updateName" label="修改人" :min-width="flexWidth('updateName',crud.data,'修改人')"/>
|
||||
<el-table-column prop="updateTime" label="修改时间" :min-width="flexWidth('updateTime',crud.data,'修改时间')"/>
|
||||
<el-table-column v-permission="[]" label="操作" width="120px" align="center" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<udOperation
|
||||
:data="scope.row"
|
||||
:permission="permission"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<!--分页组件-->
|
||||
<pagination/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import crudWorkshop from './workshop'
|
||||
import CRUD, { crud, form, header, presenter } from '@crud/crud'
|
||||
import rrOperation from '@crud/RR.operation'
|
||||
import crudOperation from '@crud/CRUD.operation'
|
||||
import udOperation from '@crud/UD.operation'
|
||||
import pagination from '@crud/Pagination'
|
||||
|
||||
const defaultForm = {
|
||||
workshopCode: null,
|
||||
workshopName: null,
|
||||
remark: null,
|
||||
isUsed: null,
|
||||
isDelete: null,
|
||||
createId: null,
|
||||
createName: null,
|
||||
createTime: null,
|
||||
updateId: null,
|
||||
updateName: null,
|
||||
updateTime: null
|
||||
}
|
||||
export default {
|
||||
name: 'Workshop',
|
||||
components: { pagination, crudOperation, rrOperation, udOperation },
|
||||
mixins: [presenter(), header(), form(defaultForm), crud()],
|
||||
cruds() {
|
||||
return CRUD({
|
||||
title: '车间基础信息',
|
||||
url: 'api/workshop',
|
||||
idField: 'workshopCode',
|
||||
sort: 'workshopCode,desc',
|
||||
crudMethod: { ...crudWorkshop }
|
||||
})
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
permission: {},
|
||||
rules: {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 钩子:在获取表格数据之前执行,false 则代表不获取数据
|
||||
[CRUD.HOOK.beforeRefresh]() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
27
nladmin-ui/src/views/wms/basedata/workshop.js
Normal file
27
nladmin-ui/src/views/wms/basedata/workshop.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
export function add(data) {
|
||||
return request({
|
||||
url: 'api/workshop',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function del(ids) {
|
||||
return request({
|
||||
url: 'api/workshop/',
|
||||
method: 'delete',
|
||||
data: ids
|
||||
})
|
||||
}
|
||||
|
||||
export function edit(data) {
|
||||
return request({
|
||||
url: 'api/workshop',
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export default { add, edit, del }
|
||||
Reference in New Issue
Block a user