提交 611b2c38 编写于 作者: sq3536's avatar sq3536

cli

上级 0159b489
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
<version>2.4.0</version> <version>2.4.0</version>
</parent> </parent>
<modules> <modules>
<module>{{projectName}}-pub</module>
<!-- boot --> <!-- boot -->
<module>{{projectName}}-boot</module> <module>{{projectName}}-boot</module>
</modules> </modules>
...@@ -73,5 +74,4 @@ ...@@ -73,5 +74,4 @@
</snapshots> </snapshots>
</repository> </repository>
</repositories> </repositories>
</project> </project>
...@@ -14,7 +14,11 @@ ...@@ -14,7 +14,11 @@
<description>{{projectDesc}} Boot</description> <description>{{projectDesc}} Boot</description>
<dependencies> <dependencies>
<dependency>
<groupId>{{packageName}}</groupId>
<artifactId>{{projectName}}-pub</artifactId>
<version>1.0.0.0</version>
</dependency>
</dependencies> </dependencies>
<profiles> <profiles>
...@@ -52,5 +56,31 @@ ...@@ -52,5 +56,31 @@
</build> </build>
</profile> </profile>
</profiles> </profiles>
<build>
<plugins>
<plugin>
<groupId>cn.ibizlab</groupId>
<artifactId>ibizlab-generator-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<output>
../
</output>
<inputSpec>
${basedir}/src/main/resources/model/com/sa/jcsc
</inputSpec>
<templateDirs>
/Users/mac/workshop/ibizlab-generator/modules/ibizlab-generator-core/src/main/resources/templ/ibiz-boot
</templateDirs>
<packageName>
${project.groupId}
</packageName>
<name>
${parent.artifactId}
</name>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>{{projectName}}</artifactId>
<groupId>{{packageName}}</groupId>
<version>1.0.0.0</version>
</parent>
<artifactId>{{projectName}}-pub</artifactId>
<name>{{projectDesc}} Generator Code</name>
<description>{{projectDesc}} 模板生成代码,不要直接修改,修改请在{{projectName}}-boot项目中重写</description>
</project>
package {{packageName}}.{{entity.module}}.service.impl; package {{packageName}}.{{entity.module}}.service.impl;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.math.BigInteger;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.ibizsys.central.plugin.boot.core.service.impl.MPServiceImpl;
import net.ibizsys.central.plugin.boot.core.service.impl.BaseServiceImpl;
import net.ibizsys.central.plugin.boot.core.helper.SpringContextHolder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.Assert;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
{{#system.enableGlobalTransaction}} {{#system.enableGlobalTransaction}}
import io.seata.spring.annotation.GlobalTransactional; import io.seata.spring.annotation.GlobalTransactional;
{{/system.enableGlobalTransaction}} {{/system.enableGlobalTransaction}}
...@@ -35,13 +13,6 @@ import {{packageName}}.{{entity.module}}.domain.{{entity.codeName}}; ...@@ -35,13 +13,6 @@ import {{packageName}}.{{entity.module}}.domain.{{entity.codeName}};
import {{packageName}}.{{entity.module}}.filter.{{entity.codeName}}SearchContext; import {{packageName}}.{{entity.module}}.filter.{{entity.codeName}}SearchContext;
import {{packageName}}.{{entity.module}}.service.I{{entity.codeName}}Service; import {{packageName}}.{{entity.module}}.service.I{{entity.codeName}}Service;
import {{packageName}}.{{entity.module}}.mapper.{{entity.codeName}}Mapper; import {{packageName}}.{{entity.module}}.mapper.{{entity.codeName}}Mapper;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import javax.annotation.Resource;
{{#entity.relEntities}} {{#entity.relEntities}}
import {{packageName}}.{{module}}.domain.{{codeName}}; import {{packageName}}.{{module}}.domain.{{codeName}};
{{#neq storage "NONE"}} {{#neq storage "NONE"}}
...@@ -55,13 +26,7 @@ import {{packageName}}.{{module}}.service.I{{codeName}}Service; ...@@ -55,13 +26,7 @@ import {{packageName}}.{{module}}.service.I{{codeName}}Service;
*/ */
@Slf4j @Slf4j
@Service("{{entity.codeName}}Service") @Service("{{entity.codeName}}Service")
public class {{entity.codeName}}ServiceImpl extends BaseServiceImpl<{{entity.codeName}},{{entity.codeName}}SearchContext> implements I{{entity.codeName}}Service { public class {{entity.codeName}}ServiceImpl extends MPServiceImpl<{{entity.codeName}},{{entity.codeName}}SearchContext,{{entity.codeName}}Mapper> implements I{{entity.codeName}}Service {
@Resource
private {{entity.codeName}}Mapper baseMapper;
public {{entity.codeName}}Mapper getBaseMapper(){
return baseMapper;
}
{{#entity.relEntities}} {{#entity.relEntities}}
{{#neq storage "NONE"}} {{#neq storage "NONE"}}
...@@ -72,34 +37,13 @@ public class {{entity.codeName}}ServiceImpl extends BaseServiceImpl<{{entity.cod ...@@ -72,34 +37,13 @@ public class {{entity.codeName}}ServiceImpl extends BaseServiceImpl<{{entity.cod
{{/neq}} {{/neq}}
{{/entity.relEntities}} {{/entity.relEntities}}
public List<{{entity.codeName}}> getByEntities(List<{{entity.codeName}}> entities) { {{#each entity.extActions}}
return this.baseMapper.selectEntities(entities); public boolean {{camelCase codeName}}({{entity.codeName}} dto) throws Throwable {
} if(!I{{entity.codeName}}Service.super.{{camelCase codeName}}(dto))
return false;
{{#entity.hasReferences}} return true;
public void fillParentData({{entity.codeName}} et) {
{{#each entity.references as |reference|}}
{{#gt reference.relFieldCount 1}}
if(!ObjectUtils.isEmpty(et.get{{pascalCase reference.fkField.codeName}}())) {
{{reference.entityCodeName}} {{camelCase reference.entityCodeName}} = et.get{{pascalCase reference.codeName}}();
if(!ObjectUtils.isEmpty({{camelCase reference.entityCodeName}})) {
{{#each reference.fields as |field|}}
{{#neq field.dataType 'PICKUP'}}
et.set{{pascalCase field.codeName}}({{camelCase reference.entityCodeName}}.get{{pascalCase field.refFieldCodeName}}());
{{/neq}}
{{/each}}
}
}
{{/gt}}
{{/each}}
}
{{/entity.hasReferences}}
{{#entity.references}}
public List<{{entity.codeName}}> selectBy{{pascalCase fkField.codeName}}({{fkField.type.java}} {{camelCase fkField.codeName}}) {
return baseMapper.selectBy{{pascalCase fkField.codeName}}({{camelCase fkField.codeName}});
} }
{{/entity.references}} {{/each}}
} }
\ No newline at end of file
...@@ -3,7 +3,7 @@ spring: ...@@ -3,7 +3,7 @@ spring:
cloud: cloud:
nacos: nacos:
discovery: discovery:
server-addr: 127.0.0.1:8848 server-addr: 172.16.100.77:8848
enabled: true enabled: true
eureka: eureka:
......
...@@ -36,12 +36,12 @@ spring: ...@@ -36,12 +36,12 @@ spring:
enabled: true enabled: true
{{/if}} {{/if}}
datasource: datasource:
username: root username: a_LAB01_da1af574b
password: root password: 'D33f8870'
url: jdbc:mysql://127.0.0.1:3306/{{projectName}}?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&allowMultiQueries=true&serverTimezone=GMT%2B8 url: jdbc:mysql://172.16.186.185:3306/a_LAB01_da1af574b?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&serverTimezone=Asia/Shanghai&allowMultiQueries=true&serverTimezone=GMT%2B8&useSSL=false
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
isSyncDBSchema: false isSyncDBSchema: false
defaultSchema: {{projectName}} defaultSchema: a_LAB01_da1af574b
{{#if system.enableDS}} {{#if system.enableDS}}
dynamic: dynamic:
druid: #以下是全局默认值,可以全局更改 druid: #以下是全局默认值,可以全局更改
......
<?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>ibizlab-generator-project</artifactId>
<groupId>cn.ibizlab</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>maven-plugin</packaging>
<artifactId>ibizlab-generator-plugin</artifactId>
<name>ibizlab-generator-plugin</name>
<description>ibizlab-generator-plugin</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.ibizlab</groupId>
<artifactId>ibizlab-generator-core</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.8</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.5</version>
<configuration>
<goalPrefix>ibizlabcli</goalPrefix>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>generated-helpmojo</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>cn.ibizlab</groupId>
<artifactId>ibizlab-generator-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<template>
<!-- <controller>/template/controller.java.vm</controller> -->
</template>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
\ No newline at end of file
package cn.ibizlab.codegen;
import cn.ibizlab.codegen.config.CodegenConfigurator;
import cn.ibizlab.codegen.config.CodegenConfiguratorUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
/**
* 生成文件
*
* @author YangHu, tangguo
* @since 2016/8/30
*/
@Mojo(name = "code", threadSafe = true)
public class GenerateMojo extends AbstractMojo {
@Parameter
private String output ;
@Parameter
private String inputSpec;
@Parameter
private String[] inputSpecfilters;
@Parameter
private String[] templateDirs;
@Parameter
private String[] templatePaths;
@Parameter
private String[] templateFilters;
@Parameter
private String auth;
@Parameter
private String[] globalProperties ;
@Parameter
private String configFile;
@Parameter
private String name;
@Parameter
private String packageName;
@Parameter
private String[] additionalProperties ;
@Parameter
private String gitHost;
@Parameter
private String gitUserId;
@Parameter
private String gitRepoId;
@Parameter
private String releaseNote;
@Parameter
private String httpUserAgent;
/**
* 日志工具
*/
protected Log log = getLog();
CodegenConfigurator configurator;
Generator generator;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// this initial check allows for field-level package private injection (for unit testing)
if (configurator == null) {
// if a config file wasn't specified, or we were unable to read it
if (configurator == null) {
// create a fresh configurator
configurator = new CodegenConfigurator();
}
}
if (isNotEmpty(inputSpec)) {
if (!inputSpec.matches("^http(s)?://.*") && !new File(inputSpec).exists()) {
getLog().error("[error] The spec file is not found: " + inputSpec);
getLog().error("[error] Check the path of the ibizlab-Model spec and try again.");
return;
}
configurator.setInputSpec(inputSpec);
}
if (isNotEmpty(output)) {
configurator.setOutputDir(output);
}
if (isNotEmpty(auth)) {
configurator.setAuth(auth);
}
if (!ObjectUtils.isEmpty(templateDirs)) {
configurator.setTemplateDirs(Arrays.asList(templateDirs));
}
if (!ObjectUtils.isEmpty(templatePaths)) {
configurator.setTemplatePaths(Arrays.asList(templatePaths));
}
if (!ObjectUtils.isEmpty(templateFilters)) {
configurator.setTemplateFilters(Arrays.asList(templateFilters));
}
if (!ObjectUtils.isEmpty(templateFilters)) {
configurator.setFilters(Arrays.asList(templateFilters));
}
if (isNotEmpty(packageName)) {
configurator.setPackageName(packageName);
}
if (isNotEmpty(name)) {
configurator.setProjectName(name);
}
if (isNotEmpty(gitHost)) {
configurator.setGitHost(gitHost);
}
if (isNotEmpty(gitUserId)) {
configurator.setGitUserId(gitUserId);
}
if (isNotEmpty(gitRepoId)) {
configurator.setGitRepoId(gitRepoId);
}
if (isNotEmpty(releaseNote)) {
configurator.setReleaseNote(releaseNote);
}
if (isNotEmpty(httpUserAgent)) {
configurator.setHttpUserAgent(httpUserAgent);
}
if (!ObjectUtils.isEmpty(globalProperties)) {
CodegenConfiguratorUtils.applyGlobalPropertiesKvpList(Arrays.asList(globalProperties), configurator);
}
if (!ObjectUtils.isEmpty(additionalProperties)) {
CodegenConfiguratorUtils.applyAdditionalPropertiesKvpList(Arrays.asList(additionalProperties), configurator);
}
try {
// this null check allows us to inject for unit testing.
if (generator == null) {
generator = new DefaultGenerator();
}
generator.opts(configurator.toClientOptInput());
generator.generate();
} catch (GeneratorNotFoundException e) {
getLog().error(e.getMessage());
getLog().error("[error] Check the spelling of the generator's name and try again.");
return;
}
}
}
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
<modules> <modules>
<module>modules/ibizlab-generator-core</module> <module>modules/ibizlab-generator-core</module>
<module>modules/ibizlab-generator-cli</module> <module>modules/ibizlab-generator-cli</module>
<module>modules/ibizlab-generator-plugin</module>
</modules> </modules>
<properties> <properties>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册