作者 钟来

U渔设备的档位bug修改

正在显示 38 个修改的文件 包含 1174 行增加620 行删除
package com.zhonglai.luhui.dao.mapper;
import com.zhonglai.luhui.dao.dto.PublicSQL;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* 公用mapper
*/
@Component
public interface PublicTemplateMapper {
/**
* 添加对象
*/
@InsertProvider(type = PublicSQL.class, method = "insert")
int insert(Object object);
/**
* 指定表名添加
*/
@InsertProvider(type = PublicSQL.class, method = "insertToTable")
@Options(useGeneratedKeys = true, keyProperty = "object.id")
int insertToTable(@Param("object") Object object,@Param("tableName") String tableName,@Param("primaryKey") String primaryKey);
/**
* 添加对象集合
*/
@InsertProvider(type = PublicSQL.class, method = "insertAll")
int insertAll(List<?> list);
/**
* 指定表名添加对象集合
*/
@InsertProvider(type = PublicSQL.class, method = "insertAllToTable")
int insertAllToTable(@Param("list")List<?> list,@Param("tableName")String tableName);
/**
* 更新对象不为空的属性
* @param object
* @param whereFieldNames
*/
@UpdateProvider(type = PublicSQL.class, method = "updateObject")
int updateObject(@Param("object") Object object, @Param("whereFieldNames") String whereFieldNames);
@UpdateProvider(type = PublicSQL.class, method = "updateObject")
int updateObjectByTable(@Param("object") Object object, @Param("whereFieldNames") String whereFieldNames, @Param("tablename") String tablename);
/**
* 自定义sql更新
* @param sql
*/
@UpdateProvider(type = PublicSQL.class, method = "updateBySql")
int updateBySql(String sql);
/**
* 查询 通过条件查询
* @param clas
* @param idName
* @param values
* @return
*/
@SelectProvider(type = PublicSQL.class, method = "getObject")
Map<String,Object> getObject(@Param("class") Class<?> clas, @Param("idName") String idName, @Param("values") String values);
@SelectProvider(type = PublicSQL.class, method = "selectCountBySql")
Long selectCountBySql(@Param("sql") String sql);
/**
* 查询 通过条件查询
* @param clas
* @param idName
* @param values
* @return
*/
@SelectProvider(type = PublicSQL.class, method = "getObject")
Map<String,Object> getObjectForTableName(@Param("class") Class<?> clas, @Param("idName") String idName, @Param("values") String values, @Param("tableName") String tableName);
/**
* 查询 通过条件查询单个指定项目
* @param clas 類型
* @param select 查詢結果
* @param idName 主鍵名稱
* @param values 主鍵值
* @return
*/
@SelectProvider(type = PublicSQL.class, method = "getObject")
Map<String,Object> getObjectSelectTableName(@Param("class") Class<?> clas, @Param("select") String select, @Param("idName") String idName, @Param("values") String values, @Param("tableName") String tableName);
/**
* 查询list
* @param object
* @param whereMap 如果是时间,whereMap里面对应的字段比较符为time,同时添加一个end_字段名的值 表示是结束时间
* @param order
* @param pagetSize
* @param pageNo
* @return
*/
@SelectProvider(type = PublicSQL.class, method = "getObjectList")
List<Map<String,Object>> getObjectList(@Param("object") Object object, @Param("selectStr") String selectStr, @Param("whereMap") Map<String, String> whereMap, @Param("order") String order, @Param("pageSize") Integer pagetSize, @Param("pageNo") Integer pageNo);
/**
* 查詢totle
* @param object
* @param whereMap 如果是时间,whereMap里面对应的字段比较符为time,同时添加一个end_字段名的值 表示是结束时间
* @return
*/
@SelectProvider(type = PublicSQL.class, method = "getObjectListTotle")
Long getObjectListTotle(@Param("object") Object object, @Param("whereMap") Map<String, String> whereMap);
/**
* 通过条件删除对象
* @param oClass
* @param map
*/
@UpdateProvider(type = PublicSQL.class, method = "deleteObjectByContent")
int deleteObjectByContent(@Param("objectCalss") Class<?> oClass, @Param("map") Map<String, String> map);
/**
* 自定义sql语句查询list
* @param sql
* @return
*/
@SelectProvider(type = PublicSQL.class, method = "getObjectListBySQL")
List<Map<String,Object>> getObjectListBySQL(@Param("sql") String sql);
/**
* 添加或更新对象列表
* INSERT INTO `test` (`in1`,`str1`)VALUES ('1','2'),('2','2') ON DUPLICATE KEY UPDATE `in1`=VALUES(`in1`),`str1`=VALUES(`str1`);
* @param objectlist 对象列表
* @return
*/
@UpdateProvider(type = PublicSQL.class, method = "saveOrUpdateObjectList")
int saveOrUpdateObjectList(List<Object> objectlist);
/**
* 添加或更新对象
* INSERT INTO test(`in1`,`str1`) VALUES ('1','1');
* @param object 对象
* @return
*/
@UpdateProvider(type = PublicSQL.class, method = "saveOrUpdateObject")
int saveOrUpdateObject(Object object);
/**
* 通过id删除数据
* @return
*/
@UpdateProvider(type = PublicSQL.class, method = "deleteObjectById")
int deleteObjectById(@Param("objectCalss") Class<?> oClass, @Param("id") String id);
@Options(useGeneratedKeys = false)
@InsertProvider(type = PublicSQL.class, method = "updateBySql")
int insertIntoBySql(@Param("sql") String sql);
@SelectProvider(type = PublicSQL.class, method = "selectTList")
List<Map<String,Object>> selectTList(Object t);
}
... ...
package com.zhonglai.luhui.dao.service;
import java.util.List;
public interface PublicTemplateService {
/**
* 查询表
*
* @return 表
*/
<T> List<T> selectTList(T t);
<T> T getTById(Object id,Class<T> clas);
int add(Object t);
int edit(Object t);
int removeByIds(Class<?> clas,Object... id);
}
... ...
package com.zhonglai.luhui.dao.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.zhonglai.luhui.dao.mapper.PublicMapper;
import com.zhonglai.luhui.dao.mapper.PublicTemplateMapper;
import com.zhonglai.luhui.dao.service.PublicTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 公共模板服务
*/
@Service
public class PublicTemplateServiceImpl implements PublicTemplateService {
@Autowired
private PublicTemplateMapper publicMapper;
@Override
public <T> List<T> selectTList(T t) {
List<Map<String,Object>> list = publicMapper.selectTList(t);
List<T> rList = new ArrayList<>();
if(null != list && list.size() != 0)
{
rList = new ArrayList<T>();
for (Map<String,Object> map:list)
{
T at = (T) JSONObject.parseObject(JSONObject.toJSONString(map),t.getClass());
rList.add(at);
}
}
return rList;
}
@Override
public <T> T getTById(Object id,Class<T> clas) {
Map<String,Object> object = publicMapper.getObject(clas,"id", String.valueOf(id));
if(null != object)
{
return JSONObject.parseObject(JSONObject.toJSONString(object),clas);
}
return null;
}
@Override
public int add(Object t) {
return publicMapper.insert(t);
}
@Override
public int edit(Object t) {
return publicMapper.updateObject(t,"id");
}
@Override
public int removeByIds(Class<?> clas, Object... ids) {
int i = 0;
for (Object o:ids)
{
i+=publicMapper.deleteObjectById(clas,o+"");
}
return i;
}
}
... ...
... ... @@ -11,20 +11,18 @@
<artifactId>ruoyi-generator</artifactId>
<description>
generator代码生成
</description>
<dependencies>
<!--velocity代码生成使用模板 -->
<!-- velocity代码生成使用模板 -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
</dependency>
<!-- collections工具类 -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<!-- 通用工具-->
<dependency>
<groupId>com.zhonglai.luhui</groupId>
... ... @@ -35,52 +33,17 @@
<groupId>com.zhonglai.luhui</groupId>
<artifactId>lh-jar-action</artifactId>
</dependency>
<!-- 文档 -->
<dependency >
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
<exclusions>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--https://mvnrepository.com/artifact/io.swagger/swagger-models-->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>${swagger-models.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<!--&lt;!&ndash; https://mvnrepository.com/artifact/com.github.xiaoymin/swagger-bootstrap-ui &ndash;&gt;-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>${swagger-ui.version}</version>
<groupId>com.zhonglai.luhui</groupId>
<artifactId>ruoyi-common-security</artifactId>
</dependency>
<!-- 阿里数据库连接池 -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<!-- 建议使用最新版本,最新版本请从项目首页查找 -->
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zhonglai.luhui</groupId>
<artifactId>lh-common-datasource</artifactId>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
package com.ruoyi.generator.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.utils.DateUtils;
import com.zhonglai.luhui.action.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
... ... @@ -23,11 +18,18 @@ import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
import com.ruoyi.common.annotation.Log;
import com.zhonglai.luhui.action.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.zhonglai.luhui.security.utils.SecurityUtils;
import com.ruoyi.common.utils.sql.SqlUtil;
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.generator.domain.GenTableColumn;
import com.ruoyi.generator.service.IGenTableColumnService;
... ... @@ -38,7 +40,6 @@ import com.ruoyi.generator.service.IGenTableService;
*
* @author ruoyi
*/
@Api(tags = "代码生成 操作处理")
@RestController
@RequestMapping("/tool/gen")
public class GenController extends BaseController
... ... @@ -52,8 +53,7 @@ public class GenController extends BaseController
/**
* 查询代码生成列表
*/
@ApiOperation("查询代码生成列表")
// @PreAuthorize("@ss.hasPermi('tool:gen:list')")
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
@GetMapping("/list")
public TableDataInfo genList(GenTable genTable)
{
... ... @@ -65,8 +65,7 @@ public class GenController extends BaseController
/**
* 修改代码生成业务
*/
@ApiOperation("修改代码生成业务")
// @PreAuthorize("@ss.hasPermi('tool:gen:query')")
@PreAuthorize("@ss.hasPermi('tool:gen:query')")
@GetMapping(value = "/{tableId}")
public AjaxResult getInfo(@PathVariable Long tableId)
{
... ... @@ -77,14 +76,13 @@ public class GenController extends BaseController
map.put("info", table);
map.put("rows", list);
map.put("tables", tables);
return AjaxResult.success(map);
return success(map);
}
/**
* 查询数据库列表
*/
@ApiOperation("查询数据库列表")
// @PreAuthorize("@ss.hasPermi('tool:gen:list')")
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
@GetMapping("/db/list")
public TableDataInfo dataList(GenTable genTable)
{
... ... @@ -96,8 +94,7 @@ public class GenController extends BaseController
/**
* 查询数据表字段列表
*/
@ApiOperation("查询数据表字段列表")
// @PreAuthorize("@ss.hasPermi('tool:gen:list')")
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
@GetMapping(value = "/column/{tableId}")
public TableDataInfo columnList(Long tableId)
{
... ... @@ -111,8 +108,7 @@ public class GenController extends BaseController
/**
* 导入表结构(保存)
*/
@ApiOperation("导入表结构(保存)")
// @PreAuthorize("@ss.hasPermi('tool:gen:import')")
@PreAuthorize("@ss.hasPermi('tool:gen:import')")
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
@PostMapping("/importTable")
public AjaxResult importTableSave(String tables)
... ... @@ -120,54 +116,87 @@ public class GenController extends BaseController
String[] tableNames = Convert.toStrArray(tables);
// 查询表信息
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
genTableService.importGenTable(tableList);
return AjaxResult.success();
genTableService.importGenTable(tableList, SecurityUtils.getUsername());
return success();
}
/**
* 创建表结构(保存)
*/
@PreAuthorize("@ss.hasRole('admin')")
@Log(title = "创建表", businessType = BusinessType.OTHER)
@PostMapping("/createTable")
public AjaxResult createTableSave(String sql)
{
try
{
SqlUtil.filterKeyword(sql);
List<SQLStatement> sqlStatements = SQLUtils.parseStatements(sql, DbType.mysql);
List<String> tableNames = new ArrayList<>();
for (SQLStatement sqlStatement : sqlStatements)
{
if (sqlStatement instanceof MySqlCreateTableStatement)
{
MySqlCreateTableStatement createTableStatement = (MySqlCreateTableStatement) sqlStatement;
if (genTableService.createTable(createTableStatement.toString()))
{
String tableName = createTableStatement.getTableName().replaceAll("`", "");
tableNames.add(tableName);
}
}
}
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames.toArray(new String[tableNames.size()]));
String operName = SecurityUtils.getUsername();
genTableService.importGenTable(tableList, operName);
return AjaxResult.success();
}
catch (Exception e)
{
logger.error(e.getMessage(), e);
return AjaxResult.error("创建表结构异常");
}
}
/**
* 修改保存代码生成业务
*/
@ApiOperation("修改保存代码生成业务")
// @PreAuthorize("@ss.hasPermi('tool:gen:edit')")
@PreAuthorize("@ss.hasPermi('tool:gen:edit')")
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult editSave(@Validated @RequestBody GenTable genTable)
{
genTableService.validateEdit(genTable);
genTableService.updateGenTable(genTable);
return AjaxResult.success();
return success();
}
/**
* 删除代码生成
*/
@ApiOperation("删除代码生成")
// @PreAuthorize("@ss.hasPermi('tool:gen:remove')")
@PreAuthorize("@ss.hasPermi('tool:gen:remove')")
@Log(title = "代码生成", businessType = BusinessType.DELETE)
@DeleteMapping("/{tableIds}")
public AjaxResult remove(@PathVariable Long[] tableIds)
{
genTableService.deleteGenTableByIds(tableIds);
return AjaxResult.success();
return success();
}
/**
* 预览代码
*/
@ApiOperation("预览代码")
// @PreAuthorize("@ss.hasPermi('tool:gen:preview')")
@PreAuthorize("@ss.hasPermi('tool:gen:preview')")
@GetMapping("/preview/{tableId}")
public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException
{
Map<String, String> dataMap = genTableService.previewCode(tableId);
return AjaxResult.success(dataMap);
return success(dataMap);
}
/**
* 生成代码(下载方式)
*/
@ApiOperation("生成代码(下载方式)")
// @PreAuthorize("@ss.hasPermi('tool:gen:code')")
@PreAuthorize("@ss.hasPermi('tool:gen:code')")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/download/{tableName}")
public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
... ... @@ -179,34 +208,31 @@ public class GenController extends BaseController
/**
* 生成代码(自定义路径)
*/
@ApiOperation("生成代码(自定义路径)")
// @PreAuthorize("@ss.hasPermi('tool:gen:code')")
@PreAuthorize("@ss.hasPermi('tool:gen:code')")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/genCode/{tableName}")
public AjaxResult genCode(@PathVariable("tableName") String tableName)
{
genTableService.generatorCode(tableName);
return AjaxResult.success();
return success();
}
/**
* 同步数据库
*/
@ApiOperation("同步数据库")
// @PreAuthorize("@ss.hasPermi('tool:gen:edit')")
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
@PreAuthorize("@ss.hasPermi('tool:gen:edit')")
@Log(title = "同步数据库", businessType = BusinessType.UPDATE)
@GetMapping("/synchDb/{tableName}")
public AjaxResult synchDb(@PathVariable("tableName") String tableName)
{
genTableService.synchDb(tableName);
return AjaxResult.success();
return success();
}
/**
* 批量生成代码
*/
@ApiOperation("批量生成代码")
// @PreAuthorize("@ss.hasPermi('tool:gen:code')")
@PreAuthorize("@ss.hasPermi('tool:gen:code')")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/batchGenCode")
public void batchGenCode(HttpServletResponse response, String tables) throws IOException
... ... @@ -216,14 +242,6 @@ public class GenController extends BaseController
genCode(response, data);
}
@ApiOperation("从数据库结构生成代码")
@ApiImplicitParam(value = "表名集合",name = "tableNames")
@GetMapping("/generatorCodeFromDb")
public void generatorCodeFromDb(HttpServletResponse response,String databaseName, String tableNames,String packageName,String dataSource) throws IOException {
byte[] data = genTableService.generatorCodeFromDb(databaseName,tableNames,packageName,dataSource);
genCode(response, data);
}
/**
* 生成zip文件
*/
... ... @@ -232,7 +250,7 @@ public class GenController extends BaseController
response.reset();
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment; filename=\""+ DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSS) +"生成代码.zip\"");
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream());
... ...
... ... @@ -3,8 +3,6 @@ package com.ruoyi.generator.domain;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import com.ruoyi.common.annotation.PublicSQLConfig;
import org.apache.commons.lang3.ArrayUtils;
import com.ruoyi.common.constant.GenConstants;
import com.ruoyi.common.tool.BaseEntity;
... ... @@ -17,7 +15,6 @@ import com.ruoyi.common.utils.StringUtils;
*/
public class GenTable extends BaseEntity
{
@PublicSQLConfig(isSelect=false)
private static final long serialVersionUID = 1L;
/** 编号 */
... ... @@ -44,6 +41,9 @@ public class GenTable extends BaseEntity
/** 使用的模板(crud单表操作 tree树表操作 sub主子表操作) */
private String tplCategory;
/** 前端类型(element-ui模版 element-plus模版) */
private String tplWebType;
/** 生成包路径 */
@NotBlank(message = "生成包路径不能为空")
private String packageName;
... ... @@ -98,7 +98,19 @@ public class GenTable extends BaseEntity
/** 上级菜单名称字段 */
private String parentMenuName;
private String dataSource;
/**
* 模块路径
*/
private String modlePath;
public String getModlePath() {
return modlePath;
}
public void setModlePath(String modlePath) {
this.modlePath = modlePath;
}
public Long getTableId()
{
... ... @@ -170,6 +182,16 @@ public class GenTable extends BaseEntity
this.tplCategory = tplCategory;
}
public String getTplWebType()
{
return tplWebType;
}
public void setTplWebType(String tplWebType)
{
this.tplWebType = tplWebType;
}
public String getPackageName()
{
return packageName;
... ... @@ -374,12 +396,4 @@ public class GenTable extends BaseEntity
}
return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
}
public String getDataSource() {
return dataSource;
}
public void setDataSource(String dataSource) {
this.dataSource = dataSource;
}
}
\ No newline at end of file
... ...
... ... @@ -3,7 +3,6 @@ package com.ruoyi.generator.domain;
import javax.validation.constraints.NotBlank;
import com.ruoyi.common.tool.BaseEntity;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.annotation.PublicSQLConfig;
/**
* 代码生成业务字段表 gen_table_column
... ... @@ -12,7 +11,6 @@ import com.ruoyi.common.annotation.PublicSQLConfig;
*/
public class GenTableColumn extends BaseEntity
{
@PublicSQLConfig(isSelect=false)
private static final long serialVersionUID = 1L;
/** 编号 */
... ...
... ... @@ -2,7 +2,6 @@ package com.ruoyi.generator.mapper;
import java.util.List;
import com.ruoyi.generator.domain.GenTableColumn;
import org.apache.ibatis.annotations.Mapper;
/**
* 业务字段 数据层
... ...
... ... @@ -2,7 +2,6 @@ package com.ruoyi.generator.mapper;
import java.util.List;
import com.ruoyi.generator.domain.GenTable;
import org.apache.ibatis.annotations.Mapper;
/**
* 业务 数据层
... ... @@ -81,4 +80,12 @@ public interface GenTableMapper
* @return 结果
*/
public int deleteGenTableByIds(Long[] ids);
/**
* 创建表
*
* @param sql 表结构
* @return 结果
*/
public int createTable(String sql);
}
... ...
package com.ruoyi.generator.service;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.zip.ZipOutputStream;
import com.ruoyi.generator.domain.GenTable;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.text.Convert;
... ... @@ -65,4 +70,5 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService
{
return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
}
}
... ...
... ... @@ -4,7 +4,6 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
... ... @@ -13,10 +12,9 @@ import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import com.ruoyi.generator.domain.TableVules;
import com.ruoyi.generator.mapper.GenTableMapMapper;
import com.zhonglai.luhui.datasource.enums.DataSource;
import com.zhonglai.luhui.datasource.enums.DataSourceType;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.GsonConstructor;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template;
... ... @@ -27,8 +25,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.GenConstants;
import com.ruoyi.common.core.text.CharsetKit;
... ... @@ -58,9 +54,6 @@ public class GenTableServiceImpl implements IGenTableService
@Autowired
private GenTableColumnMapper genTableColumnMapper;
@Autowired
private GenTableMapMapper mapMapper;
/**
* 查询业务信息
*
... ... @@ -159,38 +152,49 @@ public class GenTableServiceImpl implements IGenTableService
}
/**
* 创建表
*
* @param sql 创建表语句
* @return 结果
*/
@Override
public boolean createTable(String sql)
{
return genTableMapper.createTable(sql) == 0;
}
/**
* 导入表结构
*
* @param tableList 导入表列表
*/
@Override
@Transactional
public void importGenTable(List<GenTable> tableList)
public void importGenTable(List<GenTable> tableList, String operName)
{
// String operName = SecurityUtils.getUsername();
// try
// {
// for (GenTable table : tableList)
// {
// String tableName = table.getTableName();
// GenUtils.initTable(table, operName);
// int row = genTableMapper.insertGenTable(table);
// if (row > 0)
// {
// // 保存列信息
// List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
// for (GenTableColumn column : genTableColumns)
// {
// GenUtils.initColumnField(column, table);
// genTableColumnMapper.insertGenTableColumn(column);
// }
// }
// }
// }
// catch (Exception e)
// {
// throw new ServiceException("导入失败:" + e.getMessage());
// }
try
{
for (GenTable table : tableList)
{
String tableName = table.getTableName();
GenUtils.initTable(table, operName);
int row = genTableMapper.insertGenTable(table);
if (row > 0)
{
// 保存列信息
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
for (GenTableColumn column : genTableColumns)
{
GenUtils.initColumnField(column, table);
genTableColumnMapper.insertGenTableColumn(column);
}
}
}
}
catch (Exception e)
{
throw new ServiceException("导入失败:" + e.getMessage());
}
}
/**
... ... @@ -214,7 +218,7 @@ public class GenTableServiceImpl implements IGenTableService
VelocityContext context = VelocityUtils.prepareContext(table);
// 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
for (String template : templates)
{
// 渲染模板
... ... @@ -252,36 +256,6 @@ public class GenTableServiceImpl implements IGenTableService
{
// 查询表信息
GenTable table = genTableMapper.selectGenTableByName(tableName);
generatorCode(table);
}
/**
* 从数据库结构生成代码
*
* @param tableNames 表名称
*/
@DataSource(value = DataSourceType.SLAVE)
@Override
public byte[] generatorCodeFromDb(String databaseName,String tableNames,String packageName,String dataSource)
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
for (String tableName:tableNames.split(","))
{
// 查询表信息
GenTable table = generatorFromTablename(databaseName,tableName,packageName,dataSource);
generatorCode(table, zip);
}
IOUtils.closeQuietly(zip);
return outputStream.toByteArray();
}
private void generatorCode(GenTable table)
{
// 设置主子表信息
setSubTable(table);
// 设置主键列信息
... ... @@ -292,7 +266,7 @@ public class GenTableServiceImpl implements IGenTableService
VelocityContext context = VelocityUtils.prepareContext(table);
// 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
for (String template : templates)
{
if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm"))
... ... @@ -314,97 +288,6 @@ public class GenTableServiceImpl implements IGenTableService
}
}
public GenTable generatorFromTablename(String databaseName,String tableName,String packageName,String dataSource)
{
List<Map<String,Object>> list = mapMapper.getObjectListBySQL("SELECT COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT FROM information_schema.columns WHERE table_schema = '"+databaseName+"' AND table_name = '"+tableName+"'");
Map<String,Object> map = mapMapper.getObjectListBySQL("SELECT TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name='"+tableName+"' AND table_schema='"+databaseName+"'").get(0);
String[] tbs = tableName.split("_");
GenTable genTable = new GenTable();
genTable.setTableName(tableName);
genTable.setTableComment(map.get("TABLE_COMMENT")+"");
genTable.setClassName(GenUtils.convertClassName(tableName));
genTable.setTplCategory("crud");
genTable.setPackageName(packageName);
genTable.setModuleName(tbs[0]);
genTable.setBusinessName(genTable.getClassName());
genTable.setFunctionName(genTable.getTableComment());
genTable.setFunctionAuthor("钟来");
genTable.setGenType("1");
genTable.setGenPath("/");
if(StringUtils.isNotEmpty(dataSource))
{
genTable.setDataSource("DataSourceType."+dataSource);
}
List<GenTableColumn> columns = new ArrayList<>();
for(Map<String,Object> table:list)
{
TableVules tableVules = JSONObject.parseObject(JSONObject.toJSONString(table), TableVules.class);
GenTableColumn genTableColumn = new GenTableColumn();
genTableColumn.setColumnName(tableVules.getColumnName());
genTableColumn.setColumnComment(tableVules.getColumnComment());
genTableColumn.setColumnType(tableVules.getColumnType());
genTableColumn.setJavaType(GenUtils.toSqlToJava(tableVules.getDataType()));
genTableColumn.setJavaField(tableVules.getColumnName());
genTableColumn.setIsQuery(GenConstants.REQUIRE);
if("PRI".equals(tableVules.getColumnKey())) //主键
{
genTableColumn.setIsPk("1");
genTable.setPkColumn(genTableColumn);
}
if("auto_increment".equals(tableVules.getExtra()))
{
genTableColumn.setIsIncrement("1");
}else {
genTableColumn.setIsIncrement("0");
}
if("NO".equals(tableVules.getIsNullable()))
{
genTableColumn.setIsRequired("1");
}else {
genTableColumn.setIsRequired("0");
}
switch (tableVules.getDataType())
{
case "int":
if(genTableColumn.getColumnName().indexOf("_time")>=0 )
{
genTableColumn.setQueryType("BETWEEN");
}else{
genTableColumn.setQueryType("EQ");
}
break;
case "varchar":
genTableColumn.setQueryType("LIKE");
break;
case "bigint":
genTableColumn.setQueryType("EQ");
break;
case "boolean":
genTableColumn.setQueryType("EQ");
break;
case "char":
genTableColumn.setQueryType("EQ");
break;
case "date":
genTableColumn.setQueryType("BETWEEN");
break;
case "datetime":
genTableColumn.setQueryType("BETWEEN");
break;
case "enum":
genTableColumn.setQueryType("EQ");
break;
}
columns.add(genTableColumn);
}
genTable.setColumns(columns);
return genTable;
}
/**
* 同步数据库
*
... ... @@ -482,48 +365,13 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 查询表信息并生成代码
*/
private void generatorCode(String tableName, ZipOutputStream zip)
public void generatorCode(String tableName, ZipOutputStream zip)
{
// 查询表信息
GenTable table = genTableMapper.selectGenTableByName(tableName);
generatorCode(table,zip);
}
private void generatorCode(GenTable table, ZipOutputStream zip)
{
// 设置主子表信息
setSubTable(table);
// 设置主键列信息
setPkColumn(table);
VelocityInitializer.initVelocity();
VelocityContext context = VelocityUtils.prepareContext(table);
// 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
for (String template : templates)
{
// 渲染模板
StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
tpl.merge(context, sw);
try
{
// 添加到zip
zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
IOUtils.write(sw.toString(), zip, Constants.UTF8);
IOUtils.closeQuietly(sw);
zip.flush();
zip.closeEntry();
}
catch (IOException e)
{
log.error("渲染模板失败,表名:" + table.getTableName(), e);
}
}
}
/**
* 修改保存参数校验
*
... ... @@ -534,8 +382,8 @@ public class GenTableServiceImpl implements IGenTableService
{
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
{
String options = JSON.toJSONString(genTable.getParams());
JSONObject paramsObj = JSONObject.parseObject(options);
String options = GsonConstructor.get().toJson(genTable.getParams());
JSONObject paramsObj = JSON.parseObject(options);
if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
{
throw new ServiceException("树编码字段不能为空");
... ... @@ -619,7 +467,7 @@ public class GenTableServiceImpl implements IGenTableService
*/
public void setTableFromOptions(GenTable genTable)
{
JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions());
JSONObject paramsObj = JSON.parseObject(genTable.getOptions());
if (StringUtils.isNotNull(paramsObj))
{
String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
... ... @@ -652,4 +500,39 @@ public class GenTableServiceImpl implements IGenTableService
}
return genPath + File.separator + VelocityUtils.getFileName(template, table);
}
public void generatorCode(GenTable table, ZipOutputStream zip)
{
// 设置主子表信息
setSubTable(table);
// 设置主键列信息
setPkColumn(table);
VelocityInitializer.initVelocity();
VelocityContext context = VelocityUtils.prepareContext(table);
// 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
for (String template : templates)
{
// 渲染模板
StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
tpl.merge(context, sw);
try
{
// 添加到zip
zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
IOUtils.write(sw.toString(), zip, Constants.UTF8);
IOUtils.closeQuietly(sw);
zip.flush();
zip.closeEntry();
}
catch (IOException e)
{
log.error("渲染模板失败,表名:" + table.getTableName(), e);
}
}
}
}
\ No newline at end of file
... ...
... ... @@ -67,11 +67,20 @@ public interface IGenTableService
public void deleteGenTableByIds(Long[] tableIds);
/**
* 创建表
*
* @param sql 创建表语句
* @return 结果
*/
public boolean createTable(String sql);
/**
* 导入表结构
*
*
* @param tableList 导入表列表
* @param operName 操作人员
*/
public void importGenTable(List<GenTable> tableList);
public void importGenTable(List<GenTable> tableList, String operName);
/**
* 预览代码
... ... @@ -118,11 +127,4 @@ public interface IGenTableService
* @param genTable 业务信息
*/
public void validateEdit(GenTable genTable);
/**
* 从数据库结构生成代码
*
* @param tableName 表名称
*/
public byte[] generatorCodeFromDb(String databaseName,String tableName,String packageName,String dataSource);
}
... ...
... ... @@ -22,7 +22,7 @@ public class GenUtils
{
genTable.setClassName(convertClassName(genTable.getTableName()));
genTable.setPackageName(GenConfig.getPackageName());
genTable.setModuleName(getModuleName(GenConfig.getPackageName()));
genTable.setModuleName(getModuleName(genTable.getTableName()));
genTable.setBusinessName(getBusinessName(genTable.getTableName()));
genTable.setFunctionName(replaceText(genTable.getTableComment()));
genTable.setFunctionAuthor(GenConfig.getAuthor());
... ... @@ -70,6 +70,9 @@ public class GenUtils
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10)
{
column.setJavaType(GenConstants.TYPE_INTEGER);
}else if(column.getColumnType().equals("int"))
{
column.setJavaType(GenConstants.TYPE_INTEGER);
}
// 长整形
else
... ... @@ -150,9 +153,7 @@ public class GenUtils
*/
public static String getModuleName(String packageName)
{
int lastIndex = packageName.lastIndexOf(".");
int nameLength = packageName.length();
return StringUtils.substring(packageName, lastIndex + 1, nameLength);
return packageName.split("_")[0];
}
/**
... ... @@ -163,9 +164,7 @@ public class GenUtils
*/
public static String getBusinessName(String tableName)
{
int lastIndex = tableName.lastIndexOf("_");
int nameLength = tableName.length();
return StringUtils.substring(tableName, lastIndex + 1, nameLength);
return tableName.substring(tableName.indexOf("_")+1);
}
/**
... ... @@ -275,7 +274,7 @@ public class GenUtils
case "smallint":return "Integer";
case "mediumint":return "Integer";
case "bit":return "Boolean";
case "bigint":return "java.math.BigInteger";
case "bigint":return "java.math.Long";
case "float":return "Float";
case "double":return "Double";
case "decimal":return "java.math.BigDecimal";
... ... @@ -295,6 +294,7 @@ public class GenUtils
case "longblob":return "String";
case "mediumtext":return "String";
case "enum":return "Enum";
case "json":return "com.alibaba.fastjson2.JSONObject";
default:
System.out.println("-----------------》转化失败:未发现的类型"+sqlType);
break;
... ...
... ... @@ -4,8 +4,10 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.velocity.VelocityContext;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.velocity.VelocityContext;
import com.ruoyi.common.constant.GenConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
... ... @@ -40,6 +42,7 @@ public class VelocityUtils
String packageName = genTable.getPackageName();
String tplCategory = genTable.getTplCategory();
String functionName = genTable.getFunctionName();
String modlePath = genTable.getModlePath();
VelocityContext velocityContext = new VelocityContext();
velocityContext.put("tplCategory", genTable.getTplCategory());
... ... @@ -56,11 +59,11 @@ public class VelocityUtils
velocityContext.put("datetime", DateUtils.getDate());
velocityContext.put("pkColumn", genTable.getPkColumn());
velocityContext.put("importList", getImportList(genTable));
velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
velocityContext.put("permissionPrefix", getPermissionPrefix(modlePath,moduleName, businessName));
velocityContext.put("columns", genTable.getColumns());
velocityContext.put("table", genTable);
velocityContext.put("dicts", getDicts(genTable));
velocityContext.put("dataSource", genTable.getDataSource());
velocityContext.put("modlePath", modlePath);
setMenuVelocityContext(velocityContext, genTable);
if (GenConstants.TPL_TREE.equals(tplCategory))
{
... ... @@ -76,7 +79,7 @@ public class VelocityUtils
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
{
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
JSONObject paramsObj = JSON.parseObject(options);
String parentMenuId = getParentMenuId(paramsObj);
context.put("parentMenuId", parentMenuId);
}
... ... @@ -84,7 +87,7 @@ public class VelocityUtils
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
{
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
JSONObject paramsObj = JSON.parseObject(options);
String treeCode = getTreecode(paramsObj);
String treeParentCode = getTreeParentCode(paramsObj);
String treeName = getTreeName(paramsObj);
... ... @@ -123,31 +126,37 @@ public class VelocityUtils
/**
* 获取模板信息
*
* @param tplCategory 生成的模板
* @param tplWebType 前端类型
* @return 模板列表
*/
public static List<String> getTemplateList(String tplCategory)
public static List<String> getTemplateList(String tplCategory, String tplWebType)
{
String useWebType = "vm/vue";
if ("element-plus".equals(tplWebType))
{
useWebType = "vm/vue/v3";
}
List<String> templates = new ArrayList<String>();
templates.add("vm/java/domain.java.vm");
templates.add("vm/java/mapper.java.vm");
templates.add("vm/java/service.java.vm");
templates.add("vm/java/serviceImpl.java.vm");
// templates.add("vm/java/mapper.java.vm");
// templates.add("vm/java/service.java.vm");
// templates.add("vm/java/serviceImpl.java.vm");
templates.add("vm/java/controller.java.vm");
templates.add("vm/xml/mapper.xml.vm");
// templates.add("vm/xml/mapper.xml.vm");
templates.add("vm/sql/sql.vm");
templates.add("vm/js/api.js.vm");
if (GenConstants.TPL_CRUD.equals(tplCategory))
{
templates.add("vm/vue/index.vue.vm");
templates.add(useWebType + "/index.vue.vm");
}
else if (GenConstants.TPL_TREE.equals(tplCategory))
{
templates.add("vm/vue/index-tree.vue.vm");
templates.add(useWebType + "/index-tree.vue.vm");
}
else if (GenConstants.TPL_SUB.equals(tplCategory))
{
templates.add("vm/vue/index.vue.vm");
templates.add(useWebType + "/index.vue.vm");
templates.add("vm/java/sub-domain.java.vm");
}
return templates;
... ... @@ -169,17 +178,20 @@ public class VelocityUtils
// 业务名称
String businessName = genTable.getBusinessName();
//业务项目的路径
String modlePath = genTable.getModlePath();
String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
String mybatisPath = MYBATIS_PATH + "/" + moduleName;
String vuePath = "vue";
if (template.contains("domain.java.vm"))
{
fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
fileName = StringUtils.format("{}/domain/{}/{}.java", javaPath,moduleName, className);
}
if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory()))
{
fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName());
fileName = StringUtils.format("{}/domain/{}/{}.java", javaPath, moduleName,genTable.getSubTable().getClassName());
}
else if (template.contains("mapper.java.vm"))
{
... ... @@ -195,7 +207,7 @@ public class VelocityUtils
}
else if (template.contains("controller.java.vm"))
{
fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
fileName = StringUtils.format("{}/{}/controller/{}/{}Controller.java", javaPath,modlePath,moduleName, className);
}
else if (template.contains("mapper.xml.vm"))
{
... ... @@ -307,9 +319,9 @@ public class VelocityUtils
* @param businessName 业务名称
* @return 返回权限前缀
*/
public static String getPermissionPrefix(String moduleName, String businessName)
public static String getPermissionPrefix(String modlePath,String moduleName, String businessName)
{
return StringUtils.format("{}:{}", moduleName, businessName);
return StringUtils.format("{}:{}:{}",modlePath, moduleName, businessName);
}
/**
... ... @@ -382,7 +394,7 @@ public class VelocityUtils
public static int getExpandColumn(GenTable genTable)
{
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
JSONObject paramsObj = JSON.parseObject(options);
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
int num = 0;
for (GenTableColumn column : genTable.getColumns())
... ...
# 代码生成
gen:
gen:
# 作者
author: ruoyi
author: zhonglai
# 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
packageName: com.ruoyi.system
packageName: com.zhonglai.luhui
# 自动去除表前缀,默认是false
autoRemovePre: false
# # 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
# 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
tablePrefix: sys_
\ No newline at end of file
... ...
... ... @@ -3,7 +3,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.generator.mapper.GenTableColumnMapper">
<resultMap type="GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id" />
<result property="tableId" column="table_id" />
... ... @@ -28,23 +28,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectGenTableColumnVo">
select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column
</sql>
<select id="selectGenTableColumnListByTableId" parameterType="Long" resultMap="GenTableColumnResult">
<include refid="selectGenTableColumnVo"/>
where table_id = #{tableId}
order by sort
</select>
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else '0' end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
order by ordinal_position
</select>
<insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
insert into gen_table_column (
<if test="tableId != null and tableId != ''">table_id,</if>
... ... @@ -88,37 +88,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sysdate()
)
</insert>
<update id="updateGenTableColumn" parameterType="GenTableColumn">
update gen_table_column
<set>
column_comment = #{columnComment},
java_type = #{javaType},
java_field = #{javaField},
is_insert = #{isInsert},
is_edit = #{isEdit},
is_list = #{isList},
is_query = #{isQuery},
is_required = #{isRequired},
query_type = #{queryType},
html_type = #{htmlType},
dict_type = #{dictType},
sort = #{sort},
update_by = #{updateBy},
<if test="columnComment != null">column_comment = #{columnComment},</if>
<if test="javaType != null">java_type = #{javaType},</if>
<if test="javaField != null">java_field = #{javaField},</if>
<if test="isInsert != null">is_insert = #{isInsert},</if>
<if test="isEdit != null">is_edit = #{isEdit},</if>
<if test="isList != null">is_list = #{isList},</if>
<if test="isQuery != null">is_query = #{isQuery},</if>
<if test="isRequired != null">is_required = #{isRequired},</if>
<if test="queryType != null">query_type = #{queryType},</if>
<if test="htmlType != null">html_type = #{htmlType},</if>
<if test="dictType != null">dict_type = #{dictType},</if>
<if test="sort != null">sort = #{sort},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
where column_id = #{columnId}
</update>
<delete id="deleteGenTableColumnByIds" parameterType="Long">
delete from gen_table_column where table_id in
delete from gen_table_column where table_id in
<foreach collection="array" item="tableId" open="(" separator="," close=")">
#{tableId}
</foreach>
</delete>
<delete id="deleteGenTableColumns">
delete from gen_table_column where column_id in
delete from gen_table_column where column_id in
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item.columnId}
</foreach>
... ...
... ... @@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="subTableFkName" column="sub_table_fk_name" />
<result property="className" column="class_name" />
<result property="tplCategory" column="tpl_category" />
<result property="tplWebType" column="tpl_web_type" />
<result property="packageName" column="package_name" />
<result property="moduleName" column="module_name" />
<result property="businessName" column="business_name" />
... ... @@ -54,7 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectGenTableVo">
select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table
select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, tpl_web_type, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table
</sql>
<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
... ... @@ -111,7 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
... ... @@ -119,7 +120,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
... ... @@ -127,7 +128,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark,
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
... ... @@ -140,6 +141,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="tableComment != null and tableComment != ''">table_comment,</if>
<if test="className != null and className != ''">class_name,</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
<if test="tplWebType != null and tplWebType != ''">tpl_web_type,</if>
<if test="packageName != null and packageName != ''">package_name,</if>
<if test="moduleName != null and moduleName != ''">module_name,</if>
<if test="businessName != null and businessName != ''">business_name,</if>
... ... @@ -155,6 +157,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
<if test="className != null and className != ''">#{className},</if>
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
<if test="tplWebType != null and tplWebType != ''">#{tplWebType},</if>
<if test="packageName != null and packageName != ''">#{packageName},</if>
<if test="moduleName != null and moduleName != ''">#{moduleName},</if>
<if test="businessName != null and businessName != ''">#{businessName},</if>
... ... @@ -168,6 +171,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
)
</insert>
<update id="createTable">
${sql}
</update>
<update id="updateGenTable" parameterType="GenTable">
update gen_table
<set>
... ... @@ -180,6 +187,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="genType != null and genType != ''">gen_type = #{genType},</if>
<if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
<if test="tplWebType != null and tplWebType != ''">tpl_web_type = #{tplWebType},</if>
<if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
<if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
... ...
package ${packageName}.controller;
package ${packageName}.${modlePath}.controller.${moduleName};
import java.util.List;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
##import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
... ... @@ -19,9 +20,10 @@ import com.ruoyi.common.annotation.Log;
import com.zhonglai.luhui.action.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import ${packageName}.domain.${ClassName};
import ${packageName}.service.I${ClassName}Service;
##import com.zhonglai.luhui.sys.utils.ExcelUtil;
import com.zhonglai.luhui.dao.service.PublicTemplateService;
import ${packageName}.domain.${moduleName}.${ClassName};
import com.ruoyi.common.utils.poi.ExcelUtil;
#if($table.crud || $table.sub)
import com.ruoyi.common.core.page.TableDataInfo;
#elseif($table.tree)
... ... @@ -35,91 +37,89 @@ import com.ruoyi.common.core.page.TableDataInfo;
*/
@Api(tags = "${functionName}")
@RestController
@RequestMapping("/${moduleName}/${businessName}")
@RequestMapping("/${modlePath}/${moduleName}/${businessName}")
public class ${ClassName}Controller extends BaseController
{
@Autowired
private I${ClassName}Service ${className}Service;
private PublicTemplateService publicTemplateService;
/**
* 查询${functionName}列表
*/
@ApiOperation("查询${functionName}列表")
## @PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')")
@ApiOperation(value ="查询${functionName}列表",notes="\n" +
"公共参数描述:\n" +
"条件参数:\n" +
"timeMap; //时间条件(如:{\"create_time\":[开始时间,结束时间]})\n" +
"keyValue; //模糊匹配的关键字(如:[\"value\",\"name,no\"])\n" +
"queryParams; //字段对应的比较符号(如:{\"id\":\"EQ\"})\n" +
"orderBy; //排序(如:\"id desc,name asc\")\n" +
"\n" +
"分页参数:\n" +
"pageNum; //当前记录起始索引,从1开始\n" +
"pageSize; //每页显示记录数")
@DataSource(DataSourceType.SLAVE)
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')")
@GetMapping("/list")
#if($table.crud || $table.sub)
public TableDataInfo list(${ClassName} ${className})
{
startPage();
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
List<${ClassName}> list = publicTemplateService.selectTList(${className});
return getDataTable(list);
}
#elseif($table.tree)
public AjaxResult list(${ClassName} ${className})
{
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
return AjaxResult.success(list);
List<${ClassName}> list = publicTemplateService.selectTList(${className});
return success(list);
}
#end
## /**
## * 导出${functionName}列表
## */
## @ApiOperation("导出${functionName}列表")
#### @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')")
## @Log(title = "${functionName}", businessType = BusinessType.EXPORT)
## @PostMapping("/export")
## public void export(HttpServletResponse response, ${ClassName} ${className})
## {
## List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
## ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
## util.exportExcel(response, list, "${functionName}数据");
## }
@ApiOperation("导出${functionName}列表")
@DataSource(DataSourceType.SLAVE)
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')")
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, ${ClassName} ${className})
{
List<${ClassName}> list = publicTemplateService.selectTList(${className});
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
util.exportExcel(response, list, "${functionName}数据");
}
/**
* 获取${functionName}详细信息
*/
@ApiOperation("获取${functionName}详细信息")
## @PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')")
@DataSource(DataSourceType.SLAVE)
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')")
@GetMapping(value = "/{${pkColumn.javaField}}")
public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
{
return AjaxResult.success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}));
return success(publicTemplateService.getTById(${pkColumn.javaField}, ${ClassName}.class));
}
/**
* 新增${functionName}
*/
@ApiOperation("新增${functionName}")
## @PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')")
@DataSource(DataSourceType.SLAVE)
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')")
@Log(title = "${functionName}", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ${ClassName} ${className})
{
return toAjax(${className}Service.insert${ClassName}(${className}));
return toAjax(publicTemplateService.add(${className}));
}
/**
* 修改${functionName}
*/
@ApiOperation("修改${functionName}")
## @PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')")
@DataSource(DataSourceType.SLAVE)
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')")
@Log(title = "${functionName}", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ${ClassName} ${className})
{
return toAjax(${className}Service.update${ClassName}(${className}));
return toAjax(publicTemplateService.edit((${className})));
}
/**
* 删除${functionName}
*/
@ApiOperation("删除${functionName}")
## @PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')")
@DataSource(DataSourceType.SLAVE)
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')")
@Log(title = "${functionName}", businessType = BusinessType.DELETE)
@DeleteMapping("/{${pkColumn.javaField}s}")
public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
{
return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s));
return toAjax(publicTemplateService.removeByIds(${ClassName}.class,${pkColumn.javaField}s));
}
}
... ...
package ${packageName}.domain;
package ${packageName}.domain.${moduleName};
#foreach ($import in $importList)
import ${import};
#end
import com.ruoyi.common.annotation.Excel;
#if($table.crud || $table.sub)
#elseif($table.tree)
#end
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.zhonglai.luhui.common.util.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.ruoyi.common.annotation.PublicSQLConfig;
#if($table.crud || $table.sub)
import com.ruoyi.common.tool.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
#elseif($table.tree)
#end
/**
* ${functionName}对象 ${tableName}
... ... @@ -28,32 +27,33 @@ import org.apache.commons.lang3.builder.ToStringStyle;
#end
public class ${ClassName} extends ${Entity}
{
@PublicSQLConfig(isSelect=false)
private static final long serialVersionUID = 1L;
#foreach ($column in $columns)
#if(!$table.isSuperColumn($column.javaField))
#if(!$table.isSuperColumn($column.javaField))
/** $column.columnComment */
@ApiModelProperty("${column.columnComment}")
#if($column.list)
#set($parentheseIndex=$column.columnComment.indexOf("("))
#if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else
#set($comment=$column.columnComment)
#end
#if($parentheseIndex != -1)
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
#elseif($column.javaType == 'Date')
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd")
#else
@Excel(name = "${comment}")
#end
#end
#if($column.list)
#set($parentheseIndex=$column.columnComment.indexOf("("))
#if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else
#set($comment=$column.columnComment)
#end
#if($parentheseIndex != -1)
@ApiModelProperty(value="${comment}",allowableValues="$column.readConverterExp()")
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
#elseif($column.javaType == 'Date')
@JsonFormat(pattern = "yyyy-MM-dd")
@ApiModelProperty(value="${comment}")
@Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd")
#else
@ApiModelProperty(value="${comment}")
@Excel(name = "${comment}")
#end
#end
private $column.javaType $column.javaField;
#end
#end
#end
#if($table.sub)
/** $table.subTable.functionName信息 */
... ...
... ... @@ -7,11 +7,6 @@ import com.ruoyi.common.utils.DateUtils;
#break
#end
#end
#if($dataSource)
import com.zhonglai.luhui.datasource.enums.DataSource;
import com.zhonglai.luhui.datasource.enums.DataSourceType;
#end
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
#if($table.sub)
... ... @@ -42,9 +37,6 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
* @param ${pkColumn.javaField} ${functionName}主键
* @return ${functionName}
*/
#if($dataSource)
@DataSource(${dataSource})
#end
@Override
public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField})
{
... ... @@ -57,9 +49,6 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
* @param ${className} ${functionName}
* @return ${functionName}
*/
#if($dataSource)
@DataSource(${dataSource})
#end
@Override
public List<${ClassName}> select${ClassName}List(${ClassName} ${className})
{
... ... @@ -72,9 +61,6 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
* @param ${className} ${functionName}
* @return 结果
*/
#if($dataSource)
@DataSource(${dataSource})
#end
#if($table.sub)
@Transactional
#end
... ... @@ -101,9 +87,6 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
* @param ${className} ${functionName}
* @return 结果
*/
#if($dataSource)
@DataSource(${dataSource})
#end
#if($table.sub)
@Transactional
#end
... ... @@ -128,9 +111,6 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
* @param ${pkColumn.javaField}s 需要删除的${functionName}主键
* @return 结果
*/
#if($dataSource)
@DataSource(${dataSource})
#end
#if($table.sub)
@Transactional
#end
... ... @@ -149,9 +129,6 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
* @param ${pkColumn.javaField} ${functionName}主键
* @return 结果
*/
#if($dataSource)
@DataSource(${dataSource})
#end
#if($table.sub)
@Transactional
#end
... ... @@ -170,9 +147,6 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
*
* @param ${className} ${functionName}对象
*/
#if($dataSource)
@DataSource(${dataSource})
#end
public void insert${subClassName}(${ClassName} ${className})
{
List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List();
... ...
... ... @@ -3,8 +3,10 @@ package ${packageName}.domain;
#foreach ($import in $subImportList)
import ${import};
#end
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.PublicSQLConfig;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.zhonglai.luhui.common.util.annotation.Excel;
import com.ruoyi.common.tool.BaseEntity;
/**
* ${subTable.functionName}对象 ${subTableName}
... ... @@ -14,7 +16,6 @@ import com.ruoyi.common.annotation.PublicSQLConfig;
*/
public class ${subClassName} extends BaseEntity
{
@PublicSQLConfig(isSelect=false)
private static final long serialVersionUID = 1L;
#foreach ($column in $subTable.columns)
... ...
... ... @@ -3,7 +3,7 @@ import request from '@/utils/request'
// 查询${functionName}列表
export function list${BusinessName}(query) {
return request({
url: '/${moduleName}/${businessName}/list',
url: '/${modlePath}/${moduleName}/${businessName}/list',
method: 'get',
params: query
})
... ... @@ -12,7 +12,7 @@ export function list${BusinessName}(query) {
// 查询${functionName}详细
export function get${BusinessName}(${pkColumn.javaField}) {
return request({
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
url: '/${modlePath}/${moduleName}/${businessName}/' + ${pkColumn.javaField},
method: 'get'
})
}
... ... @@ -20,7 +20,7 @@ export function get${BusinessName}(${pkColumn.javaField}) {
// 新增${functionName}
export function add${BusinessName}(data) {
return request({
url: '/${moduleName}/${businessName}',
url: '/${modlePath}/${moduleName}/${businessName}',
method: 'post',
data: data
})
... ... @@ -29,7 +29,7 @@ export function add${BusinessName}(data) {
// 修改${functionName}
export function update${BusinessName}(data) {
return request({
url: '/${moduleName}/${businessName}',
url: '/${modlePath}/${moduleName}/${businessName}',
method: 'put',
data: data
})
... ... @@ -38,7 +38,7 @@ export function update${BusinessName}(data) {
// 删除${functionName}
export function del${BusinessName}(${pkColumn.javaField}) {
return request({
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
url: '/${modlePath}/${moduleName}/${businessName}/' + ${pkColumn.javaField},
method: 'delete'
})
}
... ...
-- 菜单 SQL
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', sysdate(), '', null, '${functionName}菜单');
values('${functionName}', 2006, '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', sysdate(), '', null, '${functionName}菜单');
-- 按钮父菜单ID
SELECT @parentId := LAST_INSERT_ID();
... ...
... ... @@ -75,7 +75,7 @@
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['${moduleName}:${businessName}:add']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
... ... @@ -144,21 +144,21 @@
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:edit']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-plus"
@click="handleAdd(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:add']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:add']"
>新增</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:remove']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:remove']"
>删除</el-button>
</template>
</el-table-column>
... ... @@ -187,11 +187,11 @@
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
</el-form-item>
#elseif($column.htmlType == "imageUpload")
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<image-upload v-model="form.${field}"/>
</el-form-item>
#elseif($column.htmlType == "fileUpload")
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<file-upload v-model="form.${field}"/>
</el-form-item>
#elseif($column.htmlType == "editor")
... ... @@ -205,8 +205,11 @@
v-for="dict in dict.type.${dictType}"
:key="dict.value"
:label="dict.label"
#if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end
#if($column.javaType == "Integer" || $column.javaType == "Long")
:value="parseInt(dict.value)"
#else
:value="dict.value"
#end
></el-option>
</el-select>
</el-form-item>
... ... @@ -217,7 +220,7 @@
</el-select>
</el-form-item>
#elseif($column.htmlType == "checkbox" && "" != $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-checkbox-group v-model="form.${field}">
<el-checkbox
v-for="dict in dict.type.${dictType}"
... ... @@ -228,24 +231,27 @@
</el-checkbox-group>
</el-form-item>
#elseif($column.htmlType == "checkbox" && $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-checkbox-group v-model="form.${field}">
<el-checkbox>请选择字典生成</el-checkbox>
</el-checkbox-group>
</el-form-item>
#elseif($column.htmlType == "radio" && "" != $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-radio-group v-model="form.${field}">
<el-radio
v-for="dict in dict.type.${dictType}"
:key="dict.value"
#if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end
#if($column.javaType == "Integer" || $column.javaType == "Long")
:label="parseInt(dict.value)"
#else
:label="dict.value"
#end
>{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
#elseif($column.htmlType == "radio" && $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-radio-group v-model="form.${field}">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
... ... @@ -335,7 +341,7 @@ export default {
#set($comment=$column.columnComment)
#end
$column.javaField: [
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
]#if($foreach.count != $columns.size()),#end
#end
#end
... ... @@ -398,10 +404,7 @@ export default {
reset() {
this.form = {
#foreach ($column in $columns)
#if($column.htmlType == "radio")
$column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($foreach.count != $columns.size()),#end
#elseif($column.htmlType == "checkbox")
#if($column.htmlType == "checkbox")
$column.javaField: []#if($foreach.count != $columns.size()),#end
#else
$column.javaField: null#if($foreach.count != $columns.size()),#end
... ... @@ -450,7 +453,7 @@ export default {
this.reset();
this.getTreeselect();
if (row != null) {
this.form.${treeParentCode} = row.${treeCode};
this.form.${treeParentCode} = row.${treeParentCode};
}
get${BusinessName}(row.${pkColumn.javaField}).then(response => {
this.form = response.data;
... ...
... ... @@ -75,7 +75,7 @@
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['${moduleName}:${businessName}:add']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
... ... @@ -86,7 +86,7 @@
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['${moduleName}:${businessName}:edit']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
... ... @@ -97,7 +97,7 @@
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['${moduleName}:${businessName}:remove']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
... ... @@ -107,7 +107,7 @@
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['${moduleName}:${businessName}:export']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
... ... @@ -158,14 +158,14 @@
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:edit']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:remove']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:remove']"
>删除</el-button>
</template>
</el-table-column>
... ... @@ -198,11 +198,11 @@
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
</el-form-item>
#elseif($column.htmlType == "imageUpload")
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<image-upload v-model="form.${field}"/>
</el-form-item>
#elseif($column.htmlType == "fileUpload")
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<file-upload v-model="form.${field}"/>
</el-form-item>
#elseif($column.htmlType == "editor")
... ... @@ -216,8 +216,11 @@
v-for="dict in dict.type.${dictType}"
:key="dict.value"
:label="dict.label"
#if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end
#if($column.javaType == "Integer" || $column.javaType == "Long")
:value="parseInt(dict.value)"
#else
:value="dict.value"
#end
></el-option>
</el-select>
</el-form-item>
... ... @@ -228,7 +231,7 @@
</el-select>
</el-form-item>
#elseif($column.htmlType == "checkbox" && "" != $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-checkbox-group v-model="form.${field}">
<el-checkbox
v-for="dict in dict.type.${dictType}"
... ... @@ -239,24 +242,27 @@
</el-checkbox-group>
</el-form-item>
#elseif($column.htmlType == "checkbox" && $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-checkbox-group v-model="form.${field}">
<el-checkbox>请选择字典生成</el-checkbox>
</el-checkbox-group>
</el-form-item>
#elseif($column.htmlType == "radio" && "" != $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-radio-group v-model="form.${field}">
<el-radio
v-for="dict in dict.type.${dictType}"
:key="dict.value"
#if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end
#if($column.javaType == "Integer" || $column.javaType == "Long")
:label="parseInt(dict.value)"
#else
:label="dict.value"
#end
>{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
#elseif($column.htmlType == "radio" && $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-radio-group v-model="form.${field}">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
... ... @@ -412,7 +418,7 @@ export default {
#set($comment=$column.columnComment)
#end
$column.javaField: [
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
]#if($foreach.count != $columns.size()),#end
#end
#end
... ... @@ -456,9 +462,7 @@ export default {
reset() {
this.form = {
#foreach ($column in $columns)
#if($column.htmlType == "radio")
$column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($foreach.count != $columns.size()),#end
#elseif($column.htmlType == "checkbox")
#if($column.htmlType == "checkbox")
$column.javaField: []#if($foreach.count != $columns.size()),#end
#else
$column.javaField: null#if($foreach.count != $columns.size()),#end
... ... @@ -589,7 +593,7 @@ export default {
#end
/** 导出按钮操作 */
handleExport() {
this.download('${moduleName}/${businessName}/export', {
this.download('${modlePath}/${moduleName}/${businessName}/export', {
...this.queryParams
}, `${businessName}_#[[${new Date().getTime()}]]#.xlsx`)
}
... ...
... ... @@ -73,7 +73,7 @@
plain
icon="Plus"
@click="handleAdd"
v-hasPermi="['${moduleName}:${businessName}:add']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
... ... @@ -136,24 +136,9 @@
#end
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button
type="text"
icon="Edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:edit']"
>修改</el-button>
<el-button
type="text"
icon="Plus"
@click="handleAdd(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:add']"
>新增</el-button>
<el-button
type="text"
icon="Delete"
@click="handleDelete(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:remove']"
>删除</el-button>
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['${modlePath}:${moduleName}:${businessName}:edit']">修改</el-button>
<el-button link type="primary" icon="Plus" @click="handleAdd(scope.row)" v-hasPermi="['${modlePath}:${moduleName}:${businessName}:add']">新增</el-button>
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['${modlePath}:${moduleName}:${businessName}:remove']">删除</el-button>
</template>
</el-table-column>
</el-table>
... ... @@ -174,11 +159,13 @@
#set($dictType=$column.dictType)
#if("" != $treeParentCode && $column.javaField == $treeParentCode)
<el-form-item label="${comment}" prop="${treeParentCode}">
<tree-select
v-model:value="form.${treeParentCode}"
:options="${businessName}Options"
:objMap="{ value: '${treeCode}', label: '${treeName}', children: 'children' }"
<el-tree-select
v-model="form.${treeParentCode}"
:data="${businessName}Options"
:props="{ value: '${treeCode}', label: '${treeName}', children: 'children' }"
value-key="${treeCode}"
placeholder="请选择${comment}"
check-strictly
/>
</el-form-item>
#elseif($column.htmlType == "input")
... ... @@ -186,11 +173,11 @@
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
</el-form-item>
#elseif($column.htmlType == "imageUpload")
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<image-upload v-model="form.${field}"/>
</el-form-item>
#elseif($column.htmlType == "fileUpload")
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<file-upload v-model="form.${field}"/>
</el-form-item>
#elseif($column.htmlType == "editor")
... ... @@ -204,8 +191,11 @@
v-for="dict in ${dictType}"
:key="dict.value"
:label="dict.label"
#if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end
#if($column.javaType == "Integer" || $column.javaType == "Long")
:value="parseInt(dict.value)"
#else
:value="dict.value"
#end
></el-option>
</el-select>
</el-form-item>
... ... @@ -216,7 +206,7 @@
</el-select>
</el-form-item>
#elseif($column.htmlType == "checkbox" && "" != $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-checkbox-group v-model="form.${field}">
<el-checkbox
v-for="dict in ${dictType}"
... ... @@ -227,24 +217,27 @@
</el-checkbox-group>
</el-form-item>
#elseif($column.htmlType == "checkbox" && $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-checkbox-group v-model="form.${field}">
<el-checkbox>请选择字典生成</el-checkbox>
</el-checkbox-group>
</el-form-item>
#elseif($column.htmlType == "radio" && "" != $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-radio-group v-model="form.${field}">
<el-radio
v-for="dict in ${dictType}"
:key="dict.value"
#if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end
#if($column.javaType == "Integer" || $column.javaType == "Long")
:label="parseInt(dict.value)"
#else
:label="dict.value"
#end
>{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
#elseif($column.htmlType == "radio" && $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-radio-group v-model="form.${field}">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
... ... @@ -320,7 +313,7 @@ const data = reactive({
#set($comment=$column.columnComment)
#end
$column.javaField: [
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
]#if($foreach.count != $columns.size()),#end
#end
#end
... ... @@ -354,8 +347,8 @@ function getList() {
}
/** 查询${functionName}下拉树结构 */
async function getTreeselect() {
await list${BusinessName}().then(response => {
function getTreeselect() {
list${BusinessName}().then(response => {
${businessName}Options.value = [];
const data = { ${treeCode}: 0, ${treeName}: '顶级节点', children: [] };
data.children = proxy.handleTree(response.data, "${treeCode}", "${treeParentCode}");
... ... @@ -373,10 +366,7 @@ function cancel() {
function reset() {
form.value = {
#foreach ($column in $columns)
#if($column.htmlType == "radio")
$column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($foreach.count != $columns.size()),#end
#elseif($column.htmlType == "checkbox")
#if($column.htmlType == "checkbox")
$column.javaField: []#if($foreach.count != $columns.size()),#end
#else
$column.javaField: null#if($foreach.count != $columns.size()),#end
... ... @@ -404,9 +394,9 @@ function resetQuery() {
}
/** 新增按钮操作 */
async function handleAdd(row) {
function handleAdd(row) {
reset();
await getTreeselect();
getTreeselect();
if (row != null && row.${treeCode}) {
form.value.${treeParentCode} = row.${treeCode};
} else {
... ... @@ -430,7 +420,7 @@ async function handleUpdate(row) {
reset();
await getTreeselect();
if (row != null) {
form.value.${treeParentCode} = row.${treeCode};
form.value.${treeParentCode} = row.${treeParentCode};
}
get${BusinessName}(row.${pkColumn.javaField}).then(response => {
form.value = response.data;
... ...
... ... @@ -73,7 +73,7 @@
plain
icon="Plus"
@click="handleAdd"
v-hasPermi="['${moduleName}:${businessName}:add']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
... ... @@ -83,7 +83,7 @@
icon="Edit"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['${moduleName}:${businessName}:edit']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
... ... @@ -93,7 +93,7 @@
icon="Delete"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['${moduleName}:${businessName}:remove']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
... ... @@ -102,7 +102,7 @@
plain
icon="Download"
@click="handleExport"
v-hasPermi="['${moduleName}:${businessName}:export']"
v-hasPermi="['${modlePath}:${moduleName}:${businessName}:export']"
>导出</el-button>
</el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
... ... @@ -148,18 +148,8 @@
#end
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button
type="text"
icon="Edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:edit']"
>修改</el-button>
<el-button
type="text"
icon="Delete"
@click="handleDelete(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:remove']"
>删除</el-button>
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['${modlePath}:${moduleName}:${businessName}:edit']">修改</el-button>
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['${modlePath}:${moduleName}:${businessName}:remove']">删除</el-button>
</template>
</el-table-column>
</el-table>
... ... @@ -191,11 +181,11 @@
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
</el-form-item>
#elseif($column.htmlType == "imageUpload")
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<image-upload v-model="form.${field}"/>
</el-form-item>
#elseif($column.htmlType == "fileUpload")
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<file-upload v-model="form.${field}"/>
</el-form-item>
#elseif($column.htmlType == "editor")
... ... @@ -209,8 +199,11 @@
v-for="dict in ${dictType}"
:key="dict.value"
:label="dict.label"
#if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end
#if($column.javaType == "Integer" || $column.javaType == "Long")
:value="parseInt(dict.value)"
#else
:value="dict.value"
#end
></el-option>
</el-select>
</el-form-item>
... ... @@ -221,7 +214,7 @@
</el-select>
</el-form-item>
#elseif($column.htmlType == "checkbox" && "" != $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-checkbox-group v-model="form.${field}">
<el-checkbox
v-for="dict in ${dictType}"
... ... @@ -232,24 +225,27 @@
</el-checkbox-group>
</el-form-item>
#elseif($column.htmlType == "checkbox" && $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-checkbox-group v-model="form.${field}">
<el-checkbox>请选择字典生成</el-checkbox>
</el-checkbox-group>
</el-form-item>
#elseif($column.htmlType == "radio" && "" != $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-radio-group v-model="form.${field}">
<el-radio
v-for="dict in ${dictType}"
:key="dict.value"
#if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end
#if($column.javaType == "Integer" || $column.javaType == "Long")
:label="parseInt(dict.value)"
#else
:label="dict.value"
#end
>{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
#elseif($column.htmlType == "radio" && $dictType)
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${field}">
<el-radio-group v-model="form.${field}">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
... ... @@ -398,7 +394,7 @@ const data = reactive({
#set($comment=$column.columnComment)
#end
$column.javaField: [
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
]#if($foreach.count != $columns.size()),#end
#end
#end
... ... @@ -442,9 +438,7 @@ function cancel() {
function reset() {
form.value = {
#foreach ($column in $columns)
#if($column.htmlType == "radio")
$column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($foreach.count != $columns.size()),#end
#elseif($column.htmlType == "checkbox")
#if($column.htmlType == "checkbox")
$column.javaField: []#if($foreach.count != $columns.size()),#end
#else
$column.javaField: null#if($foreach.count != $columns.size()),#end
... ... @@ -492,8 +486,8 @@ function handleAdd() {
/** 修改按钮操作 */
function handleUpdate(row) {
reset();
const ${pkColumn.javaField} = row.${pkColumn.javaField} || ids.value
get${BusinessName}(${pkColumn.javaField}).then(response => {
const _${pkColumn.javaField} = row.${pkColumn.javaField} || ids.value
get${BusinessName}(_${pkColumn.javaField}).then(response => {
form.value = response.data;
#foreach ($column in $columns)
#if($column.htmlType == "checkbox")
... ... @@ -539,9 +533,9 @@ function submitForm() {
/** 删除按钮操作 */
function handleDelete(row) {
const ${pkColumn.javaField}s = row.${pkColumn.javaField} || ids.value;
proxy.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?').then(function() {
return del${BusinessName}(${pkColumn.javaField}s);
const _${pkColumn.javaField}s = row.${pkColumn.javaField} || ids.value;
proxy.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + _${pkColumn.javaField}s + '"的数据项?').then(function() {
return del${BusinessName}(_${pkColumn.javaField}s);
}).then(() => {
getList();
proxy.#[[$modal]]#.msgSuccess("删除成功");
... ... @@ -587,7 +581,7 @@ function handle${subClassName}SelectionChange(selection) {
#end
/** 导出按钮操作 */
function handleExport() {
proxy.download('${moduleName}/${businessName}/export', {
proxy.download('${modlePath}/${moduleName}/${businessName}/export', {
...queryParams.value
}, `${businessName}_#[[${new Date().getTime()}]]#.xlsx`)
}
... ...
... ... @@ -23,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#end
<sql id="select${ClassName}Vo">
select#foreach($column in $columns) `$column.columnName`#if($foreach.count != $columns.size()),#end#end from ${tableName}
select#foreach($column in $columns) $column.columnName#if($foreach.count != $columns.size()),#end#end from ${tableName}
</sql>
<select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}Result">
... ... @@ -77,7 +77,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="(" suffix=")" suffixOverrides=",">
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">`$column.columnName`,</if>
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName,</if>
#end
#end
</trim>
... ... @@ -95,7 +95,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=",">
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName)
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">`$column.columnName` = #{$column.javaField},</if>
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if>
#end
#end
</trim>
... ...
... ... @@ -146,7 +146,7 @@ public class BaseController
/**
* 返回成功消息
*/
public AjaxResult success(String message)
public AjaxResult success(Object message)
{
return AjaxResult.success(message);
}
... ...
... ... @@ -59,7 +59,6 @@ public class IotProduct implements Serializable
@ApiModelProperty("产品名称")
private String product_name;
@ApiModelProperty("是否需要同步数据库(0否,1是)")
private Integer is_sync_db;
... ... @@ -72,6 +71,17 @@ public class IotProduct implements Serializable
@ApiModelProperty("清洗服务")
private Integer purification_clas; // varchar(100) DEFAULT 'com.zhonglai.luhui.device.protocol.factory.purification.DefaultProtocolPurificationFactoryImpl' COMMENT '清洗服务',
@ApiModelProperty("订阅服务器id")
private Integer subscribe_service_ip;
public Integer getSubscribe_service_ip() {
return subscribe_service_ip;
}
public void setSubscribe_service_ip(Integer subscribe_service_ip) {
this.subscribe_service_ip = subscribe_service_ip;
}
public Integer getPurification_clas() {
return purification_clas;
}
... ...
package com.zhonglai.luhui.device.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.ruoyi.common.tool.BaseEntity;
/**
* 产品类型对象 iot_product_type
*
* @author zhonglai
* @date 2024-06-26
*/
@ApiModel("产品类型")
public class IotProductType extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
private Integer id;
/** 类型名称 */
@ApiModelProperty(value="类型名称")
private String name;
/** 关联的产品id */
@ApiModelProperty(value="关联的产品id")
private Integer productId;
public void setId(Integer id)
{
this.id = id;
}
public Integer getId()
{
return id;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setProductId(Integer productId)
{
this.productId = productId;
}
public Integer getProductId()
{
return productId;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("name", getName())
.append("productId", getProductId())
.append("createTime", getCreateTime())
.toString();
}
}
... ...
... ... @@ -44,7 +44,31 @@ public class IotProtocolClass extends BaseEntity
@ApiModelProperty("创建时间")
private String create_time;
public void setId(Integer id)
/** 类名 */
@ApiModelProperty("订阅的topic")
private String sub_topics;
/** 类名 */
@ApiModelProperty("协议地址")
private String protocol_url;
public String getSub_topics() {
return sub_topics;
}
public void setSub_topics(String sub_topics) {
this.sub_topics = sub_topics;
}
public String getProtocol_url() {
return protocol_url;
}
public void setProtocol_url(String protocol_url) {
this.protocol_url = protocol_url;
}
public void setId(Integer id)
{
this.id = id;
}
... ...
... ... @@ -20,10 +20,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="sync_db" column="sync_db" />
<result property="analysis_clas" column="analysis_clas" />
<result property="purification_clas" column="purification_clas" />
<result property="subscribe_service_ip" column="subscribe_service_ip" />
</resultMap>
<sql id="selectIotProductVo">
select `id`,`mqtt_username`,`mqtt_password`,`product_name`,`mqtt_salt`,`create_time`,`encryption_type`,`open_encryption`,`used`,`role_id`,`is_sync_db`,`sync_db`,`analysis_clas`,`purification_clas` from iot_product
select `id`,`mqtt_username`,`mqtt_password`,`product_name`,`mqtt_salt`,`create_time`,`encryption_type`,`open_encryption`,`used`,`role_id`,`is_sync_db`,`sync_db`,`analysis_clas`,`purification_clas`,`subscribe_service_ip` from iot_product
</sql>
<select id="selectIotProductList" parameterType="IotProduct" resultMap="IotProductResult">
... ... @@ -38,6 +39,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="mqtt_username != null and mqtt_username != ''">
AND `mqtt_username` like concat('%', #{mqtt_username}, '%')
</if>
<if test="subscribe_service_ip != null and subscribe_service_ip != ''">
AND `subscribe_service_ip` like concat('%', #{subscribe_service_ip}, '%')
</if>
</where>
</select>
... ...
... ... @@ -11,10 +11,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="case_model" column="case_model" />
<result property="classname" column="classname" />
<result property="create_time" column="create_time" />
<result property="sub_topics" column="sub_topics" />
<result property="protocol_url" column="protocol_url" />
</resultMap>
<sql id="selectIotProtocolClassVo">
select `id`, `type`, `name`, `case_model`, `classname`, `create_time` from iot_protocol_class
select `id`, `type`, `name`, `case_model`, `classname`, `create_time`,`sub_topics`,`protocol_url` from iot_protocol_class
</sql>
<select id="selectIotProtocolClassList" parameterType="IotProtocolClass" resultMap="IotProtocolClassResult">
... ... @@ -40,6 +42,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="case_model != null">`case_model`,</if>
<if test="classname != null">`classname`,</if>
<if test="create_time != null">`create_time`,</if>
<if test="sub_topics != null">`sub_topics`,</if>
<if test="protocol_url != null">`protocol_url`,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="type != null">#{type},</if>
... ... @@ -47,6 +51,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="case_model != null">#{case_model},</if>
<if test="classname != null">#{classname},</if>
<if test="create_time != null">#{create_time},</if>
<if test="sub_topics != null">#{sub_topics},</if>
<if test="protocol_url != null">#{protocol_url},</if>
</trim>
</insert>
... ... @@ -58,6 +64,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="case_model != null">`case_model` = #{case_model},</if>
<if test="classname != null">`classname` = #{classname},</if>
<if test="create_time != null">`create_time` = #{create_time},</if>
<if test="sub_topics != null">`sub_topics` = #{sub_topics},</if>
<if test="protocol_url != null">`protocol_url` = #{protocol_url},</if>
</trim>
where id = #{id}
</update>
... ...
package com.zhonglai.luhui.admin.controller.iot;
import javax.servlet.http.HttpServletResponse;
import com.zhonglai.luhui.sys.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.zhonglai.luhui.action.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zhonglai.luhui.dao.service.PublicTemplateService;
import com.zhonglai.luhui.device.domain.IotProductType;
import com.ruoyi.common.core.page.TableDataInfo;
import java.util.List;
/**
* 产品类型Controller
*
* @author zhonglai
* @date 2024-06-26
*/
@Api(tags = "产品类型")
@RestController
@RequestMapping("/com.zhonglai.luhui.admin/iot/product_type")
public class IotProductTypeController extends BaseController
{
@Autowired
private PublicTemplateService publicTemplateService;
@ApiOperation(value ="查询产品类型列表",notes="\n" +
"公共参数描述:\n" +
"条件参数:\n" +
"timeMap; //时间条件(如:{\"create_time\":[开始时间,结束时间]})\n" +
"keyValue; //模糊匹配的关键字(如:[\"value\",\"name,no\"])\n" +
"queryParams; //字段对应的比较符号(如:{\"id\":\"EQ\"})\n" +
"orderBy; //排序(如:\"id desc,name asc\")\n" +
"\n" +
"分页参数:\n" +
"pageNum; //当前记录起始索引,从1开始\n" +
"pageSize; //每页显示记录数")
@PreAuthorize("@ss.hasPermi('com.zhonglai.luhui.admin:iot:product_type:list')")
@GetMapping("/list")
public TableDataInfo list(IotProductType iotProductType)
{
startPage();
List<IotProductType> list = publicTemplateService.selectTList(iotProductType);
return getDataTable(list);
}
@ApiOperation("导出产品类型列表")
@PreAuthorize("@ss.hasPermi('com.zhonglai.luhui.admin:iot:product_type:export')")
@Log(title = "产品类型", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, IotProductType iotProductType)
{
List<IotProductType> list = publicTemplateService.selectTList(iotProductType);
ExcelUtil<IotProductType> util = new ExcelUtil<IotProductType>(IotProductType.class);
util.exportExcel(response, list, "产品类型数据");
}
@ApiOperation("获取产品类型详细信息")
@PreAuthorize("@ss.hasPermi('com.zhonglai.luhui.admin:iot:product_type:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Integer id)
{
return success(publicTemplateService.getTById(id, IotProductType.class));
}
@ApiOperation("新增产品类型")
@PreAuthorize("@ss.hasPermi('com.zhonglai.luhui.admin:iot:product_type:add')")
@Log(title = "产品类型", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody IotProductType iotProductType)
{
return toAjax(publicTemplateService.add(iotProductType));
}
@ApiOperation("修改产品类型")
@PreAuthorize("@ss.hasPermi('com.zhonglai.luhui.admin:iot:product_type:edit')")
@Log(title = "产品类型", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody IotProductType iotProductType)
{
return toAjax(publicTemplateService.edit((iotProductType)));
}
@ApiOperation("删除产品类型")
@PreAuthorize("@ss.hasPermi('com.zhonglai.luhui.admin:iot:product_type:remove')")
@Log(title = "产品类型", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Integer[] ids)
{
return toAjax(publicTemplateService.removeByIds(IotProductType.class,ids));
}
}
... ...
... ... @@ -189,6 +189,7 @@ public class IotThingsModelController extends BaseController
iotThingsModel.setMqtt_username(iotProduct.getMqtt_username());
terminalDataThingsModeService.saveIotThingsModel(JSON.parseObject(JSONObject.toJSONString(iotThingsModel),IotThingsModel.class));
return toAjax(ri);
}
... ...
package com.zhonglai.luhui.admin.controller.system;
import com.zhonglai.luhui.admin.service.LuhuiGenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Api(tags = "禄辉代码生成管理")
@RestController
@RequestMapping("/admin/luhuiGen")
public class LuhuiGenController {
@Autowired
private LuhuiGenService luhuiGenService;
/**
* 批量生成代码
*/
@ApiOperation( "代码生成")
@ApiImplicitParams({
@ApiImplicitParam(name = "databaseName", value = "数据库名称",required = true),
@ApiImplicitParam(name = "tableNmaes", value = "表名集合")
})
@GetMapping("/batchGenCode/{databaseName}")
public void generatorCodeFromDatabase(HttpServletResponse response, @PathVariable("databaseName") String databaseName,String modlePath,String tableNmaes) throws IOException
{
byte[] data = luhuiGenService.generatorCodeFromDb(databaseName,modlePath,tableNmaes);
genCode(response, data);
}
/**
* 生成zip文件
*/
private void genCode(HttpServletResponse response, byte[] data) throws IOException
{
response.reset();
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream());
}
}
... ...
package com.zhonglai.luhui.admin.service;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.generator.domain.GenTableColumn;
import com.ruoyi.generator.service.GenTableServiceImpl;
import com.ruoyi.generator.util.GenUtils;
import com.zhonglai.luhui.dao.service.PublicService;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipOutputStream;
@Service
public class LuhuiGenService {
@Autowired
private PublicService publicService;
@Autowired
private GenTableServiceImpl genTableService;
public byte[] generatorCodeFromDb(String databaseName,String modlePath,String tableNmaes)
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
// 查询表信息
List<GenTable> tables = fromDBNameToGenTables(databaseName,modlePath,tableNmaes);
for (GenTable table:tables)
{
genTableService.generatorCode(table, zip);
}
IOUtils.closeQuietly(zip);
return outputStream.toByteArray();
}
private static List<String> findClassesInPackage(String packageName) throws ClassNotFoundException, IOException {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
String path = packageName.replace('.', '/');
Enumeration<URL> resources = classLoader.getResources(path);
List<String> classNames = new ArrayList<>();
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
classNames.addAll(findClasses(new File(resource.getFile()), packageName));
}
return classNames;
}
private static List<String> findClasses(File directory, String packageName) throws ClassNotFoundException, IOException {
List<String> classNames = new ArrayList<>();
if (!directory.exists()) {
return classNames;
}
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
// 如果是目录,递归调用findClasses方法
classNames.addAll(findClasses(file, packageName + "." + file.getName()));
} else if (file.getName().endsWith(".class")) {
// 如果是.class文件,提取类名
String className = packageName + '.' + file.getName().substring(0, file.getName().length() - 6);
try {
Class.forName(className);
classNames.add(className.substring(className.lastIndexOf(".")+1));
} catch (ClassNotFoundException e) {
// 忽略找不到的类,可能是一个编译后的.class文件而没有对应的源代码
}
}
}
}
return classNames;
}
private List<GenTable> fromDBNameToGenTables(String dbName,String modlePath,String tableNmaes) {
String tableWhere = "";
if (StringUtils.isNotEmpty(tableNmaes)) {
tableWhere = " and TABLE_NAME in ('" + tableNmaes.replace(",", "','") + "')";
}
List<Map<String, Object>> list = publicService.getObjectListBySQL("SELECT TABLE_NAME, TABLE_COMMENT, CREATE_TIME, UPDATE_TIME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '" + dbName + "'" + tableWhere);
if (null != list && list.size() != 0) {
List<String> classNames = new ArrayList<>();
try {
classNames = findClassesInPackage("com.zhonglai.luhui.domain");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
List<GenTable> listGenTable = new ArrayList<>();
for (Map<String, Object> map : list) {
GenTable table = JSONObject.parseObject(JSONObject.toJSONString(map), GenTable.class);
String tableName = table.getTableName();
String className = GenUtils.convertClassName(tableName);
// if (StringUtils.isEmpty(tableNmaes) && classNames.contains(className)) {
// continue;
// }
GenUtils.initTable(table, "钟来");
table.setModlePath(modlePath);
String moduleName = tableName.split("_")[0];
table.setPackageName("com.zhonglai.luhui");
table.setModuleName(moduleName);
table.setTplCategory("crud");
table.setGenPath("/");
table.setGenType("0");
List<Map<String, Object>> columnlist = publicService.getObjectListBySQL("SELECT column_name, (CASE WHEN (is_nullable = 'no' && column_key != 'PRI') THEN '1' ELSE '0' END) AS is_required, (CASE WHEN column_key = 'PRI' THEN '1' ELSE '0' END) AS is_pk, ordinal_position AS sort, column_comment, (CASE WHEN extra = 'auto_increment' THEN '1' ELSE '0' END) AS is_increment, column_type\n" +
"\t\tFROM information_schema.columns WHERE table_schema = '" + dbName + "' AND table_name = '" + tableName + "'\n" +
"\t\tORDER BY ordinal_position");
List<GenTableColumn> columns = new ArrayList<>();
for (Map<String, Object> columnMap : columnlist) {
GenTableColumn column = JSONObject.parseObject(JSONObject.toJSONString(columnMap), GenTableColumn.class);
GenUtils.initColumnField(column, table);
if (StringUtils.isEmpty(column.getDictType())) {
column.setDictType("");
if (StringUtils.isEmpty(column.getQueryType())) {
column.setQueryType("EQ");
}
columns.add(column);
}
table.setColumns(columns);
}
listGenTable.add(table);
}
return listGenTable;
}
return null;
}
}
... ...