Skip to content

Commit

Permalink
Merge pull request #2 from enilu/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
enilu authored Aug 22, 2019
2 parents f0bf45f + 0e17fe5 commit 7f40e6c
Show file tree
Hide file tree
Showing 67 changed files with 2,209 additions and 180 deletions.
5 changes: 5 additions & 0 deletions material-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

<artifactId>material-core</artifactId>
<dependencies>
<dependency>
<groupId>cn.enilu</groupId>
<artifactId>material-generator</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package cn.enilu.material.bean.entity.test;


import cn.enilu.material.bean.entity.BaseEntity;
import lombok.Data;
import org.hibernate.annotations.Table;

import javax.persistence.Column;
import javax.persistence.Entity;

/**
* 该实体用于测试生成代码
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package cn.enilu.material.bean.exception;

/**
* 封装guns的异常
* 封装异常
*
* @author fengshuonan
* @Date 2017/12/28 下午10:32
*/
public class GunsException extends RuntimeException {
public class ApplicationException extends RuntimeException {

private Integer code;

private String message;

public GunsException(ServiceExceptionEnum serviceExceptionEnum) {
public ApplicationException(ServiceExceptionEnum serviceExceptionEnum) {
this.code = serviceExceptionEnum.getCode();
this.message = serviceExceptionEnum.getMessage();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package cn.enilu.material.bean.exception;

/**
* Guns异常枚举
* 异常枚举
*
* @author fengshuonan
* @Date 2017/12/28 下午10:33
*/
public enum GunsExceptionEnum implements ServiceExceptionEnum{
public enum ExceptionEnum implements ServiceExceptionEnum{

/**
* 其他
Expand All @@ -27,7 +27,7 @@ public enum GunsExceptionEnum implements ServiceExceptionEnum{

TASK_CONFIG_ERROR(500, "定时任务配置错误");

GunsExceptionEnum(int code, String message) {
ExceptionEnum(int code, String message) {
this.code = code;
this.message = message;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ZTreeNode {
private Long id; //节点id

private Long pId;//父节点id
private String code;//编号

private String name;//节点名称

Expand Down Expand Up @@ -77,13 +78,22 @@ public void setNodeData(Object nodeData) {
this.nodeData = nodeData;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public static ZTreeNode createParent(){
ZTreeNode zTreeNode = new ZTreeNode();
zTreeNode.setChecked(true);
zTreeNode.setId(0L);
zTreeNode.setName("顶级");
zTreeNode.setOpen(true);
zTreeNode.setpId(0L);
zTreeNode.setCode("");
return zTreeNode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface MenuRepository extends BaseRepository<Menu,Long> {
List getMenus();
@Query(nativeQuery = true,value="select menuid from t_sys_relation where roleid=?1")
List getMenuIdsByRoleId(Integer roleId);
@Query(nativeQuery = true,value = "SELECT m1.id AS id, ( CASE WHEN (m2.id = 0 OR m2.id IS NULL) THEN 0 ELSE m2.id END ) AS pId, m1. NAME AS NAME, ( CASE WHEN (m2.id = 0 OR m2.id IS NULL) THEN 'true' ELSE 'false' END ) AS isOpen FROM t_sys_menu m1 LEFT JOIN t_sys_menu m2 ON m1.pcode = m2. CODE ORDER BY m1.id ASC")
@Query(nativeQuery = true,value = "SELECT m1.id AS id, ( CASE WHEN (m2.id = 0 OR m2.id IS NULL) THEN 0 ELSE m2.id END ) AS pId, m1. NAME AS NAME, ( CASE WHEN (m2.id = 0 OR m2.id IS NULL) THEN 'true' ELSE 'false' END ) AS isOpen, m1.code FROM t_sys_menu m1 LEFT JOIN t_sys_menu m2 ON m1.pcode = m2. CODE ORDER BY m1.id ASC")
List menuTreeList();
@Query(nativeQuery = true,value = "SELECT m1.id AS id, ( CASE WHEN (m2.id = 0 OR m2.id IS NULL) THEN 0 ELSE m2.id END ) AS pId, m1. NAME AS NAME, ( CASE WHEN (m2.id = 0 OR m2.id IS NULL) THEN 'true' ELSE 'false' END ) AS isOpen, ( CASE WHEN (m3.ID = 0 OR m3.ID IS NULL) THEN 'false' ELSE 'true' END ) \"checked\" FROM t_sys_menu m1 LEFT JOIN t_sys_menu m2 ON m1.pcode = m2. CODE LEFT JOIN ( SELECT ID FROM t_sys_menu WHERE ID IN (?1)) m3 ON m1.id = m3.id ORDER BY m1.id ASC")
List menuTreeListByMenuIds(List<Long> menuIds);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.enilu.material.factory;

import cn.enilu.material.bean.enumeration.BizExceptionEnum;
import cn.enilu.material.bean.exception.GunsException;
import cn.enilu.material.bean.exception.ApplicationException;
import cn.enilu.material.service.system.IConstantFactory;
import cn.enilu.material.service.system.impl.ConstantFactory;
import org.slf4j.Logger;
Expand Down Expand Up @@ -30,7 +30,7 @@ public static Object createFieldWarpper(Object field, String methodName) {
Object result = method.invoke(me, Long.valueOf(field.toString()));
return result;
} catch (Exception e1) {
throw new GunsException(BizExceptionEnum.ERROR_WRAPPER_FIELD);
throw new ApplicationException(BizExceptionEnum.ERROR_WRAPPER_FIELD);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import cn.enilu.material.bean.entity.message.MessageSender;
import cn.enilu.material.bean.entity.message.MessageTemplate;
import cn.enilu.material.bean.enumeration.BizExceptionEnum;
import cn.enilu.material.bean.exception.GunsException;
import cn.enilu.material.bean.exception.ApplicationException;
import cn.enilu.material.dao.message.MessagesenderRepository;
import cn.enilu.material.dao.message.MessagetemplateRepository;
import cn.enilu.material.service.BaseService;
Expand Down Expand Up @@ -33,12 +33,12 @@ public void save(MessageSender messageSender){
messageSenderRepository.save(messageSender);
}
@Override
public void delete(Long id) throws GunsException {
public void delete(Long id) throws ApplicationException {
List<MessageTemplate> templateList = messagetemplateRepository.findByIdMessageSender(id);
if(templateList.isEmpty()) {
messageSenderRepository.deleteById(id);
}else{
throw new GunsException(BizExceptionEnum.CAN_NOT_DELETE);
throw new ApplicationException(BizExceptionEnum.CAN_NOT_DELETE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import cn.enilu.material.bean.entity.system.Menu;
import cn.enilu.material.bean.enumeration.BizExceptionEnum;
import cn.enilu.material.bean.exception.GunsException;
import cn.enilu.material.bean.exception.ApplicationException;
import cn.enilu.material.bean.vo.node.MenuNode;
import cn.enilu.material.bean.vo.node.Node;
import cn.enilu.material.bean.vo.node.ZTreeNode;
Expand Down Expand Up @@ -146,6 +146,7 @@ public List<ZTreeNode> menuTreeList() {
node.setpId(Long.valueOf(source[1].toString()));
node.setName(source[2].toString());
node.setIsOpen(Boolean.valueOf(source[3].toString()));
node.setCode(source[4].toString());
nodes.add(node);
}
return nodes;
Expand Down Expand Up @@ -180,7 +181,7 @@ public void menuSetPcode(Menu menu) {

//如果编号和父编号一致会导致无限递归
if (menu.getCode().equals(menu.getPcode())) {
throw new GunsException(BizExceptionEnum.MENU_PCODE_COINCIDENCE);
throw new ApplicationException(BizExceptionEnum.MENU_PCODE_COINCIDENCE);
}

menu.setLevels(pLevels + 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cn.enilu.material.service.task;

import cn.enilu.material.bean.entity.system.Task;
import cn.enilu.material.bean.exception.GunsException;
import cn.enilu.material.bean.exception.GunsExceptionEnum;
import cn.enilu.material.bean.exception.ApplicationException;
import cn.enilu.material.bean.exception.ExceptionEnum;
import cn.enilu.material.bean.vo.QuartzJob;
import cn.enilu.material.bean.vo.query.SearchFilter;
import com.alibaba.fastjson.JSON;
Expand Down Expand Up @@ -84,7 +84,7 @@ public QuartzJob getJob(Task task) {
Map<String, Object> dataMap = JSON.parseObject( task.getData(),Map.class);
job.setDataMap(dataMap);
} catch (Exception e) {
throw new GunsException(GunsExceptionEnum.TASK_CONFIG_ERROR);
throw new ApplicationException(ExceptionEnum.TASK_CONFIG_ERROR);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import cn.enilu.material.bean.entity.system.Task;
import cn.enilu.material.bean.entity.system.TaskLog;
import cn.enilu.material.bean.exception.GunsException;
import cn.enilu.material.bean.exception.GunsExceptionEnum;
import cn.enilu.material.bean.exception.ApplicationException;
import cn.enilu.material.bean.exception.ExceptionEnum;
import cn.enilu.material.bean.vo.QuartzJob;
import cn.enilu.material.bean.vo.query.Page;
import cn.enilu.material.dao.system.TaskLogRepository;
Expand Down Expand Up @@ -106,7 +106,7 @@ public Task enable(Long id) {
jobService.addJob(jobService.getJob(task));
}
} catch (SchedulerException e) {
throw new GunsException(GunsExceptionEnum.TASK_CONFIG_ERROR);
throw new ApplicationException(ExceptionEnum.TASK_CONFIG_ERROR);
}
return task;
}
Expand Down
12 changes: 6 additions & 6 deletions material-core/src/main/resouces/code/code.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"codeConfig": {
"type": "cn.enilu.sbvue.code.CodeConfig",
"type": "cn.enilu.flash.code.CodeConfig",
"fields": {
entityModel: "guns-entity",
daoModel: "guns-dao1",
serviceModel: "guns-service2",
controllerModel: "guns-api",
viewModel: "guns-admin-vuejs"
entityModel: "material-core",
daoModel: "material-core",
serviceModel: "material-core",
controllerModel: "material-manage",
viewModel: "material-manage"
}
}
}
54 changes: 54 additions & 0 deletions material-generator/README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 代码生成

## 用法
- 在material-core/pom.xml中添加依赖
```xml
<dependency>
<groupId>cn.enilu</groupId>
<artifactId>material-generator</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
```
- 下载intellij代码生成插件,在插件中心搜索并安装插件:webflash-generator

- 写好实体类,例如:
```java
package cn.enilu.material.bean.entity.test;
import cn.enilu.material.bean.entity.BaseEntity;
import lombok.Data;
import org.hibernate.annotations.Table;
import javax.persistence.Column;
import javax.persistence.Entity;

@Entity(name="t_test_boy")
@Table(appliesTo = "t_test_boy",comment = "男孩")
@Data

public class Boy extends BaseEntity {
@Column(columnDefinition = "VARCHAR(32) COMMENT '姓名'")
private String name;
@Column(columnDefinition = "INT COMMENT '年龄'")
private Integer age;
@Column(columnDefinition = "VARCHAR(12) COMMENT '生日'")
private String birthday;
@Column(name = "has_girl_friend",columnDefinition = "TINYINT COMMENT '是否有女朋友'")
private Boolean hasGirFriend;
}

```
- 上面实体类注意事项
- @Table注解要使用org.hibernate.annotations.Table 不要使用javax.persistence.Table
- @Table注解 必须配置表名(applyiesTo)和注释(comment)
- @Column注解必须配置columnDefinition来表述列信息(英文全部大写):包括类型,注释COMMENT
- 实体类必须继承BaseEntity
- 实体类准备好了后,打开实体类,右键点击“Generator"-->"web-flash-mvc",弹出如下图所示对话框
![code-generator](./doc/code-generate.jpg)
**注意**不用更改对话框中的配置(大部分没有什么作用)
- 运行生成代码后,将会生成controller,service,repository,以及对应的增上改查页面和js,以TestBoy为例,生成的代码如下所示:
![generate-result](./doc/generate-result.png)
- 代码生成后,在系统中配置对应的菜单和权限,即可使用
![菜单配置](./doc/menu.png)

![功能预览](./doc/boy-list.png)

Binary file added material-generator/doc/boy-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material-generator/doc/code-generate.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material-generator/doc/generate-result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material-generator/doc/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions material-generator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>material-admin</artifactId>
<groupId>cn.enilu</groupId>
<version>0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>material-generator</artifactId>
<properties>
<java-version>1.8</java-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<evo-inflector-version>1.0.1</evo-inflector-version>
<velocity-version>1.7</velocity-version>
<commons-cli-version>1.2</commons-cli-version>
<spring.boot.version>2.1.1.RELEASE</spring.boot.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.atteo</groupId>
<artifactId>evo-inflector</artifactId>
<version>${evo-inflector-version}</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>${commons-cli-version}</version>
</dependency>

<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>${velocity-version}</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutz</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cn.enilu.flash.code;

import org.nutz.ioc.Ioc;

import java.util.Map;

/**
* 基础的数据结构加载器<br>
* @author : zhangtao <br>
* 创建日期: 16-7-12<br>
*/
public abstract class AbstractLoader {

public abstract Map<String, TableDescriptor> loadTables(Ioc ioc,
String basePackageName, String baseUri,
String servPackageName,
String repositoryPackageName,
String modPackageName) throws Exception;


}
Loading

0 comments on commit 7f40e6c

Please sign in to comment.