提交 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>
...@@ -11,22 +11,31 @@ import java.math.BigInteger; ...@@ -11,22 +11,31 @@ import java.math.BigInteger;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.util.ObjectUtils;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import net.ibizsys.central.util.ISearchContextDTO; import net.ibizsys.central.util.ISearchContextDTO;
import net.ibizsys.model.dataentity.action.IPSDEAction; import net.ibizsys.model.dataentity.action.IPSDEAction;
import net.ibizsys.model.dataentity.ds.IPSDEDataSet; import net.ibizsys.model.dataentity.ds.IPSDEDataSet;
import net.ibizsys.central.plugin.boot.core.service.IBaseService; import net.ibizsys.central.plugin.boot.core.service.IMPService;
import net.ibizsys.central.plugin.boot.core.helper.CachedBeanCopier; import net.ibizsys.central.plugin.boot.core.helper.CachedBeanCopier;
import net.ibizsys.central.plugin.boot.core.helper.SpringContextHolder; import net.ibizsys.central.plugin.boot.core.helper.SpringContextHolder;
import net.ibizsys.central.dataentity.IDataEntityRuntimeContext;
import {{packageName}}.{{entity.module}}.domain.{{entity.codeName}}; 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}}.mapper.{{entity.codeName}}Mapper;
{{#entity.relEntities}}
import {{packageName}}.{{module}}.domain.{{codeName}};
{{#neq storage "NONE"}}
import {{packageName}}.{{module}}.service.I{{codeName}}Service;
{{/neq}}
{{/entity.relEntities}}
{{#dsName}} {{#dsName}}
@DS("{{entity.dataSource}}") @DS("{{entity.dataSource}}")
{{/dsName}} {{/dsName}}
public interface I{{entity.codeName}}Service extends IBaseService<{{entity.codeName}}, {{entity.codeName}}SearchContext> { public interface I{{entity.codeName}}Service extends IMPService<{{entity.codeName}}, {{entity.codeName}}SearchContext,{{entity.codeName}}Mapper> {
@Override @Override
default String getDataEntityId() { default String getDataEntityId() {
...@@ -48,6 +57,17 @@ public interface I{{entity.codeName}}Service extends IBaseService<{{entity.codeN ...@@ -48,6 +57,17 @@ public interface I{{entity.codeName}}Service extends IBaseService<{{entity.codeN
return this.getRuntimeService().getDataEntityRuntime().executeAction(strActionName, iPSDEAction, args, true); return this.getRuntimeService().getDataEntityRuntime().executeAction(strActionName, iPSDEAction, args, true);
} }
default Object onExecuteActionReal(IDataEntityRuntimeContext iDataEntityRuntimeContext, String strActionName, IPSDEAction iPSDEAction, Object[] args, Object actionData) throws Throwable{
switch (strActionName.toLowerCase()) {
{{#each entity.extActions}}
case "{{lowerCase codeName}}" :
this.on{{pascalCase codeName}}(({{entity.codeName}})args[0]);
return null;
{{/each}}
}
return iDataEntityRuntimeContext.executeActionReal(strActionName, iPSDEAction, args, actionData);
}
default Object onFetchDataSet(String strDataSetName, IPSDEDataSet iPSDEDataSet, Object[] args) throws Throwable { default Object onFetchDataSet(String strDataSetName, IPSDEDataSet iPSDEDataSet, Object[] args) throws Throwable {
switch (strDataSetName.toLowerCase()) { switch (strDataSetName.toLowerCase()) {
{{#entity.dataSets}} {{#entity.dataSets}}
...@@ -58,45 +78,103 @@ public interface I{{entity.codeName}}Service extends IBaseService<{{entity.codeN ...@@ -58,45 +78,103 @@ public interface I{{entity.codeName}}Service extends IBaseService<{{entity.codeN
return this.getRuntimeService().getDataEntityRuntime().fetchDataSet(strDataSetName, iPSDEDataSet, args, true); return this.getRuntimeService().getDataEntityRuntime().fetchDataSet(strDataSetName, iPSDEDataSet, args, true);
} }
default Object onFetchDataSetReal(IDataEntityRuntimeContext iDataEntityRuntimeContext, String strDataSetName, IPSDEDataSet iPSDEDataSet, Object[] args, Object actionData) throws Throwable{
switch (strDataSetName.toLowerCase()) {
{{#entity.dataSets}}
case "{{lowerCase codeName}}" :
return this.onFetch{{pascalCase codeName}}(({{entity.codeName}}SearchContext) args[0]);
{{/entity.dataSets}}
}
return iDataEntityRuntimeContext.fetchDataSetReal(strDataSetName, iPSDEDataSet, args, actionData);
}
default boolean create({{entity.codeName}} dto) throws Throwable { default boolean create({{entity.codeName}} dto) throws Throwable {
return IBaseService.super.create(dto); return IMPService.super.create(dto);
}
default boolean onCreate({{entity.codeName}} dto) throws Throwable {
return IMPService.super.onCreate(dto);
} }
{{#enableEntityCache}} {{#enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true) @CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/enableEntityCache}} {{/enableEntityCache}}
default boolean update({{entity.codeName}} dto) throws Throwable { default boolean update({{entity.codeName}} dto) throws Throwable {
return IBaseService.super.update(dto); return IMPService.super.update(dto);
}
{{#enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/enableEntityCache}}
default boolean onUpdate({{entity.codeName}} dto) throws Throwable {
return IMPService.super.onUpdate(dto);
} }
{{#enableEntityCache}} {{#enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true) @CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/enableEntityCache}} {{/enableEntityCache}}
default boolean remove({{entity.keyField.type.java}} key) throws Throwable { default boolean remove({{entity.keyField.type.java}} key) throws Throwable {
return IBaseService.super.remove(key); return IMPService.super.remove(key);
} }
{{#enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/enableEntityCache}}
default boolean onRemove({{entity.keyField.type.java}} key) throws Throwable {
List keys=new ArrayList();
keys.add(key);
return IMPService.super.onRemove(keys);
}
{{#enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/enableEntityCache}}
default boolean remove(List keys) throws Throwable { default boolean remove(List keys) throws Throwable {
return IBaseService.super.remove(keys); return IMPService.super.remove(keys);
}
{{#enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/enableEntityCache}}
default boolean onRemove(List keys) throws Throwable {
return IMPService.super.onRemove(keys);
} }
default {{entity.codeName}} get({{entity.keyField.type.java}} key) throws Throwable { default {{entity.codeName}} get({{entity.keyField.type.java}} key) throws Throwable {
return IBaseService.super.get(key); return IMPService.super.get(key);
}
default {{entity.codeName}} onGet({{entity.keyField.type.java}} key) throws Throwable {
return IMPService.super.onGet(key);
} }
default {{entity.codeName}} getDraft({{entity.codeName}} dto) throws Throwable { default {{entity.codeName}} getDraft({{entity.codeName}} dto) throws Throwable {
return IBaseService.super.getDraft(dto); return IMPService.super.getDraft(dto);
}
default {{entity.codeName}} onGetDraft({{entity.codeName}} dto) throws Throwable {
return IMPService.super.onGetDraft(dto);
} }
default Integer checkKey({{entity.codeName}} dto) throws Throwable { default Integer checkKey({{entity.codeName}} dto) throws Throwable {
return IBaseService.super.checkKey(dto); return IMPService.super.checkKey(dto);
}
default Integer onCheckKey({{entity.codeName}} dto) throws Throwable {
return IMPService.super.onCheckKey(dto);
} }
{{#enableEntityCache}} {{#enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true) @CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/enableEntityCache}} {{/enableEntityCache}}
default boolean save({{entity.codeName}} dto) throws Throwable { default boolean save({{entity.codeName}} dto) throws Throwable {
return IBaseService.super.save(dto); return IMPService.super.save(dto);
}
{{#enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/enableEntityCache}}
default boolean onSave({{entity.codeName}} dto) throws Throwable {
return IMPService.super.onSave(dto);
} }
{{#each entity.extActions}} {{#each entity.extActions}}
...@@ -104,17 +182,35 @@ public interface I{{entity.codeName}}Service extends IBaseService<{{entity.codeN ...@@ -104,17 +182,35 @@ public interface I{{entity.codeName}}Service extends IBaseService<{{entity.codeN
this.getRuntimeService().getDataEntityRuntime().executeAction("{{name}}", null, new Object[]{dto}, true); this.getRuntimeService().getDataEntityRuntime().executeAction("{{name}}", null, new Object[]{dto}, true);
return true; return true;
} }
default boolean on{{pascalCase codeName}}({{entity.codeName}} dto) throws Throwable {
this.getDataEntityRuntimeContext().executeActionReal("{{name}}", null, new Object[]{dto}, null);
return true;
}
{{#if action}} {{#if action}}
default {{entity.codeName}} {{camelCase codeName}}({{entity.keyField.type.java}} key) { default {{entity.codeName}} {{camelCase codeName}}({{entity.keyField.type.java}} key) {
return {{camelCase codeName}}(new {{entity.codeName}}().set{{pascalCase entity.keyField.codeName}}(key)); {{entity.codeName}} dto = new {{entity.codeName}}();
} dto.set{{pascalCase entity.keyField.codeName}}(key);
return {{camelCase codeName}}(dto);
}
default {{entity.codeName}} on{{pascalCase codeName}}({{entity.keyField.type.java}} key) {
{{entity.codeName}} dto = new {{entity.codeName}}();
dto.set{{pascalCase entity.keyField.codeName}}(key);
return on{{pascalCase codeName}}(dto);
}
{{/if}} {{/if}}
{{/each}} {{/each}}
{{#entity.dataSets}} {{#entity.dataSets}}
default Page<{{entity.codeName}}> fetch{{pascalCase codeName}}({{entity.codeName}}SearchContext dto) throws Throwable { default Page<{{entity.codeName}}> fetch{{pascalCase codeName}}({{entity.codeName}}SearchContext dto) throws Throwable {
return (Page) this.getRuntimeService().getDataEntityRuntime().fetchDataSet("{{name}}", null, new Object[]{dto}, true); return (Page) this.getRuntimeService().getDataEntityRuntime().fetchDataSet("{{name}}", dto.getDataSet(), new Object[]{dto}, true);
}
default Page<{{entity.codeName}}> onFetch{{pascalCase codeName}}({{entity.codeName}}SearchContext dto) throws Throwable {
return (Page) this.getDataEntityRuntimeContext().fetchDataSetReal("{{name}}", dto.getDataSet(), new Object[]{dto}, null);
} }
default List<{{entity.codeName}}> select{{pascalCase codeName}}({{entity.codeName}}SearchContext dto) throws Throwable { default List<{{entity.codeName}}> select{{pascalCase codeName}}({{entity.codeName}}SearchContext dto) throws Throwable {
...@@ -122,8 +218,33 @@ public interface I{{entity.codeName}}Service extends IBaseService<{{entity.codeN ...@@ -122,8 +218,33 @@ public interface I{{entity.codeName}}Service extends IBaseService<{{entity.codeN
} }
{{/entity.dataSets}} {{/entity.dataSets}}
{{#entity.references}}
List<{{entity.codeName}}> selectBy{{pascalCase fkField.codeName}}({{fkField.type.java}} {{camelCase fkField.codeName}});
{{#entity.hasReferences}}
default 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}}
default List<{{entity.codeName}}> getByEntities(List<{{entity.codeName}}> entities) {
return this.getBaseMapper().selectEntities(entities);
}
{{#entity.references}}
default List<{{entity.codeName}}> selectBy{{pascalCase fkField.codeName}}({{fkField.type.java}} {{camelCase fkField.codeName}}) {
return this.getBaseMapper().selectBy{{pascalCase fkField.codeName}}({{camelCase fkField.codeName}});
}
{{/entity.references}} {{/entity.references}}
} }
\ No newline at end of file
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 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册