提交 06232cf0 编写于 作者: sq3536's avatar sq3536

update

上级 c8e48f99
...@@ -360,31 +360,31 @@ public class EntityModel extends BaseModel { ...@@ -360,31 +360,31 @@ public class EntityModel extends BaseModel {
private String storageMode="SQL"; private String storage="SQL";
public void setStorageMode(Integer type) public void setStorage(Integer type)
{ {
switch(type){ switch(type){
case 0: case 0:
this.storageMode="NONE"; this.storage="NONE";
break; break;
case 1: case 1:
this.storageMode="SQL"; this.storage="SQL";
break; break;
case 2: case 2:
this.storageMode="NoSQL"; this.storage="NoSQL";
break; break;
case 4: case 4:
this.storageMode="ServiceAPI"; this.storage="ServiceAPI";
break; break;
default: default:
this.storageMode="SQL"; this.storage="SQL";
break; break;
} }
} }
public void setStorageMode(String type) public void setStorage(String type)
{ {
this.storageMode=type; this.storage=type;
} }
...@@ -480,7 +480,7 @@ public class EntityModel extends BaseModel { ...@@ -480,7 +480,7 @@ public class EntityModel extends BaseModel {
this.system=systemModel; this.system=systemModel;
this.setCodeName(dataEntity.getCodeName()); this.setCodeName(dataEntity.getCodeName());
this.setName(dataEntity.getName()); this.setName(dataEntity.getName());
this.setStorageMode(dataEntity.getStorageMode()); this.setStorage(dataEntity.getStorageMode());
List<String> dsTypes=new ArrayList<>(); List<String> dsTypes=new ArrayList<>();
if(dataEntity.getAllPSDEDBConfigs()!=null) if(dataEntity.getAllPSDEDBConfigs()!=null)
......
...@@ -45,7 +45,7 @@ public class LabelExt implements java.io.Serializable, Comparable<String>, CharS ...@@ -45,7 +45,7 @@ public class LabelExt implements java.io.Serializable, Comparable<String>, CharS
} }
public String toPluralize() { public String toPluralize() {
return Inflector.getInstance().pluralize(toCamelCase()); return Inflector.getInstance().pluralize(toCamelCase().toLowerCase());
} }
public String getLowerCase() public String getLowerCase()
......
...@@ -138,7 +138,7 @@ public class ModelStorage { ...@@ -138,7 +138,7 @@ public class ModelStorage {
else if(type.equals(TemplateFileType.entity)) else if(type.equals(TemplateFileType.entity))
{ {
getSystemModel().getEntities().forEach(item->{ getSystemModel().getEntities().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.entity).setCliSubType(item.getStorageMode()).setModule(item.getModule()) CliOption opt=newCliOption(TemplateFileType.entity).setCliSubType(item.getStorage()).setModule(item.getModule())
.baseData(item,item.getCodeName().toString()); .baseData(item,item.getCodeName().toString());
rt.addOption(opt); rt.addOption(opt);
}); });
......
package cn.ibizlab.codegen.model; package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.utils.StringAdvUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
...@@ -292,7 +293,7 @@ public class PojoSchema { ...@@ -292,7 +293,7 @@ public class PojoSchema {
if(!referenceMap.containsKey(prop.getOptions().getCodeName().toLowerCase())) if(!referenceMap.containsKey(prop.getOptions().getCodeName().toLowerCase()))
referenceMap.put(prop.getOptions().getCodeName().toLowerCase(), prop); referenceMap.put(prop.getOptions().getCodeName().toLowerCase(), prop);
} }
String pluralize= Inflector.getInstance().pluralize(StringUtils.isEmpty(prop.getOptions().getCodeName())?prop.getOptions().getEntityName():prop.getOptions().getCodeName()).toLowerCase(); String pluralize= Inflector.getInstance().pluralize(StringAdvUtils.camelcase(StringUtils.isEmpty(prop.getOptions().getCodeName())?prop.getOptions().getEntityName():prop.getOptions().getCodeName()).toLowerCase());
if(!referenceMap.containsKey(pluralize)) if(!referenceMap.containsKey(pluralize))
referenceMap.put(pluralize, prop); referenceMap.put(pluralize, prop);
} }
......
...@@ -92,6 +92,8 @@ public class SystemModel extends BaseModel { ...@@ -92,6 +92,8 @@ public class SystemModel extends BaseModel {
private IPSSysSFPub pub; private IPSSysSFPub pub;
private Set<String> mqSubscribes;
private Map<String,EntityModel> entitiesMap; private Map<String,EntityModel> entitiesMap;
public synchronized Map<String, EntityModel> getEntitiesMap() { public synchronized Map<String, EntityModel> getEntitiesMap() {
if(entitiesMap==null) { if(entitiesMap==null) {
...@@ -107,6 +109,13 @@ public class SystemModel extends BaseModel { ...@@ -107,6 +109,13 @@ public class SystemModel extends BaseModel {
enableES=true; enableES=true;
if(!ObjectUtils.isEmpty(entity.getAllPSDEDataSyncs())) if(!ObjectUtils.isEmpty(entity.getAllPSDEDataSyncs()))
enableMQ=true; enableMQ=true;
if(entity.getAllPSDEDataSyncs()!=null)
{
entity.getAllPSDEDataSyncs().forEach(sync->{
if(mqSubscribes==null) mqSubscribes=new LinkedHashSet<>();
mqSubscribes.add(sync.getCodeName());
});
}
entitiesMap.put(entity.getCodeName(),new EntityModel(this,entity)); entitiesMap.put(entity.getCodeName(),new EntityModel(this,entity));
}); });
} }
......
package cn.ibizlab.codegen.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.service.IPSSysServiceAPI;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class test {
private String type;
@JsonIgnore
@JSONField(serialize = false)
private Map<String,Object> extensionparams=new HashMap<String,Object>();
@JsonAnyGetter
@JSONField(name = "_any", unwrapped = true, serialize = true, deserialize = false)
public Map<String , Object> getExtensionparams() {
return extensionparams;
}
@JsonAnySetter
@JSONField(name = "_any", unwrapped = true, serialize = false, deserialize = true)
public test set(String field, Object value) {
extensionparams.put(field,value);
return this;
}
public static void main(String[] args) {
String str="{'a':'b','c':'d','type':'12'}";
test t= JSON.parseObject(str,test.class);
System.out.print(JSON.toJSONString(t));
}
}
...@@ -115,7 +115,7 @@ public enum StringHelpers implements Helper<Object> { ...@@ -115,7 +115,7 @@ public enum StringHelpers implements Helper<Object> {
pluralize { pluralize {
@Override @Override
protected CharSequence safeApply(final Object value, final Options options) { protected CharSequence safeApply(final Object value, final Options options) {
return Inflector.getInstance().pluralize(StringAdvUtils.camelcase(value.toString())); return Inflector.getInstance().pluralize(StringAdvUtils.camelcase(value.toString()).toLowerCase());
} }
}; };
......
...@@ -36,7 +36,7 @@ public class PluralizeLambda implements Mustache.Lambda { ...@@ -36,7 +36,7 @@ public class PluralizeLambda implements Mustache.Lambda {
@Override @Override
public void execute(Template.Fragment fragment, Writer writer) throws IOException { public void execute(Template.Fragment fragment, Writer writer) throws IOException {
String text = Inflector.getInstance().pluralize(StringAdvUtils.camelcase(fragment.execute())); String text = Inflector.getInstance().pluralize(StringAdvUtils.camelcase(fragment.execute()).toLowerCase());
writer.write(text); writer.write(text);
......
FROM image.ibizlab.cn/library/openjdk:8-jre-alpine
ENV TZ="Asia/Shanghai" \
SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
IBIZ_SLEEP=0 \
JAVA_OPTS=""
CMD echo "The application will start in ${IBIZ_SLEEP}s..." && \
sleep ${IBIZ_SLEEP} && \
java ${JAVA_OPTS} -Duser.timezone=$TZ -Djava.security.egd=file:/dev/./urandom -jar /{{projectName}}-app-{{apps}}.jar
EXPOSE {{#if app.httpPort}}{{app.httpPort}}{{else}}8080{{/if}}
ADD {{projectName}}-app-{{apps}}.jar /{{projectName}}-app-{{apps}}.jar
package {{packageName}}.{{apps}}.config;
import com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration;
import cn.ibizlab.util.errors.BadRequestAlertException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.Query;
import java.lang.management.ManagementFactory;
import java.util.Set;
/**
* 外部容器启动服务时,自动注册服务到nacos
*/
@Component
@Slf4j
@ConditionalOnExpression("'${ibiz.deploy.packagetype:jar}'.equals('war')")
public class NacosRegisterConfig implements ApplicationRunner {
@Autowired(required = false)
private NacosAutoServiceRegistration registration;
@Value("${server.port:8080}")
Integer port;
@Override
public void run(ApplicationArguments args) {
log.info("正在尝试将应用程序注册到nacos");
if (registration != null && port != null) {
try {
String containerPort = getContainerPort();
if(!StringUtils.isEmpty(containerPort)){
registration.setPort(new Integer(containerPort));
}
else{
registration.setPort(port);
log.info("无法获取外部容器端口,将使用程序默认端口{}",port);
}
registration.start();
} catch (Exception e) {
throw new BadRequestAlertException("应用程序注册到nacos失败,"+e,"","");
}
log.info("已将应用程序成功注册到nacos");
}
else{
log.info("无法获取应用程序端口,将应用程序注册到nacos请求被忽略。");
}
}
/**
* 获取外部容器端口
*/
public String getContainerPort(){
String port = null;
try {
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = beanServer.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
if(!ObjectUtils.isEmpty(objectNames)){
port = objectNames.iterator().next().getKeyProperty("port");
}
}
catch (Exception e) {
log.error("获取外部容器端口失败!"+e);
}
return port;
}
}
</#if>
\ No newline at end of file
package {{packageName}}.{{apps}}.config; package {{packageName}}.{{apps}}.config;
import {{packageName}}.util.security.AuthenticationEntryPoint; import cn.ibizlab.util.security.AuthenticationEntryPoint;
import {{packageName}}.util.security.AuthorizationTokenFilter; import cn.ibizlab.util.security.AuthorizationTokenFilter;
import {{packageName}}.util.service.AuthenticationUserService; import cn.ibizlab.util.service.AuthenticationUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -39,22 +39,22 @@ public class {{app.codeName}}SecurityConfig extends WebSecurityConfigurerAdapter ...@@ -39,22 +39,22 @@ public class {{app.codeName}}SecurityConfig extends WebSecurityConfigurerAdapter
@Autowired @Autowired
AuthorizationTokenFilter authenticationTokenFilter; AuthorizationTokenFilter authenticationTokenFilter;
@Value("${ibiz.auth.path:v7/login}"}) @Value("${ibiz.auth.path:v7/login}")
private String loginPath; private String loginPath;
@Value("${ibiz.auth.logoutpath:v7/logout}"}) @Value("${ibiz.auth.logoutpath:v7/logout}")
private String logoutPath; private String logoutPath;
@Value("${ibiz.file.uploadpath:ibizutil/upload}"}) @Value("${ibiz.file.uploadpath:ibizutil/upload}")
private String uploadpath; private String uploadpath;
@Value("${ibiz.file.downloadpath:ibizutil/download}"}) @Value("${ibiz.file.downloadpath:ibizutil/download}")
private String downloadpath; private String downloadpath;
@Value("${ibiz.file.previewpath:ibizutil/preview}"}) @Value("${ibiz.file.previewpath:ibizutil/preview}")
private String previewpath; private String previewpath;
@Value("${ibiz.auth.excludesPattern:}"}) @Value("${ibiz.auth.excludesPattern:}")
private String[] excludesPattern; private String[] excludesPattern;
@Autowired @Autowired
......
...@@ -13,7 +13,7 @@ import org.mybatis.spring.annotation.MapperScan; ...@@ -13,7 +13,7 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import {{packageName}}.util.web.SearchContextHandlerMethodArgumentResolver; import cn.ibizlab.util.web.SearchContextHandlerMethodArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.List; import java.util.List;
......
package {{packageName}}.${app.getPKGCodeName()?lower_case};
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
/**
* 提供外部容器启动服务能力
*/
@Slf4j
public class {{app.codeName}}Initializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
log.info("--正在使用外部容器启动服务--");
return builder.sources({{app.codeName}}Application.class);
}
}
\ No newline at end of file
...@@ -7,12 +7,12 @@ logging: ...@@ -7,12 +7,12 @@ logging:
#zuul网关路由设置 #zuul网关路由设置
zuul: zuul:
routes: routes:
{{#enableWorkflow}} {{#if system.enableWorkflow}}
wfcore: wfcore:
path: /wfcore/** path: /wfcore/**
serviceId: ${ibiz.ref.service.wf:ibzwf-api}} serviceId: ${ibiz.ref.service.wf:ibzwf-api}}
stripPrefix: true stripPrefix: true
{{/enableWorkflow}} {{/if}}
loginv7: loginv7:
path: /v7/login path: /v7/login
serviceId: ${ibiz.ref.service.uaa:ibzuaa-api}} serviceId: ${ibiz.ref.service.uaa:ibzuaa-api}}
...@@ -71,9 +71,9 @@ zuul: ...@@ -71,9 +71,9 @@ zuul:
stripPrefix: false stripPrefix: false
{{#each app.appEntities}} {{#each app.appEntities}}
{{#serviceId}} {{#serviceId}}
{{lowerCase codeName}}: {{apps}}-{{lowerCase codeName}}:
path: /{{pluralize codeName}}/** path: /{{pluralize codeName}}/**
serviceId: ${ibiz.ref.service.{{serviceId}}:{{serviceId}}\} serviceId: ${ ibiz.ref.service.{{serviceId}}:{{serviceId}} }
stripPrefix: false stripPrefix: false
{{/serviceId}} {{/serviceId}}
{{/each}} {{/each}}
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<property name="LOG_PATH" value="logs" />
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] %-40.40logger{39} : %msg%n" />
<!-- 彩色日志 -->
<!-- 彩色日志依赖的渲染类 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<!-- 彩色日志格式 -->
<property name="LOG_PATTERN2" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr([${LOG_LEVEL_PATTERN:-%5p}]) %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}}" />
<!-- 控制台输出 -->
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN}}</pattern>
</encoder>
</appender>
<!--<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">-->
<!-- <destination>127.0.0.1:9601</destination>-->
<!-- <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">-->
<!-- <customFields>{"appname":"{{projectName}}-{{apps}}"}</customFields>-->
<!-- </encoder>-->
<!--</appender>-->
<!-- 按照每天生成日志文件 -->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_PATH}}/{{projectName}}-{{apps}}.%d{yyyy-MM-dd}.log</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN}}</pattern>
</encoder>
<!--日志文件最大的大小-->
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>100MB</MaxFileSize>
</triggeringPolicy>
</appender>
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="Console" />
<appender-ref ref="file" />
<!--<appender-ref ref="LOGSTASH" />-->
</root>
</configuration>
package {{packageName}};
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import java.util.List;
import cn.ibizlab.util.web.SearchContextHandlerMethodArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
@EnableDiscoveryClient
@Configuration
@EnableTransactionManagement
@EnableFeignClients(basePackages = {"{{packageName}}" })
@SpringBootApplication(exclude = {
{{#unless system.enableMongo}}
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.class,
{{/unless}}
{{#if system.enableDS}}
com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.class
{{/if}}
})
@ComponentScan(basePackages = {"{{packageName}}"}
// ,excludeFilters = {
// @ComponentScan.Filter(type= org.springframework.context.annotation.FilterType.REGEX, pattern="{{packageName}}.xxx.rest.xxx"),
// }
)
@Import({
org.springframework.cloud.openfeign.FeignClientsConfiguration.class
})
@EnableAsync
@EnableScheduling
public class DevBootApplication extends WebMvcConfigurerAdapter {
@Autowired
SearchContextHandlerMethodArgumentResolver resolver;
public static void main(String[] args) {
SpringApplication.run(DevBootApplication.class, args);
}
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
super.addArgumentResolvers(argumentResolvers);
argumentResolvers.add(resolver);
}
}
package {{packageName}}.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
{{#if system.enableGlobalTransaction}}
@Import({com.alibaba.cloud.seata.feign.SeataFeignClientAutoConfiguration.class})
{{/if}}
public class DevBootAutoConfiguration {
}
{{#eq system.saaSMode 4}}
package {{packageName}}.config;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class DevBootHeaderFilter extends ZuulFilter {
@Override
public String filterType() {
return "pre";
}
@Override
public int filterOrder() {
return 0;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public Object run() throws ZuulException {
RequestContext ctx = RequestContext.getCurrentContext();
ctx.addZuulRequestHeader("srfsystem", "{{system.codeName}}");
return null;
}
}
{{/eq}}
\ No newline at end of file
package {{packageName}}.config;
import cn.ibizlab.util.security.AuthenticationEntryPoint;
import cn.ibizlab.util.security.AuthorizationTokenFilter;
import cn.ibizlab.util.service.AuthenticationUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.core.GrantedAuthorityDefaults;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.beans.factory.annotation.Qualifier;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class DevBootSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthenticationEntryPoint unauthorizedHandler;
@Autowired
private AuthenticationUserService userDetailsService;
/**
* 自定义基于JWT的安全过滤器
*/
@Autowired
AuthorizationTokenFilter authenticationTokenFilter;
@Value("${ibiz.auth.path:v7/login}")
private String loginPath;
@Value("${ibiz.auth.logoutpath:v7/logout}")
private String logoutPath;
@Value("${ibiz.file.uploadpath:ibizutil/upload}")
private String uploadpath;
@Value("${ibiz.file.downloadpath:ibizutil/download}")
private String downloadpath;
@Value("${ibiz.file.previewpath:ibizutil/preview}")
private String previewpath;
@Value("${ibiz.auth.excludesPattern:}")
private String[] excludesPattern;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoderBean());
}
@Bean
GrantedAuthorityDefaults grantedAuthorityDefaults() {
// Remove the ROLE_ prefix
return new GrantedAuthorityDefaults("");
}
@Bean
public PasswordEncoder passwordEncoderBean() {
return new BCryptPasswordEncoder();
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
// 禁用 CSRF
.csrf().disable()
// 授权异常
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
// 不创建会话
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
// 过滤请求
.authorizeRequests()
.antMatchers(
HttpMethod.GET,
"/*.html",
"/**/*.html",
"/**/*.css",
"/**/*.js",
"/**/*.ico",
"/**/assets/**",
"/**/css/**",
"/**/fonts/**",
"/**/js/**",
"/**/img/**",
"/",
"webjars/**",
"/swagger-resources/**",
"/v2/**"
).permitAll()
//放行登录请求
.antMatchers( HttpMethod.POST, "/"+loginPath).permitAll()
//放行注销请求
.antMatchers( HttpMethod.GET, "/"+logoutPath).permitAll()
// 文件操作
.antMatchers("/"+downloadpath+"/**").permitAll()
.antMatchers("/"+uploadpath).permitAll()
.antMatchers("/"+previewpath+"/**").permitAll();
for (String excludePattern : excludesPattern) {
authenticationTokenFilter.addExcludePattern(excludePattern);
httpSecurity.authorizeRequests().antMatchers(excludePattern).permitAll();
}
httpSecurity.authorizeRequests().anyRequest().authenticated()
// 防止iframe 造成跨域
.and().headers().frameOptions().disable();
httpSecurity
.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
}
}
server:
port: 8080
#zuul网关路由设置
zuul:
routes:
{{#if system.enableWorkflow}}
wfcore:
path: /wfcore/**
serviceId: ${ibiz.ref.service.wf:ibzwf-api}}
stripPrefix: true
{{/if}}
loginv7:
path: /v7/login
serviceId: ${ibiz.ref.service.uaa:ibzuaa-api}}
stripPrefix: false
changepwd:
path: /v7/changepwd
serviceId: ${ibiz.ref.service.uaa:ibzuaa-api}}
stripPrefix: false
uaa:
path: /uaa/**
serviceId: ${ibiz.ref.service.uaa:ibzuaa-api}}
stripPrefix: false
config:
path: /configs/**
serviceId: ${ibiz.ref.service.uaa:ibzuaa-api}}
stripPrefix: false
oucore:
path: /ibzorganizations/**
serviceId: ${ibiz.ref.service.ou:ibzou-api}}
stripPrefix: false
oudict:
path: /dictionarys/**/Ibzou**
serviceId: ${ibiz.ref.service.ou:ibzou-api}}
stripPrefix: false
ou:
path: /ibzdepartments/**
serviceId: ${ibiz.ref.service.ou:ibzou-api}}
stripPrefix: false
uaadict:
path: /dictionarys/**/SysOperator
serviceId: ${ibiz.ref.service.uaa:ibzuaa-api}}
stripPrefix: false
dict:
path: /dictionarys/**
serviceId: ${ibiz.ref.service.dict:ibzdict-api}}
stripPrefix: false
disk:
path: /net-disk/**
serviceId: ${ibiz.ref.service.disk:ibzdisk-api}}
stripPrefix: false
ou_sys_org:
path: /sysorganizations/**
serviceId: ${ibiz.ref.service.ou:ibzou-api}}
stripPrefix: false
ou_sys_dept:
path: /sysdepartments/**
serviceId: ${ibiz.ref.service.ou:ibzou-api}}
stripPrefix: false
lite-core:
path: /lite/**
serviceId: ${ibiz.ref.service.lite:ibzlite-api}}
stripPrefix: false
sysauthlog:
path: /sysauthlogs
serviceId: ${ibiz.ref.service.uaa:ibzuaa-api}}
stripPrefix: false
{{#each system.apps as | app |}}
{{#each app.appEntities}}
{{#eq entity.storage "ServiceAPI"}}
{{#serviceId}}
{{apps}}-{{lowerCase codeName}}:
path: /{{pluralize codeName}}/**
serviceId: ${ ibiz.ref.service.{{serviceId}}:{{serviceId}} }
stripPrefix: false
{{/serviceId}}
{{/eq}}
{{/each}}
{{/each}}
sensitive-headers:
- Cookie,Set-Cookie,Authorization
\ No newline at end of file
spring:
profiles:
include: sys , nacos ,{{#each apps}} {{apps}}-dev ,{{/each}}{{#each apis}} {{apis}}-dev ,{{/each}} dev
application:
name: {{projectName}}
main:
allow-bean-definition-overriding: true
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<property name="LOG_PATH" value="logs" />
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] %-40.40logger{39} : %msg%n" />
<!-- 彩色日志 -->
<!-- 彩色日志依赖的渲染类 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<!-- 彩色日志格式 -->
<property name="LOG_PATTERN2" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr([${LOG_LEVEL_PATTERN:-%5p}]) %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}}" />
<!-- 控制台输出 -->
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN}}</pattern>
</encoder>
</appender>
<!--<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">-->
<!-- <destination>127.0.0.1:9601</destination>-->
<!-- <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">-->
<!-- <customFields>{"appname":"{{projectName}}"}</customFields>-->
<!-- </encoder>-->
<!--</appender>-->
<!-- 按照每天生成日志文件 -->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_PATH}}/{{projectName}}.%d{yyyy-MM-dd}.log</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN}}</pattern>
</encoder>
<!--日志文件最大的大小-->
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>100MB</MaxFileSize>
</triggeringPolicy>
</appender>
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="Console" />
<appender-ref ref="file" />
<!--<appender-ref ref="LOGSTASH" />-->
</root>
</configuration>
package {{packageName}}.core.util.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
/**
* 通用配置类
*/
@Configuration
public class CommonAutoConfig {
@Value("${jbpm.enable.multi.con:true}")
private String flag;
/**
* 处理逻辑节点支持多来源配置
*/
@Component
public class InstallSystemParamsCommandLineRunner implements CommandLineRunner {
@Override
public void run(String... var1){
System.setProperty("jbpm.enable.multi.con", flag);
}
}
}
package {{packageName}}.core.util.config;
import org.kie.api.KieServices;
import org.kie.api.builder.KieFileSystem;
import org.kie.api.runtime.KieContainer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class DroolsAutoConfiguration {
@Bean
@ConditionalOnMissingBean(KieContainer.class)
public KieContainer kieContainer() {
KieServices kieServices = KieServices.get();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieServices.newKieBuilder(kieFileSystem).buildAll();
return kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId());
}
}
\ No newline at end of file
package {{packageName}}.core.util.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.apache.ibatis.mapping.DatabaseIdProvider;
import java.util.Properties;
import org.springframework.context.annotation.Primary;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.jdbc.DataSourceBuilder;
import cn.ibizlab.util.domain.LiquibaseProp;
import org.springframework.beans.factory.annotation.Autowired;
import liquibase.integration.spring.SpringLiquibase;
import org.springframework.util.StringUtils;
import com.alibaba.druid.pool.DruidDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
@Configuration
public class LiquibaseConfiguration {
/**
* 主数据源版本管理
* @param
* @return
*/
@Bean
public SpringLiquibase masterliquibase(LiquibaseProp masterProperties) {
return LiquibaseInit(masterProperties);
}
/**
* liquibase初始化数据库
* @param properties
* @return
*/
private SpringLiquibase LiquibaseInit(LiquibaseProp properties){
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setUsername(properties.getUsername());
druidDataSource.setPassword(properties.getPassword());
druidDataSource.setUrl(properties.getUrl());
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setDataSource(druidDataSource);
liquibase.setChangeLog(getChangelog(properties.getIsSyncDBSchema(),properties.getConf()));
liquibase.setContexts("development,test,production");
liquibase.setShouldRun(true);
liquibase.setDefaultSchema(properties.getDefaultSchema());
return liquibase;
}
/**
* 获取数据库差异文件
* @param isSyncDBSchema 是否同步表结构
* @param conf //liquibase配置文件
* @return
*/
private String getChangelog(String isSyncDBSchema,String conf){
String defaultChangelog="classpath:liquibase/empty.xml";
if((!StringUtils.isEmpty(isSyncDBSchema))&&(!StringUtils.isEmpty(conf))){
if(isSyncDBSchema.toLowerCase().equals("true"))
defaultChangelog=conf;
}
return defaultChangelog;
}
}
\ No newline at end of file
package {{packageName}}.core.util.config;
import cn.ibizlab.util.helper.JSR310DateConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.mongodb.core.convert.*;
import java.util.ArrayList;
import java.util.List;
@Configuration
public class MongoDBConfig {
@Bean
public MongoCustomConversions customConversions() {
List<Converter<?, ?>> converterList = new ArrayList<>();
converterList.add(JSR310DateConverters.DateToZonedDateTimeConverter.INSTANCE);
converterList.add(JSR310DateConverters.ZonedDateTimeToDateConverter.INSTANCE);
converterList.add(JSR310DateConverters.DurationToLongConverter.INSTANCE);
converterList.add(JSR310DateConverters.TimestampToDateConverter.INSTANCE);
converterList.add(JSR310DateConverters.DateToTimestampConverter.INSTANCE);
return new MongoCustomConversions(converterList);
}
}
\ No newline at end of file
package {{packageName}}.core.util.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Configuration;
/**
* mybatis自动配置
*/
@Configuration
@ConditionalOnClass(MybatisConfiguration.class)
@ConditionalOnWebApplication
public class MybatisAutoConfiguration {
}
package {{packageName}}.core.util.config;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import cn.ibizlab.util.helper.UniqueNameGenerator;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;
import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Properties;
{{#eq system.saaSMode 4}}
import com.baomidou.mybatisplus.core.parser.ISqlParserFilter;
import com.baomidou.mybatisplus.core.parser.SqlParserHelper;
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
import com.baomidou.mybatisplus.core.parser.ISqlParser;
import org.apache.ibatis.mapping.MappedStatement;
import java.util.ArrayList;
import java.util.List;
{{/eq}}
/**
* mybatis全局配置类
*/
@Configuration
@MapperScan(value="{{packageName}}.core.*.mapper",nameGenerator = UniqueNameGenerator.class)
public class MybatisConfiguration {
{{#eq system.saaSMode 4}}
@Autowired
private {{packageName}}.core.util.config.SaaSTenantProperties saaSTenantProperties;
{{/eq}}
/**
* mybatis适配多数据库
* @return
*/
@Bean
public DatabaseIdProvider getDatabaseIdProvider() {
DatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
Properties p = new Properties();
p.setProperty("Oracle", "oracle");
p.setProperty("MySQL", "mysql");
p.setProperty("PostgreSQL", "postgresql");
p.setProperty("DM", "oracle");//达梦数据库使用oracle模式
p.setProperty("H2", "mysql");//根据当前运行的数据库设置h2对应的databaseid
databaseIdProvider.setProperties(p);
return databaseIdProvider;
}
/**
* mybatis-plus分页
* @return
*/
@Bean
public PaginationInterceptor paginationInterceptor({{#eq system.saaSMode 4}}SaaSTenantHandler saaSTenantHandler{{/eq}}) {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
// 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false
// paginationInterceptor.setOverflow(false);
// 设置最大单页限制数量,默认 500 条,-1 不受限制
paginationInterceptor.setLimit(-1);
{{#eq system.saaSMode 4}}
// 创建SQL解析器集合
List<ISqlParser> sqlParserList = new ArrayList<>();
// 创建租户SQL解析器
SaaSTenantSqlParser tenantSqlParser = new SaaSTenantSqlParser();
// 设置租户处理器
tenantSqlParser.setTenantHandler(saaSTenantHandler);
sqlParserList.add(tenantSqlParser);
paginationInterceptor.setSqlParserList(sqlParserList);
// 设置租户忽略
paginationInterceptor.setSqlParserFilter(ignoreParserFilter());
{{/eq}}
// 开启 count 的 join 优化,只针对部分 left join
paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
return paginationInterceptor;
}
{{#eq system.saaSMode 4}}
@Bean
public ISqlParserFilter ignoreParserFilter() {
return metaObject -> {
// 此处就过滤
MappedStatement ms = SqlParserHelper.getMappedStatement(metaObject);
if (saaSTenantProperties.getIgnoreMappers().contains(ms.getId())) {
return true;
}
return false;
};
}
{{/eq}}
}
\ No newline at end of file
package {{packageName}}.core.util.config;
import com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration;
import cn.ibizlab.util.errors.BadRequestAlertException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.Query;
import java.lang.management.ManagementFactory;
import java.util.Set;
/**
* 外部容器启动服务时,自动注册服务到nacos
*/
@Component
@Slf4j
@ConditionalOnExpression("'${ibiz.deploy.packagetype:jar}'.equals('war')")
public class NacosRegisterConfig implements ApplicationRunner {
@Autowired(required = false)
private NacosAutoServiceRegistration registration;
@Value("${server.port:8080}")
Integer port;
@Override
public void run(ApplicationArguments args) {
log.info("正在尝试将应用程序注册到nacos");
if (registration != null && port != null) {
try {
String containerPort = getContainerPort();
if(!StringUtils.isEmpty(containerPort)){
registration.setPort(new Integer(containerPort));
}
else{
registration.setPort(port);
log.info("无法获取外部容器端口,将使用程序默认端口{}",port);
}
registration.start();
} catch (Exception e) {
throw new BadRequestAlertException("应用程序注册到nacos失败,"+e,"","");
}
log.info("已将应用程序成功注册到nacos");
}
else{
log.info("无法获取应用程序端口,将应用程序注册到nacos请求被忽略。");
}
}
/**
* 获取外部容器端口
*/
public String getContainerPort(){
String port = null;
try {
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = beanServer.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
if(!ObjectUtils.isEmpty(objectNames)){
port = objectNames.iterator().next().getKeyProperty("port");
}
}
catch (Exception e) {
log.error("获取外部容器端口失败!"+e);
}
return port;
}
}
</#if>
\ No newline at end of file
package {{packageName}}.core.util.config;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
@Slf4j
@Configuration
@ConditionalOnExpression("'${rocketmq.consumer.isOnOff:off}'.equals('on')")
public class RocketMQConsumer {
@Value("${rocketmq.consumer.groupName:default}")
private String groupName;
@Value("${rocketmq.consumer.topic:default}")
private String topic;
@Value("${rocketmq.consumer.namesrvAddr:127.0.0.1:9876}")
private String namesrvAddr;
@Value("${rocketmq.consumer.consumeThreadMin:1}")
private Integer consumeThreadMin;
@Value("${rocketmq.consumer.consumeThreadMax:1}")
private Integer consumeThreadMax;
@Value("${rocketmq.consumer.consumeMessageBatchMaxSize:1}")
private Integer consumeMessageBatchMaxSize;
@Autowired
@Lazy
private RocketMQListenerProcessor listenerProcessor;
/**
* mq 消费者配置
*
* @return
* @throws MQClientException
*/
@Bean
public DefaultMQPushConsumer defaultConsumer() {
log.info("defaultConsumer 正在创建---------------------------------------");
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(groupName);
consumer.setNamesrvAddr(namesrvAddr);
consumer.setConsumeThreadMin(consumeThreadMin);
consumer.setConsumeThreadMax(consumeThreadMax);
consumer.setConsumeMessageBatchMaxSize(consumeMessageBatchMaxSize);
// 设置监听
consumer.registerMessageListener(listenerProcessor);
/**
* 设置consumer第一次启动是从队列头部开始还是队列尾部开始
* 如果不是第一次启动,那么按照上次消费的位置继续消费
*/
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
/**
* 设置消费模型,集群还是广播,默认为集群
*/
//consumer.setMessageModel(MessageModel.CLUSTERING);
try {
consumer.subscribe(topic, "{{#each system.mqSubscribes}}{{#unless @first}} || {{/unless}}{{lowerCase this}}{{/each}}");
consumer.start();
log.info("rocketmq consumer 创建成功 groupName={}, topics={}, namesrvAddr={}", groupName, topic, namesrvAddr);
} catch (MQClientException e) {
log.error("rocketmq consumer 创建失败!" + e);
}
return consumer;
}
}
\ No newline at end of file
package {{packageName}}.core.util.config;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import cn.ibizlab.util.domain.EntityBase;
import java.util.List;
import java.util.Map;
/**
* MQ订阅消息处理
*/
@Slf4j
@Component
@ConditionalOnExpression("'${rocketmq.consumer.isOnOff:off}'.equals('on')")
public class RocketMQListenerProcessor implements MessageListenerOrderly {
{{#each system.entities as | entity |}}
{{#if entity.allPSDEDataSyncs}}
@Autowired
@Lazy
{{packageName}}.core.{{entity.module}}.service.I{{entity.codeName}}Service {{camelCase entity.codeName}}Service;
{{/if}}
{{/each}}
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> list, ConsumeOrderlyContext consumeOrderlyContext) {
if (CollectionUtils.isEmpty(list)) {
log.info("MQ接收消息为空,直接返回成功");
return ConsumeOrderlyStatus.SUCCESS;
}
for (MessageExt messageExt : list) {
log.info("MQ接收到的消息为:" + messageExt.toString());
try {
String topic = messageExt.getTopic();
String tags = messageExt.getTags();
String body = new String(messageExt.getBody(),"utf-8");
log.info("MQ消息topic={}, tags={}, 消息内容={}", topic, tags, body);
{{#each system.entities as | entity |}}
{{#each entity.allPSDEDataSyncs as | dataSync |}}
{{#if dataSync.inPSSysDataSyncAgent}}
{{#if dataSync.inTestPSDEAction}}
{{#unless @first}}else {{/unless}}if ("{{lowerCase dataSync.codeName}}".equalsIgnoreCase(tags)) {
{{packageName}}.core.{{entity.module}}.domain.{{entity.codeName}} domain = EntityBase.fromJSONString(body,{{packageName}}.core.{{entity.module}}.domain.{{entity.codeName}}.class);
{{camelCase entity.codeName}}Service.{{camelCase dataSync.inTestPSDEAction.codeName}}(domain);
}
{{else}}
log.info("接收到[{"+tags+"}]消息,但未配置实体输入过滤行为,消息将被忽略。"+body);
{{/if}}
{{/if}}
{{/each}}
{{/each}}
} catch (Exception e) {
log.error("获取MQ消息内容异常{}", e);
}
}
return ConsumeOrderlyStatus.SUCCESS;
}
}
\ No newline at end of file
package {{packageName}}.core.util.config;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
@Slf4j
@Configuration
@ConditionalOnExpression("'${rocketmq.producer.isOnOff:off}'.equals('on')")
public class RocketMQProducer {
@Value("${rocketmq.producer.groupName:default}")
private String groupName;
@Value("${rocketmq.producer.namesrvAddr:127.0.0.1:9876}")
private String namesrvAddr;
// 消息最大值
@Value("${rocketmq.producer.maxMessageSize:409600}")
private Integer maxMessageSize;
// 消息发送超时时间
@Value("${rocketmq.producer.sendMsgTimeOut:3000}")
private Integer sendMsgTimeOut;
// 失败重试次数
@Value("${rocketmq.producer.retryTimesWhenSendFailed:2}")
private Integer retryTimesWhenSendFailed;
/**
* mq 生成者配置
*
* @return
* @throws MQClientException
*/
@Bean
public DefaultMQProducer defaultProducer() throws MQClientException {
log.info("rocketmq defaultProducer 正在创建---------------------------------------");
DefaultMQProducer producer = new DefaultMQProducer(groupName);
producer.setNamesrvAddr(namesrvAddr);
producer.setVipChannelEnabled(false);
producer.setMaxMessageSize(maxMessageSize);
producer.setSendMsgTimeout(sendMsgTimeOut);
producer.setRetryTimesWhenSendAsyncFailed(retryTimesWhenSendFailed);
producer.start();
log.info("rocketmq producer server 开启成功----------------------------------");
return producer;
}
}
{{#eq system.saaSMode 4}}
package {{packageName}}.core.util.config;
import cn.ibizlab.util.security.AuthenticationUser;
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.StringValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@EnableConfigurationProperties(SaaSTenantProperties.class)
public class SaaSTenantHandler implements TenantHandler {
@Autowired
private SaaSTenantProperties saaSTenantProperties;
@Override
public Expression getTenantId(boolean where) {
AuthenticationUser user = AuthenticationUser.getAuthenticationUser();
return new StringValue(user.getSrfdcid());
}
@Override
public String getTenantIdColumn() {
return saaSTenantProperties.getColumn();
}
@Override
public boolean doTableFilter(String tableName) {
String strTableName = tableName.replace("`","") ;
if (saaSTenantProperties.getSysTables().stream().anyMatch(table -> table.equalsIgnoreCase(strTableName)))
return true;
return false;
}
}
{{/eq}}
\ No newline at end of file
{{#eq system.saaSMode 4}}
package {{packageName}}.core.util.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@ConfigurationProperties(prefix = "ibiz.saas")
public class SaaSTenantProperties {
/**
* 多租户字段名称
*/
private String column = "SRFDCID";
/**
* 多租户系统数据表
*/
private List<String> sysTables = new ArrayList<>();
/**
* 多租户忽略租户查询
*/
private List<String> ignoreMappers = new ArrayList<>();
}
{{/eq}}
\ No newline at end of file
{{#eq system.saaSMode 4}}
package {{packageName}}.core.util.config;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
import net.sf.jsqlparser.expression.*;
import net.sf.jsqlparser.expression.operators.arithmetic.Addition;
import net.sf.jsqlparser.expression.operators.arithmetic.Division;
import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication;
import net.sf.jsqlparser.expression.operators.arithmetic.Subtraction;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
import net.sf.jsqlparser.expression.operators.relational.*;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.select.*;
import java.util.List;
public class SaaSTenantSqlParser extends TenantSqlParser {
/**
* 处理 PlainSelect
*
* @param plainSelect ignore
* @param addColumn 是否添加租户列,insert into select语句中需要
*/
@Override
protected void processPlainSelect(PlainSelect plainSelect, boolean addColumn) {
//处理selectItem表达式
processSelectItem(plainSelect);
FromItem fromItem = plainSelect.getFromItem();
if (fromItem instanceof Table) {
Table fromTable = (Table) fromItem;
if (!this.getTenantHandler().doTableFilter(fromTable.getName())) {
plainSelect.setWhere(builderExpression(plainSelect.getWhere(), fromTable));
if (addColumn) {
if (fromItem.getAlias() != null) {
plainSelect.getSelectItems().add(new SelectExpressionItem(new Column(fromItem.getAlias().getName() + StringPool.DOT + this.getTenantHandler().getTenantIdColumn())));
}else {
plainSelect.getSelectItems().add(new SelectExpressionItem(new Column(this.getTenantHandler().getTenantIdColumn())));
}
}
}
} else {
processFromItem(fromItem);
}
List<Join> joins = plainSelect.getJoins();
if (joins != null && joins.size() > 0) {
joins.forEach(j -> {
processJoin(j);
processFromItem(j.getRightItem());
});
}
//处理where表达式
processExcepression(plainSelect.getWhere());
}
/**
* exception 表达式处理
*/
protected void processExcepression(Expression exception) {
if (exception == null) {
return;
}else if (exception instanceof AndExpression) {
processExcepression(((AndExpression) exception).getLeftExpression());
processExcepression(((AndExpression) exception).getRightExpression());
} else if (exception instanceof OrExpression) {
processExcepression(((OrExpression) exception).getLeftExpression());
processExcepression(((OrExpression) exception).getRightExpression());
} else if (exception instanceof Parenthesis) {
processExcepression(((Parenthesis) exception).getExpression());
} else if (exception instanceof NotExpression) {
processExcepression(((NotExpression) exception).getExpression());
} else if (exception instanceof InExpression) {
processExcepression(((InExpression) exception).getLeftExpression());
if(((InExpression) exception).getRightItemsList() instanceof SubSelect) {
this.processSelectBody(((SubSelect) ((InExpression) exception).getRightItemsList()).getSelectBody());
}
} else if (exception instanceof EqualsTo) {
processExcepression(((EqualsTo) exception).getLeftExpression());
processExcepression(((EqualsTo) exception).getRightExpression());
} else if (exception instanceof ExistsExpression) {
processExcepression(((ExistsExpression) exception).getRightExpression());
} else if (exception instanceof GreaterThan) {
processExcepression(((GreaterThan) exception).getLeftExpression());
processExcepression(((GreaterThan) exception).getRightExpression());
} else if (exception instanceof GreaterThanEquals) {
processExcepression(((GreaterThanEquals) exception).getLeftExpression());
processExcepression(((GreaterThanEquals) exception).getRightExpression());
} else if (exception instanceof MinorThan) {
processExcepression(((MinorThan) exception).getLeftExpression());
processExcepression(((MinorThan) exception).getRightExpression());
} else if (exception instanceof MinorThanEquals) {
processExcepression(((MinorThanEquals) exception).getLeftExpression());
processExcepression(((MinorThanEquals) exception).getRightExpression());
} else if (exception instanceof NotEqualsTo) {
processExcepression(((NotEqualsTo) exception).getLeftExpression());
processExcepression(((NotEqualsTo) exception).getRightExpression());
} else if (exception instanceof IsBooleanExpression) {
processExcepression(((IsBooleanExpression) exception).getLeftExpression());
} else if (exception instanceof IsNullExpression) {
processExcepression(((IsNullExpression) exception).getLeftExpression());
} else if (exception instanceof LikeExpression) {
processExcepression(((LikeExpression) exception).getLeftExpression());
processExcepression(((LikeExpression) exception).getRightExpression());
} else if (exception instanceof Between) {
processExcepression(((Between) exception).getLeftExpression());
processExcepression(((Between) exception).getBetweenExpressionStart());
processExcepression(((Between) exception).getBetweenExpressionEnd());
} else if (exception instanceof Function) {
if(null != ((Function) exception).getParameters()) {
for (Expression e : ((Function) exception).getParameters().getExpressions()) {
processExcepression(e);
}
}
} else if (exception instanceof CaseExpression) {
CaseExpression caseExpression = (CaseExpression) exception;
processExcepression(caseExpression.getElseExpression());
processExcepression(caseExpression.getSwitchExpression());
for (WhenClause whenClause : caseExpression.getWhenClauses()) {
processExcepression(whenClause.getWhenExpression());
processExcepression(whenClause.getThenExpression());
}
}else if(exception instanceof Subtraction){
processExcepression(((Subtraction) exception).getLeftExpression());
processExcepression(((Subtraction) exception).getRightExpression());
}else if(exception instanceof Multiplication){
processExcepression(((Multiplication) exception).getLeftExpression());
processExcepression(((Multiplication) exception).getRightExpression());
}else if(exception instanceof Addition){
processExcepression(((Addition) exception).getLeftExpression());
processExcepression(((Addition) exception).getRightExpression());
}else if(exception instanceof Division){
processExcepression(((Division) exception).getLeftExpression());
processExcepression(((Division) exception).getRightExpression());
} else if (exception instanceof SubSelect) {
this.processSelectBody(((SubSelect) exception).getSelectBody());
}
}
/**
* select 中包含 select、function 添加租户id
*/
protected void processSelectItem(PlainSelect plainSelect) {
List<SelectItem> selectItems = plainSelect.getSelectItems();
for (SelectItem selectItem : selectItems) {
if (selectItem instanceof SelectExpressionItem) {
Expression selectExcepression = ((SelectExpressionItem) selectItem).getExpression();
processExcepression(selectExcepression);
}
}
}
}
{{/eq}}
\ No newline at end of file
...@@ -14,14 +14,14 @@ import com.fasterxml.jackson.annotation.JsonProperty; ...@@ -14,14 +14,14 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
import {{packageName}}.util.domain.EntityBase; import cn.ibizlab.util.domain.EntityBase;
import {{packageName}}.util.annotation.DEField; import cn.ibizlab.util.annotation.DEField;
import {{packageName}}.util.enums.DEPredefinedFieldType; import cn.ibizlab.util.enums.DEPredefinedFieldType;
import {{packageName}}.util.enums.DEFieldDefaultValueType; import cn.ibizlab.util.enums.DEFieldDefaultValueType;
import {{packageName}}.util.helper.DataObject; import cn.ibizlab.util.helper.DataObject;
import {{packageName}}.util.annotation.Audit; import cn.ibizlab.util.annotation.Audit;
import {{packageName}}.util.enums.DupCheck; import cn.ibizlab.util.enums.DupCheck;
import {{packageName}}.util.domain.EntityMP; import cn.ibizlab.util.domain.EntityMP;
import java.io.Serializable; import java.io.Serializable;
import lombok.*; import lombok.*;
import org.springframework.data.annotation.Transient; import org.springframework.data.annotation.Transient;
......
...@@ -18,7 +18,7 @@ import org.springframework.util.StringUtils; ...@@ -18,7 +18,7 @@ import org.springframework.util.StringUtils;
{{#entity.enableES}} {{#entity.enableES}}
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
{{/entity.enableES}} {{/entity.enableES}}
import {{packageName}}.util.filter.QueryWrapperContext; import cn.ibizlab.util.filter.QueryWrapperContext;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import {{packageName}}.core.{{module}}.filte.{{entity.codeName}}; import {{packageName}}.core.{{module}}.filte.{{entity.codeName}};
/** /**
......
...@@ -27,6 +27,10 @@ import {{packageName}}.core.{{module}}.filter.{{entity.codeName}}SearchContext; ...@@ -27,6 +27,10 @@ import {{packageName}}.core.{{module}}.filter.{{entity.codeName}}SearchContext;
public interface I{{entity.codeName}}Service extends IService<{{entity.codeName}}> { public interface I{{entity.codeName}}Service extends IService<{{entity.codeName}}> {
{{entity.codeName}} get({{entity.keyField.type.java}} key); {{entity.codeName}} get({{entity.keyField.type.java}} key);
default {{entity.codeName}} get({{entity.codeName}} et) {
CachedBeanCopier.copy(get(et.get{{pascalCase entity.keyField.codeName}}()), et);
return et;
}
List<{{entity.codeName}}> getByIds(Collection<{{entity.keyField.type.java}}> idList); List<{{entity.codeName}}> getByIds(Collection<{{entity.keyField.type.java}}> idList);
List<{{entity.codeName}}> getByEntities(Collection<{{entity.codeName}}> entities); List<{{entity.codeName}}> getByEntities(Collection<{{entity.codeName}}> entities);
...@@ -53,6 +57,9 @@ public interface I{{entity.codeName}}Service extends IService<{{entity.codeName} ...@@ -53,6 +57,9 @@ public interface I{{entity.codeName}}Service extends IService<{{entity.codeName}
boolean saveBatch(List<{{entity.codeName}}> list); boolean saveBatch(List<{{entity.codeName}}> list);
boolean remove({{entity.keyField.type.java}} key); boolean remove({{entity.keyField.type.java}} key);
default boolean remove({{entity.codeName}} et) {
return remove(et.get{{pascalCase entity.keyField.codeName}}());
}
{{#enableEntityCache}} {{#enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true) @CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/enableEntityCache}} {{/enableEntityCache}}
......
...@@ -21,7 +21,7 @@ import org.springframework.data.domain.Pageable; ...@@ -21,7 +21,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import {{packageName}}.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
<#system.enableGlobalTransaction> <#system.enableGlobalTransaction>
import io.seata.spring.annotation.GlobalTransactional; import io.seata.spring.annotation.GlobalTransactional;
</system.enableGlobalTransaction> </system.enableGlobalTransaction>
...@@ -31,8 +31,8 @@ import {{packageName}}.core.{{entity.module}}.domain.{{entity.codeName}}; ...@@ -31,8 +31,8 @@ import {{packageName}}.core.{{entity.module}}.domain.{{entity.codeName}};
import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchContext; import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchContext;
import {{packageName}}.core.{{entity.module}}.service.I{{entity.codeName}}Service; import {{packageName}}.core.{{entity.module}}.service.I{{entity.codeName}}Service;
import {{packageName}}.core.{{entity.module}}.mapper.${item.getCodeName()}Mapper; import {{packageName}}.core.{{entity.module}}.mapper.${item.getCodeName()}Mapper;
import {{packageName}}.util.helper.CachedBeanCopier; import cn.ibizlab.util.helper.CachedBeanCopier;
import {{packageName}}.util.helper.DEFieldCacheMap; import cn.ibizlab.util.helper.DEFieldCacheMap;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
......
<#ibiztemplate>
TARGET=PSSYSTEM
</#ibiztemplate>
<#assign eurekaUrl = "http://127.0.0.1:8762/eureka/" >
<#comment>前端应用微服务平台配置</#comment>
<#if sys.getAllPSDevSlnMSDepApps()??>
<#list sys.getAllPSDevSlnMSDepApps() as depApp>
<#if depApp.getPSDCMSPlatform()??>
<#assign appPlatform=depApp.getPSDCMSPlatform()>
<#if appPlatform.getUserParam("eureka","http://127.0.0.1:8762/eureka/")??>
<#assign eurekaUrl = appPlatform.getUserParam("eureka","http://127.0.0.1:8762/eureka/")>
</#if>
<#break>
</#if>
</#list>
</#if>
<#comment>服务接口微服务平台配置</#comment>
<#if sys.getAllPSDevSlnMSDepAPIs()??>
<#list sys.getAllPSDevSlnMSDepAPIs() as depSysApi>
<#if depSysApi.getPSDCMSPlatform()?? >
<#assign sysApiPlatform=depSysApi.getPSDCMSPlatform()>
<#if sysApiPlatform.getUserParam("eureka","http://127.0.0.1:8762/eureka/")??>
<#assign eurekaUrl = sysApiPlatform.getUserParam("eureka","http://127.0.0.1:8762/eureka/")>
</#if>
<#break>
</#if>
</#list>
</#if>
#eureka配置中心
spring:
cloud:
nacos:
discovery:
enabled: false
eureka:
client:
enabled: true
serviceUrl:
defaultZone: ${eurekaUrl}
<#ibiztemplate>
TARGET=PSSYSTEM
</#ibiztemplate>
<#assign nacosUrl = "127.0.0.1:8848" >
<#comment>前端应用微服务平台配置</#comment>
<#if sys.getAllPSDevSlnMSDepApps()??>
<#list sys.getAllPSDevSlnMSDepApps() as depApp>
<#if depApp.getPSDCMSPlatform()??>
<#assign appPlatform=depApp.getPSDCMSPlatform()>
<#if appPlatform.getUserParam("nacos","127.0.0.1:8848")??>
<#assign nacosUrl = appPlatform.getUserParam("nacos","127.0.0.1:8848")>
</#if>
<#break>
</#if>
</#list>
</#if>
<#comment>服务接口微服务平台配置</#comment>
<#if sys.getAllPSDevSlnMSDepAPIs()??>
<#list sys.getAllPSDevSlnMSDepAPIs() as depSysApi>
<#if depSysApi.getPSDCMSPlatform()?? >
<#assign sysApiPlatform=depSysApi.getPSDCMSPlatform()>
<#if sysApiPlatform.getUserParam("nacos","127.0.0.1:8848")??>
<#assign nacosUrl = sysApiPlatform.getUserParam("nacos","127.0.0.1:8848")>
</#if>
<#break>
</#if>
</#list>
</#if>
#nacos配置中心
spring:
cloud:
nacos:
discovery:
server-addr: ${nacosUrl}
enabled: true
eureka:
client:
enabled: false
<#ibiztemplate>
TARGET=PSSYSTEM
</#ibiztemplate>
<#comment>通用配置文件</#comment>
<#assign redisHost = "127.0.0.1" >
<#assign redisPort = "6379" >
<#assign redisDataBase = "0" >
<#assign dbUserName="root">
<#assign dbPassWord="root">
<#assign dbUrl="jdbc:mysql://127.0.0.1:3306/"+sys.name+"?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&allowMultiQueries=true">
<#assign dbDriver="com.mysql.jdbc.Driver">
<#assign bDynamicDS=false>
<#assign bmogo=false>
<#assign mongodbUri="mongodb://"+sys.name+":"+sys.name+"@127.0.0.1:27017/"+sys.name>
<#assign hasMQProducer=false>
<#assign hasMQConsumer=false>
<#if sys.getAllPSDataEntities()??>
<#list sys.getAllPSDataEntities() as de>
<#if de.getStorageMode()?? && de.getStorageMode()==2>
<#assign bmogo=true>
<#break >
</#if>
</#list>
</#if>
<#list sys.getAllPSDataEntities() as entity>
<#if (entity.getStorageMode()==1 || entity.getStorageMode()==2) && entity.getDSLink()!='DEFAULT'>
<#assign bDynamicDS=true>
<#break>
</#if>
</#list>
<#assign hasESEntity=false>
<#list sys.getAllPSDataEntities() as dataEntity>
<#if dataEntity.getUserTag()?? && dataEntity.getUserTag()=='elasticsearch'>
<#assign hasESEntity=true>
<#break>
</#if>
</#list>
<#assign TcServerCluster="default">
<#assign seataServerName="seata-server">
<#assign nacosAddress="localhost">
<#assign nacosGroup="DEFAULT_GROUP">
<#assign nacosNamespace="">
<#assign nacosUserName="">
<#assign nacosPassWord="">
<#comment>前端应用微服务平台配置</#comment>
<#if sys.getAllPSDevSlnMSDepApps()??>
<#list sys.getAllPSDevSlnMSDepApps() as depApp>
<#if depApp.getPSDCMSPlatform()??>
<#assign appPlatform=depApp.getPSDCMSPlatform()>
<#if appPlatform.getUserParam("spring.redis.host","127.0.0.1")??>
<#assign redisHost = appPlatform.getUserParam("spring.redis.host","127.0.0.1")>
</#if>
<#if appPlatform.getUserParam("spring.redis.port","6379")??>
<#assign redisPort = appPlatform.getUserParam("spring.redis.port","6379")>
</#if>
<#if appPlatform.getUserParam("spring.redis.database","0")??>
<#assign redisDataBase = appPlatform.getUserParam("spring.redis.database","0")>
</#if>
<#if appPlatform.getUserParam("spring.data.mongodb.uri",mongodbUri)??>
<#assign mongodbUri = appPlatform.getUserParam("spring.data.mongodb.uri",mongodbUri)>
</#if>
<#if appPlatform.getUserParam("seata.service.vgroup-mapping."+sys.getName()+"group",TcServerCluster)??>
<#assign TcServerCluster = appPlatform.getUserParam("seata.service.vgroup-mapping."+sys.getName()+"group",TcServerCluster)>
</#if>
<#if appPlatform.getUserParam("seata.registry.nacos.application",seataServerName)??>
<#assign seataServerName = appPlatform.getUserParam("seata.registry.nacos.application",seataServerName)>
</#if>
<#if appPlatform.getUserParam("seata.registry.nacos.server-addr",nacosAddress)??>
<#assign nacosAddress = appPlatform.getUserParam("seata.registry.nacos.server-addr",nacosAddress)>
</#if>
<#if appPlatform.getUserParam("seata.registry.nacos.group",nacosGroup)??>
<#assign nacosGroup = appPlatform.getUserParam("seata.registry.nacos.group",nacosGroup)>
</#if>
<#if appPlatform.getUserParam("seata.registry.nacos.namespace",nacosNamespace)??>
<#assign nacosNamespace = appPlatform.getUserParam("seata.registry.nacos.namespace",nacosNamespace)>
</#if>
<#if appPlatform.getUserParam("seata.registry.nacos.userName",nacosUserName)??>
<#assign nacosUserName = appPlatform.getUserParam("seata.registry.nacos.userName",nacosUserName)>
</#if>
<#if appPlatform.getUserParam("seata.registry.nacos.password",nacosPassWord)??>
<#assign nacosPassWord = appPlatform.getUserParam("seata.registry.nacos.password",nacosPassWord)>
</#if>
<#break>
</#if>
</#list>
</#if>
<#comment>服务接口微服务平台配置</#comment>
<#if sys.getAllPSDevSlnMSDepAPIs()??>
<#list sys.getAllPSDevSlnMSDepAPIs() as depSysApi>
<#if depSysApi.getPSDCMSPlatform()?? >
<#assign sysApiPlatform=depSysApi.getPSDCMSPlatform()>
<#if sysApiPlatform.getUserParam("spring.redis.host","127.0.0.1")??>
<#assign redisHost = sysApiPlatform.getUserParam("spring.redis.host","127.0.0.1")>
</#if>
<#if sysApiPlatform.getUserParam("spring.redis.port","6379")??>
<#assign redisPort = sysApiPlatform.getUserParam("spring.redis.port","6379")>
</#if>
<#if sysApiPlatform.getUserParam("spring.redis.database","0")??>
<#assign redisDataBase = sysApiPlatform.getUserParam("spring.redis.database","0")>
</#if>
<#if sysApiPlatform.getUserParam("spring.data.mongodb.uri",mongodbUri)??>
<#assign mongodbUri = sysApiPlatform.getUserParam("spring.data.mongodb.uri",mongodbUri)>
</#if>
<#if sysApiPlatform.getUserParam("seata.service.vgroup-mapping."+sys.getName()+"group",TcServerCluster)??>
<#assign TcServerCluster = sysApiPlatform.getUserParam("seata.service.vgroup-mapping."+sys.getName()+"group",TcServerCluster)>
</#if>
<#if sysApiPlatform.getUserParam("seata.registry.nacos.application",seataServerName)??>
<#assign seataServerName = sysApiPlatform.getUserParam("seata.registry.nacos.application",seataServerName)>
</#if>
<#if sysApiPlatform.getUserParam("seata.registry.nacos.server-addr",nacosAddress)??>
<#assign nacosAddress = sysApiPlatform.getUserParam("seata.registry.nacos.server-addr",nacosAddress)>
</#if>
<#if sysApiPlatform.getUserParam("seata.registry.nacos.group",nacosGroup)??>
<#assign nacosGroup = sysApiPlatform.getUserParam("seata.registry.nacos.group",nacosGroup)>
</#if>
<#if sysApiPlatform.getUserParam("seata.registry.nacos.namespace",nacosNamespace)??>
<#assign nacosNamespace = sysApiPlatform.getUserParam("seata.registry.nacos.namespace",nacosNamespace)>
</#if>
<#if sysApiPlatform.getUserParam("seata.registry.nacos.userName",nacosUserName)??>
<#assign nacosUserName = sysApiPlatform.getUserParam("seata.registry.nacos.userName",nacosUserName)>
</#if>
<#if sysApiPlatform.getUserParam("seata.registry.nacos.password",nacosPassWord)??>
<#assign nacosPassWord = sysApiPlatform.getUserParam("seata.registry.nacos.password",nacosPassWord)>
</#if>
<#break>
</#if>
</#list>
</#if>
<#comment>一键发布数据库配置</#comment>
<#if sysrun.getPSDBDevInst()??>
<#assign sysRunDBInst = sysrun.getPSDBDevInst()>
<#assign dbUserName=sysRunDBInst.getUserName()>
<#assign dbPassWord=sysRunDBInst.getPassword()>
<#assign dbUrl=sysRunDBInst.getConnUrl()>
<#if (sysRunDBInst.getDBType()=='MYSQL5')>
<#assign dbDriver="com.mysql.jdbc.Driver">
<#assign dbUrl=dbUrl+"&allowMultiQueries=true">
<#elseif (sysRunDBInst.getDBType()=='DB2')>
<#assign dbDriver="com.ibm.db2.jcc.DB2Driver">
<#elseif (sysRunDBInst.getDBType()=='ORACLE')>
<#assign dbDriver="oracle.jdbc.driver.OracleDriver">
<#elseif (sysRunDBInst.getDBType()=='SQLSERVER')>
<#assign dbDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver">
<#elseif (sysRunDBInst.getDBType()=='POSTGRESQL')>
<#assign dbDriver="org.postgresql.Driver">
<#elseif (sysRunDBInst.getDBType()=='PPAS')>
<#assign dbDriver="com.edb.Driver">
</#if>
</#if>
<#comment>部署-前端应用数据库配置</#comment>
<#if sys.getAllPSDevSlnMSDepApps()??>
<#list sys.getAllPSDevSlnMSDepApps() as depApp>
<#if depApp.getPSDBDevInst()??>
<#assign appDBInst=depApp.getPSDBDevInst()>
<#assign dbUserName=appDBInst.getUserName()>
<#assign dbPassWord=appDBInst.getPassword()>
<#assign dbUrl=appDBInst.getConnUrl()>
<#if (appDBInst.getDBType()=='MYSQL5')>
<#assign dbDriver="com.mysql.jdbc.Driver">
<#assign dbUrl=dbUrl+"&allowMultiQueries=true">
<#elseif (appDBInst.getDBType()=='DB2')>
<#assign dbDriver="com.ibm.db2.jcc.DB2Driver">
<#elseif (appDBInst.getDBType()=='ORACLE')>
<#assign dbDriver="oracle.jdbc.driver.OracleDriver">
<#elseif (appDBInst.getDBType()=='SQLSERVER')>
<#assign dbDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver">
<#elseif (appDBInst.getDBType()=='POSTGRESQL')>
<#assign dbDriver="org.postgresql.Driver">
<#elseif (appDBInst.getDBType()=='PPAS')>
<#assign dbDriver="com.edb.Driver">
</#if>
<#break>
</#if>
</#list>
</#if>
<#comment>部署-服务接口数据库配置</#comment>
<#if sys.getAllPSDevSlnMSDepAPIs()??>
<#list sys.getAllPSDevSlnMSDepAPIs() as depSysApi>
<#if depSysApi.getPSDBDevInst()??>
<#assign sysApiDBInst=depSysApi.getPSDBDevInst()>
<#assign dbUserName=sysApiDBInst.getUserName()>
<#assign dbPassWord=sysApiDBInst.getPassword()>
<#assign dbUrl=sysApiDBInst.getConnUrl()>
<#if (sysApiDBInst.getDBType()=='MYSQL5')>
<#assign dbDriver="com.mysql.jdbc.Driver">
<#assign dbUrl=dbUrl+"&allowMultiQueries=true&serverTimezone=GMT%2B8">
<#elseif (sysApiDBInst.getDBType()=='DB2')>
<#assign dbDriver="com.ibm.db2.jcc.DB2Driver">
<#elseif (sysApiDBInst.getDBType()=='ORACLE')>
<#assign dbDriver="oracle.jdbc.driver.OracleDriver">
<#elseif (sysApiDBInst.getDBType()=='SQLSERVER')>
<#assign dbDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver">
<#elseif (sysApiDBInst.getDBType()=='POSTGRESQL')>
<#assign dbDriver="org.postgresql.Driver">
<#elseif (sysApiDBInst.getDBType()=='PPAS')>
<#assign dbDriver="com.edb.Driver">
</#if>
<#break>
</#if>
</#list>
</#if>
#缓存、数据源
spring:
cache:
redis:
time-to-live: 3600
caffeine:
spec: initialCapacity=5,maximumSize=500,expireAfterWrite=3600s
redis:
host: ${redisHost}
port: ${redisPort}
password:
database: ${redisDataBase}
lettuce:
pool:
max-active: 32
max-wait: 300ms
max-idle: 16
min-idle: 8
servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB
<#if bmogo || hasESEntity>
data:
<#if bmogo>
mongodb:
uri: ${mongodbUri}
</#if>
<#if hasESEntity>
elasticsearch:
cluster-name: es-cluster
cluster-nodes: 127.0.0.1:9300
repositories:
enabled: true
</#if>
<#if hasESEntity>
management:
health:
elasticsearch:
enabled: false
</#if>
</#if>
<#if bDynamicDS>
<@dynamicDatasourceConfig/>
<#else>
<@singleDatasourceConfig/>
</#if>
#Mybatis-plus配置
mybatis-plus:
global-config:
refresh-mapper: true
db-config:
# 全局逻辑已删除默认值
logic-delete-value: 0
# 全局逻辑未删除默认值
logic-not-delete-value: 1
mapper-locations: classpath*:/mapper/*/*/*.xml
configuration:
jdbc-type-for-null: 'null'
map-underscore-to-camel-case: false
#阿里sentinel熔断器
feign:
httpclient:
enabled: true
sentinel:
enabled: true
compression:
request:
enabled: true
mime-types: application/javascript,text/css,application/json,application/xml,text/html,text/xml,text/plain
min-response-size: 10240
response:
enabled: true
#Log配置
logging:
level:
${pub.getPKGCodeName()}: debug
org.springframework.boot.autoconfigure: ERROR
#zuul网关超时设置
ribbon:
ReadTimeout: 60000
ConnectTimeout: 60000
<#assign enableDataAcc="false">
#系统是否开启权限验证、是否开启缓存
#缓存级别:无缓存(无配置项)、一级缓存(L1)、二级缓存(L2)
ibiz:
<#if sys.getPSSystemSetting()?? && sys.getPSSystemSetting().getDataAccCtrlArch()?? && sys.getPSSystemSetting().getDataAccCtrlArch()==1>
<#assign enableDataAcc="true">
</#if>
enablePermissionValid: ${enableDataAcc}
cacheLevel: L1 #(L1)一级本地caffeine缓存;(L2)caffeine缓存+Redis缓存
<#if sys.getSaaSMode()==4>
saas:
column: SRFDCID
sys-tables: ACT_RU_TASK,act_re_procdef,databasechangelog,databasechangeloglock<#list sys.getAllPSDataEntities() as entity><#if entity.getStorageMode()==1 && entity.getSaaSMode()==0>,${entity.getTableName()}</#if></#list>
</#if>
### jobs
jobs:
#admin-address: http://127.0.0.1:40005
app-name: ${sys.getName()}
app-port: 9999
#app-ip: 127.0.0.1
### 启用Gzip压缩
server:
compression:
enabled: true
mime-types: application/javascript,text/css,application/json,application/xml,text/html,text/xml,text/plain
min-response-size: 10240
<#if pub.isEnableGlobalTransaction?? && pub.isEnableGlobalTransaction()?? && pub.isEnableGlobalTransaction()==true>
seata:
enabled: true #是否开启全局事务
application-id: ${sys.getName()} #服务标识
tx-service-group: ${sys.getName()}group #事务组
service:
vgroup-mapping:
${sys.getName()}group: ${TcServerCluster} #指定事务组对应的Tc Server集群
registry:
type: nacos #注册中心
nacos:
application: ${seataServerName} #Tc Server服务标识
server-addr: ${nacosAddress} #注册中心地址
group: ${nacosGroup} #服务组
namespace: ${nacosNamespace} #服务命名空间
userName: "${nacosUserName}" #用户名
password: "${nacosPassWord}" #密码
</#if>
<#assign producerMQServer="127.0.0.1:9876">
<#assign consumerMQServer="127.0.0.1:9876">
<#assign producerisOnOff="off">
<#assign consumerisOnOff="off">
<#assign producerGroupName="default">
<#assign consumerGroupName="default">
<#assign producerTopic="default">
<#assign consumerTopic="default">
<#if sys.getAllPSDevSlnMSDepAPIs()??>
<#list sys.getAllPSDevSlnMSDepAPIs() as depSysApi>
<#if depSysApi.getPSDCMSPlatform()?? >
<#if depSysApi.getUserParam("rocketmq.producer.namesrvAddr","")?? && depSysApi.getUserParam("rocketmq.producer.namesrvAddr","")!=''>
<#assign hasMQProducer=true>
<#assign producerMQServer=depSysApi.getUserParam("rocketmq.producer.namesrvAddr","")>
<#if depSysApi.getUserParam("rocketmq.producer.isOnOff","")?? && depSysApi.getUserParam("rocketmq.producer.isOnOff","")!=''>
<#assign producerMQServer=depSysApi.getUserParam("rocketmq.producer.isOnOff","")>
</#if>
<#if depSysApi.getUserParam("rocketmq.producer.groupName","")?? && depSysApi.getUserParam("rocketmq.producer.groupName","")!=''>
<#assign producerGroupName=depSysApi.getUserParam("rocketmq.producer.groupName","")>
</#if>
<#if depSysApi.getUserParam("rocketmq.producer.topic","")?? && depSysApi.getUserParam("rocketmq.producer.topic","")!=''>
<#assign producerTopic=depSysApi.getUserParam("rocketmq.producer.topic","")>
</#if>
</#if>
<#if depSysApi.getUserParam("rocketmq.consumer.namesrvAddr","")?? && depSysApi.getUserParam("rocketmq.consumer.namesrvAddr","")!=''>
<#assign hasMQConsumer=true>
<#assign consumerMQServer=depSysApi.getUserParam("rocketmq.consumer.namesrvAddr","")>
<#if depSysApi.getUserParam("rocketmq.consumer.isOnOff","")?? && depSysApi.getUserParam("rocketmq.consumer.isOnOff","")!=''>
<#assign consumerisOnOff=depSysApi.getUserParam("rocketmq.consumer.isOnOff","")>
</#if>
<#if depSysApi.getUserParam("rocketmq.consumer.groupName","")?? && depSysApi.getUserParam("rocketmq.consumer.groupName","")!=''>
<#assign consumerGroupName=depSysApi.getUserParam("rocketmq.consumer.groupName","")>
</#if>
<#if depSysApi.getUserParam("rocketmq.consumer.topic","")?? && depSysApi.getUserParam("rocketmq.consumer.topic","")!=''>
<#assign consumerTopic=depSysApi.getUserParam("rocketmq.consumer.topic","")>
</#if>
</#if>
</#if>
</#list>
</#if>
<#if hasMQProducer ||hasMQConsumer>
rocketmq:
<#if hasMQProducer>
producer:
namesrvAddr: ${producerMQServer}
isOnOff: 'on'
groupName: ${producerGroupName}
topic: ${producerTopic}
</#if>
<#if hasMQConsumer>
consumer:
namesrvAddr: ${consumerMQServer}
isOnOff: 'on'
groupName: ${consumerGroupName}
topic: ${consumerTopic}
</#if>
</#if>
<#macro singleDatasourceConfig>
datasource:
username: ${dbUserName}
password: '${dbPassWord}'
url: ${dbUrl}
driver-class-name: ${dbDriver}
filters: stat,wall,log4j2
#配置初始化大小/最小/最大
initial-size: 1
min-idle: 1
max-active: 20
#获取连接等待超时时间
max-wait: 60000
#间隔多久进行一次检测,检测需要关闭的空闲连接
time-between-eviction-runs-millis: 60000
#一个连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1 FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
#打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
pool-prepared-statements: false
max-pool-prepared-statement-per-connection-size: 20
isSyncDBSchema: false
defaultSchema: <#if dbUserName=='root'>${sys.name}<#else>${dbUserName}</#if>
conf: classpath:liquibase/master.xml
</#macro>
<#macro dynamicDatasourceConfig>
datasource:
username: ${dbUserName}
password: '${dbPassWord}'
url: ${dbUrl}
driver-class-name: ${dbDriver}
isSyncDBSchema: false
defaultSchema: <#if dbUserName=='root'>${sys.name}<#else>${dbUserName}</#if>
dynamic:
druid: #以下是全局默认值,可以全局更改
filters: stat,wall,log4j2
#配置初始化大小/最小/最大
initial-size: 1
min-idle: 1
max-active: 20
#获取连接等待超时时间
max-wait: 60000
#间隔多久进行一次检测,检测需要关闭的空闲连接
time-between-eviction-runs-millis: 60000
#一个连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1 FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
#打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
pool-prepared-statements: false
max-pool-prepared-statement-per-connection-size: 20
datasource:
master:
username: ${r'${spring.datasource.username}'}
password: ${r'${spring.datasource.password}'}
url: ${r'${spring.datasource.url}'}
driver-class-name: ${r'${spring.datasource.driver-class-name}'}
conf: classpath:liquibase/master.xml
isSyncDBSchema: ${r'${spring.datasource.isSyncDBSchema}'}
defaultSchema: ${r'${spring.datasource.defaultSchema}'}
<#list sys.getAllPSDataEntities() as entity>
<#if (entity.getStorageMode()==1 || entity.getStorageMode()==2) && entity.getDSLink()!='DEFAULT'>
<#assign dbLink=entity.getDSLink()?lower_case>
<#if !P.exists('dynamicDatasource',dbLink)>
${dbLink}:
username: ${r'${spring.datasource.username}'}
password: ${r'${spring.datasource.password}'}
url: ${r'${spring.datasource.url}'}
driver-class-name: ${r'${spring.datasource.driver-class-name}'}
conf: classpath:liquibase/master.xml
isSyncDBSchema: ${r'${spring.datasource.isSyncDBSchema}'}
defaultSchema: ${r'${spring.datasource.defaultSchema}'}
</#if>
</#if>
</#list>
</#macro>
...@@ -83,6 +83,8 @@ ...@@ -83,6 +83,8 @@
<!-- 阿里seata分布式事务 --> <!-- 阿里seata分布式事务 -->
<alibaba-seata.version>1.3.0</alibaba-seata.version> <alibaba-seata.version>1.3.0</alibaba-seata.version>
<log4j2.version>2.16.0</log4j2.version>
{{#system.enableOracle}} {{#system.enableOracle}}
<oracle.version>19.8.0.0</oracle.version> <oracle.version>19.8.0.0</oracle.version>
{{/system.enableOracle}} {{/system.enableOracle}}
......
FROM image.ibizlab.cn/library/openjdk:8-jre-alpine
ENV TZ="Asia/Shanghai" \
SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
IBIZ_SLEEP=0 \
JAVA_OPTS=""
CMD echo "The application will start in ${IBIZ_SLEEP}s..." && \
sleep ${IBIZ_SLEEP} && \
java ${JAVA_OPTS} -Duser.timezone=$TZ -Djava.security.egd=file:/dev/./urandom -jar /{{projectName}}-provider-{{apis}}.jar
EXPOSE {{#if app.httpPort}}{{app.httpPort}}{{else}}8080{{/if}}
ADD {{projectName}}-provider-{{apis}}.jar /{{projectName}}-provider-{{apis}}.jar
package {{packageName}}.swagger;
import cn.ibizlab.util.security.SpringContextHolder;
import cn.ibizlab.util.web.IBZOperationParameterReader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.plugin.core.PluginRegistry;
import org.springframework.plugin.core.PluginRegistrySupport;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.schema.EnumTypeDeterminer;
import springfox.documentation.spi.service.OperationBuilderPlugin;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.spring.web.readers.operation.OperationParameterReader;
import springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
@Configuration
@EnableSwagger2
@ConditionalOnExpression("${swagger.enable:false}")
public class SwaggerConfiguration {
@Bean
public Docket docket() {
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.groupName("DEFAULT")
.pathMapping("/")
.apiInfo(
new ApiInfoBuilder()
.title("DEFAULT")
.build()
)
.select()
.apis(RequestHandlerSelectors.basePackage("{{packageName}}"))
//.paths(or(regex("/rest/.*")))
.paths(PathSelectors.any())
.build();
removeDefaultPlugin();
return docket ;
}
@Bean
public Docket {{apis}}Docket() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("{{api.name}}")
.pathMapping("/")
.apiInfo(
new ApiInfoBuilder()
.title("{{api.name}}")
.version("{{api.aPIVersion}}")
.build()
)
.select()
.apis(RequestHandlerSelectors.basePackage("{{packageName}}.{{api.codeName}}"))
.paths(PathSelectors.any())
.build();
}
private void removeDefaultPlugin() {
// 从spring容器中获取swagger插件注册表
PluginRegistry<OperationBuilderPlugin, DocumentationType> pluginRegistry = SpringContextHolder.getBean("operationBuilderPluginRegistry");
// 插件集合
List<OperationBuilderPlugin> plugins = pluginRegistry.getPlugins();
// 从spring容器中获取需要删除的插件
OperationParameterReader operationParameterReader = SpringContextHolder.getBean(OperationParameterReader.class);
if(operationParameterReader==null)
return ;
// 原plugins集合不能修改,创建新集合,通过反射替换
if (pluginRegistry.contains(operationParameterReader)) {
List<OperationBuilderPlugin> plugins_new = new ArrayList<OperationBuilderPlugin>(plugins);
plugins_new.remove(operationParameterReader);
try {
Field field = PluginRegistrySupport.class.getDeclaredField("plugins");
field.setAccessible(true);
field.set(pluginRegistry, plugins_new);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Bean
public IBZOperationParameterReader iBZOperationParameterReader(ModelAttributeParameterExpander expander,EnumTypeDeterminer enumTypeDeterminer){
IBZOperationParameterReader iBZOperationParameterReader = new IBZOperationParameterReader(expander, enumTypeDeterminer) ;
return iBZOperationParameterReader ;
}
}
package {{packageName}}.{{apis}}.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import org.springframework.context.annotation.Import;
{{#if system.enableGlobalTransaction}}
@Import({com.alibaba.cloud.seata.feign.SeataFeignClientAutoConfiguration.class})
{{/if}}
@Configuration
@ConditionalOnClass({{api.codeName}}RestConfiguration.class)
@ConditionalOnWebApplication
@EnableConfigurationProperties({{api.codeName}}ServiceProperties.class)
public class {{api.codeName}}AutoConfiguration implements ApplicationContextAware {
protected ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Bean("asyncExecutor")
public Executor asyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(20);
executor.setQueueCapacity(2000);
executor.setKeepAliveSeconds(600);
executor.setThreadNamePrefix("asyncExecutor-");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
return executor;
}
// @Bean
// public ServletRegistrationBean {{api.codeName}}Servlet() {
// AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
// dispatcherServletConfiguration.setParent(applicationContext);
// dispatcherServletConfiguration.register({{api.codeName}}RestConfiguration.class);
// DispatcherServlet servlet = new DispatcherServlet(dispatcherServletConfiguration);
// String path = "/{{lowerCase api.codeName}}";
// String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*");
// ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet, urlMapping);
// registrationBean.setName("{{api.codeName}}");
// return registrationBean;
// }
}
package {{packageName}}.{{apis}}.config;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan("{{packageName}}.{{apis}}")
public class {{api.codeName}}RestConfiguration {
}
package {{packageName}}.{{apis}}.config;
import cn.ibizlab.util.security.AuthenticationEntryPoint;
import cn.ibizlab.util.security.AuthorizationTokenFilter;
import cn.ibizlab.util.service.AuthenticationUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.core.GrantedAuthorityDefaults;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.context.annotation.Profile;
import org.springframework.beans.factory.annotation.Qualifier;
@Profile("{{apis}}-prod")
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class {{api.codeName}}SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthenticationEntryPoint unauthorizedHandler;
@Autowired
private AuthenticationUserService userDetailsService;
/**
* 自定义基于JWT的安全过滤器
*/
@Autowired
AuthorizationTokenFilter authenticationTokenFilter;
@Value("${ibiz.auth.path:v7/login}")
private String loginPath;
@Value("${ibiz.auth.logoutpath:v7/logout}")
private String logoutPath;
@Value("${ibiz.file.uploadpath:ibizutil/upload}")
private String uploadpath;
@Value("${ibiz.file.downloadpath:ibizutil/download}")
private String downloadpath;
@Value("${ibiz.file.previewpath:ibizutil/preview}")
private String previewpath;
@Value("${ibiz.auth.excludesPattern:}")
private String[] excludesPattern;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoderBean());
}
@Bean
GrantedAuthorityDefaults grantedAuthorityDefaults() {
// Remove the ROLE_ prefix
return new GrantedAuthorityDefaults("");
}
@Bean
public PasswordEncoder passwordEncoderBean() {
return new BCryptPasswordEncoder();
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
// 禁用 CSRF
.csrf().disable()
// 授权异常
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
// 不创建会话
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
// 过滤请求
.authorizeRequests()
.antMatchers(
HttpMethod.GET,
"/*.html",
"/**/*.html",
"/**/*.css",
"/**/*.js",
"/**/*.ico",
"/**/assets/**",
"/**/css/**",
"/**/fonts/**",
"/**/js/**",
"/**/img/**",
"/",
"webjars/**",
"/swagger-resources/**",
"/v2/**"
).permitAll()
//放行登录请求
.antMatchers( HttpMethod.POST, "/"+loginPath).permitAll()
//放行注销请求
.antMatchers( HttpMethod.GET, "/"+logoutPath).permitAll()
// 文件操作
.antMatchers("/"+downloadpath+"/**").permitAll()
.antMatchers("/"+uploadpath).permitAll()
.antMatchers("/"+previewpath+"/**").permitAll();
for (String excludePattern : excludesPattern) {
authenticationTokenFilter.addExcludePattern(excludePattern);
httpSecurity.authorizeRequests().antMatchers(excludePattern).permitAll();
}
// 所有请求都需要认证
httpSecurity.authorizeRequests().anyRequest().authenticated()
// 防止iframe 造成跨域
.and().headers().frameOptions().disable();
httpSecurity
.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
}
}
package {{packageName}}.{{apis}}.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import lombok.Data;
@ConfigurationProperties(prefix = "service.{{apis}}")
@Data
public class {{apis.codeName}}ServiceProperties {
private boolean enabled;
private boolean auth;
}
\ No newline at end of file
<#ibiztemplate>
TARGET=PSDESERVICEAPI
</#ibiztemplate>
<#comment>引入驼峰配置</#comment>
<#ibizinclude>/SLN/globalfunc.cfg</#ibizinclude>
<#comment>不发布子系统实体</#comment>
<#if de.isSubSysDE()==false>
<#assign pubPkgCodeName = pub.getPKGCodeName()>
<#assign itemSysApiCodeNameLC = item.getPSSysServiceAPI().getCodeName()?lower_case>
<#assign dtoBase="DTOBase">
<#comment>中台模式通过DTOClient设置dirtyflag</#comment>
<#if ((de.getPSSubSysServiceAPI().getServiceType())!'')=='MIDDLEPLATFORM'>
<#assign dtoBase="DTOClient">
</#if>
<#assign hasValueRuleGroup=false>
<#if sys.codeName == 'Sample'>
<#if de.getAllPSDEFValueRules()??>
<#list de.getAllPSDEFValueRules() as deRule>
<#if deRule.codeName!='Default'>
<#if deRule.getPSDEFVRGroupCondition()??>
<#assign hasValueRuleGroup=true>
<#break>
</#if>
</#if>
</#list>
</#if>
</#if>
package {{packageName}}.{{apis}}.dto;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.math.BigInteger;
import java.util.Map;
import java.util.HashMap;
import java.io.Serializable;
import java.math.BigDecimal;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.alibaba.fastjson.annotation.JSONField;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import cn.ibizlab.util.domain.DTOBase;
import cn.ibizlab.util.domain.DTOClient;
import lombok.Data;
<#if hasValueRuleGroup>
import cn.ibizlab.util.annotation.ValueRuleCheck;
</#if>
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* 服务DTO对象[${item.getCodeName()}DTO]
*/
@Data
<@valueRuleGroup/>
@ApiModel("${item.getLogicName()}")
public class ${item.getCodeName()}DTO extends ${dtoBase} implements Serializable {
private static final long serialVersionUID = 1L;
<#if item.getPSDEServiceAPIFields()??>
<#comment>接口属性集合</#comment>
<#list item.getPSDEServiceAPIFields() as apifield>
<#assign defDataType = (apifield.getPSDEField().getDataType())!"">
<#assign columnname = apifield.getName()?lower_case>
<#assign prvateCodeName = srfr7templcaseformat(apifield.getCodeName()) >
<#assign publicCodeName = prvateCodeName?cap_first >
<#assign jsonfield = apifield.getCodeName()?lower_case >
<#assign defield=(apifield.getPSDEField())!"">
<#if defDataType!='ONE2MANYDATA'>
/**
* 属性 [${apifield.getName()}]
*
*/
<#if defDataType == "DATETIME" || ((defDataType=='PICKUPDATA'||defDataType=='INHERIT') && srfdatatype(apifield.getStdDataType())== "DATETIME" && apifield.getPSDEField().getValueFormat()=="%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS")>
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", locale = "zh" , timezone="GMT+8")
@JSONField(name = "${jsonfield}" , format="yyyy-MM-dd HH:mm:ss")
<#elseif defDataType == "DATE" || ((defDataType=='PICKUPDATA'||defDataType=='INHERIT') && srfdatatype(apifield.getStdDataType())== "DATETIME" && apifield.getPSDEField().getValueFormat()=="%1$tY-%1$tm-%1$td")>
@JsonFormat(pattern="yyyy-MM-dd", locale = "zh" , timezone="GMT+8")
@JSONField(name = "${jsonfield}" , format="yyyy-MM-dd")
<#elseif defDataType == "TIME" || ((defDataType=='PICKUPDATA'||defDataType=='INHERIT') && srfdatatype(apifield.getStdDataType())== "DATETIME" && apifield.getPSDEField().getValueFormat()=="%1$tH:%1$tM:%1$tS")>
@JsonFormat(pattern="HH:mm:ss", locale = "zh" , timezone="GMT+8")
@JSONField(name = "${jsonfield}" , format="HH:mm:ss")
<#else>
@JSONField(name = "${jsonfield}")
</#if>
@JsonProperty("${jsonfield}")
<#comment>Long型数据转String,解决前端精度丢失问题</#comment>
<#if srfr7javatype(apifield.getStdDataType())=='Long'>
@JsonSerialize(using = ToStringSerializer.class)
</#if>
<@valueRule defield />
@ApiModelProperty("${apifield.getLogicName()}")
private ${srfr7javatype(apifield.getStdDataType())} ${prvateCodeName};
</#if>
</#list>
</#if>
<#comment>输出set方法用于设置null值</#comment>
<#list item.getPSDEServiceAPIFields() as apifield>
<#assign defield = apifield.getPSDEField() >
<#assign defDataType = (defield.getDataType())!"">
<#assign columnname = apifield.getName()?lower_case>
<#assign prvateCodeName = srfr7templcaseformat(apifield.getCodeName()) >
<#assign publicCodeName = prvateCodeName?cap_first >
<#if defield.isPhisicalDEField()==true && defield.isKeyDEField()==false && defDataType!='ONE2MANYDATA'>
<#if defield.getPredefinedType()?? && defield.getPredefinedType()!=''>
<#else >
/**
* 设置 [${apifield.getName()}]
*/
public void set${publicCodeName}(${srfr7javatype(apifield.getStdDataType())} ${prvateCodeName}){
this.${prvateCodeName} = ${prvateCodeName} ;
this.modify("${columnname}",${prvateCodeName});
}
</#if>
</#if>
</#list>
<#comment>输出关系数据(子实体)</#comment>
<#if item.getPSDEServiceAPIRSs()?? >
<#list item.getPSDEServiceAPIRSs() as apider>
<#if apider.getPSDER1N()??>
<#assign der = apider.getPSDER1N() >
<#if apider.getMinorPSDEServiceAPI().isNested()>
<#assign subDTOs = srfpluralize(apider.getMinorPSDEServiceAPI().getCodeName())?lower_case >
<#assign subcode = srfr7templcaseformat((der.getMinorCodeName()!der.getMinorPSDataEntity().getCodeName())) >
<#if subcode?? && subcode==''><#assign subcode=srfr7templcaseformat(der.getMinorPSDataEntity().getCodeName())></#if>
/**
* [${apider.getMinorPSDEServiceAPI().getName()}]
*/
@JsonProperty("${subDTOs}")
@JSONField(name = "${subDTOs}")
private List<${apider.getMinorPSDEServiceAPI().getCodeName()}DTO> ${subcode} ;
</#if>
</#if>
</#list>
</#if>
}
</#if>
<#comment>属性值规则</#comment>
<#macro valueRule defield>
<#if defield !=''>
<#if defield.isKeyDEField()==true || defield.getPredefinedType()?? && defield.getPredefinedType()!=''>
<#else>
<#if defield.isAllowEmpty()==false>
<#assign notNullMsg="["+defield.getLogicName()+"]不允许为空!">
<#if srfr7javatype(defield.stdDataType)=='String'>
@NotBlank(message = "${notNullMsg}")
<#else>
@NotNull(message = "${notNullMsg}")
</#if>
</#if>
</#if>
<#if defield.getAllPSDEFValueRules()??>
<#list defield.getAllPSDEFValueRules() as defieldVR>
<#if defieldVR.getPSDEFVRGroupCondition?? && defieldVR.getPSDEFVRGroupCondition()?? && defieldVR.getCodeName()=='Default'>
<#assign vrCond=defieldVR.getPSDEFVRGroupCondition()>
<#assign vrCondType=vrCond.getCondType()>
<#assign vrCondOp=vrCond.getCondOp()>
<#if vrCond.getPSDEFVRConditions?? && vrCond.getPSDEFVRConditions()??>
<#list vrCond.getPSDEFVRConditions() as subVRCond>
<#if subVRCond.getCondType()=='STRINGLENGTH'>
<#if subVRCond.getMaxValue()?c!='-1'>
@Size(min = 0, max = ${subVRCond.getMaxValue()?c}, message = "${subVRCond.getRuleInfo()}")
</#if>
</#if>
</#list>
</#if>
</#if>
</#list>
</#if>
</#if>
</#macro>
<#comment>属性值规则(规则组)</#comment>
<#macro valueRuleGroup>
<#if hasValueRuleGroup>
<#assign ruleMsg="">
@ValueRuleCheck.List({
<#list de.getAllPSDEFValueRules() as deRule>
<#if deRule.codeName!='Default'>
<#if deRule.getPSDEFVRGroupCondition()??>
<#assign ruleName=(de.codeName+"_"+deRule.getPSDEField().codeName+"_"+deRule.codeName)?lower_case>
<#assign ruleField=(deRule.getPSDEField().codeName)?lower_case>
<#assign group=deRule.getPSDEFVRGroupCondition()>
@ValueRuleCheck(field = "${ruleField}", rule = "${ruleName}"),
</#if>
</#if>
</#list>
})
</#if>
</#macro>
\ No newline at end of file
{{#unless apiEntity.subSysDE}}
<#assign pubPkgCodeName = pub.getPKGCodeName()>
<#assign itemSysApiCodeNameLC = item.getPSSysServiceAPI().getCodeName()?lower_case>
<#assign itemSysApiCodeName = item.getPSSysServiceAPI().getCodeName()>
<#assign mappingName=itemSysApiCodeName+item.codeName+"Mapping">
package {{packageName}}.{{apis}}.mapping;
{{#with api.entity as | entity | }}
import org.mapstruct.*;
import {{packageName}}.core.{{entity.model}}.domain.{{entity.codeName}};
import {{packageName}}.{{apis}}.dto.{{apiEntity.codeName}}DTO;
import cn.ibizlab.util.domain.MappingBase;
@Mapper(componentModel = "spring", uses = {}, implementationName = "{{api.codeName}}{{apiEntity.codeName}}Mapping",
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface {{apiEntity.codeName}}Mapping extends MappingBase<{{apiEntity.codeName}}DTO, {{entity.codeName}}> {
}
{{/with}}
{{/unless}}
\ No newline at end of file
<#ibiztemplate>
TARGET=PSDESERVICEAPI
</#ibiztemplate>
<#comment>引入驼峰配置</#comment>
<#ibizinclude>/SLN/globalfunc.cfg</#ibizinclude>
<#comment>不发布子系统实体</#comment>
<#if de.isSubSysDE()==false>
<#-- SYSAPIRESTFUL,主从接口(非嵌套) -->
<#if api.getAPIType() == "RESTFUL" && !item.isNested()>
<#assign pubPkgCodeName = pub.getPKGCodeName()>
<#assign itemCodeName = item.getCodeName()>
<#assign itemCodeNameLC = itemCodeName?lower_case>
<#assign deCodeName = de.getCodeName()>
<#assign deLogicName = de.getLogicName()>
<#assign deCodeNameCamel = srfr7templcaseformat(deCodeName)?cap_first>
<#assign deCodeNameLC = deCodeName?lower_case>
<#assign dePKCodeNameLC = srfr7templcaseformat(de.getKeyPSDEField().getCodeName())>
<#assign dePKCodeName = (dePKCodeNameLC)?cap_first>
<#assign deModelCodeNameLC = de.getPSSystemModule().getCodeName()?lower_case>
<#assign itemSysApiCodeName = item.getPSSysServiceAPI().getCodeName()>
<#assign itemSysApiCodeNameLC = item.getPSSysServiceAPI().getCodeName()?lower_case>
<#assign keyCNLC = "_id">
<#assign hasDEPrefield=false>
<#if de.getPSDEFieldByPDT('ORGID',true)?? || de.getPSDEFieldByPDT('ORGSECTORID',true)?? || de.getPSDEFieldByPDT('CREATEMAN',true)?? >
<#assign hasDEPrefield=true>
</#if>
<#assign hasDEImport=false>
<#comment>实体数据导入</#comment>
<#if de.getAllPSDEDataImports?? && de.getAllPSDEDataImports()??>
<#list de.getAllPSDEDataImports() as deImport>
<#assign hasDEImport=true>
<#break>
</#list>
</#if>
package ${pubPkgCodeName}.${itemSysApiCodeNameLC}.rest;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.math.BigInteger;
import java.util.HashMap;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.ServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import ${pubPkgCodeName}.${itemSysApiCodeNameLC}.dto.*;
import ${pubPkgCodeName}.${itemSysApiCodeNameLC}.mapping.*;
import ${pubPkgCodeName}.core.${deModelCodeNameLC}.domain.${deCodeName};
import ${pubPkgCodeName}.core.${deModelCodeNameLC}.service.I${deCodeName}Service;
import ${pubPkgCodeName}.core.${deModelCodeNameLC}.filter.${deCodeName}SearchContext;
import ${pubPkgCodeName}.util.annotation.VersionCheck;
<#if item.getPSDEServiceAPIRSs()??>
<#list item.getPSDEServiceAPIRSs() as apider>
<#assign deapide=apider.getMinorPSDEServiceAPI().getPSDataEntity()>
<#assign deapideCN=deapide.getCodeName()>
<#assign deapideModuleCNLC=deapide.getPSSystemModule().getCodeName()?lower_case>
<#if apider.getMinorPSDEServiceAPI().isNested() && (deapide.getStorageMode()==1||deapide.getStorageMode()==2||deapide.getStorageMode()==4) >
import ${pubPkgCodeName}.core.${deapideModuleCNLC}.filter.${deapideCN}SearchContext;
import ${pubPkgCodeName}.core.${deapideModuleCNLC}.domain.${deapideCN};
import ${pubPkgCodeName}.core.${deapideModuleCNLC}.service.I${deapideCN}Service;
</#if>
</#list>
</#if>
@Slf4j
@Api(tags = {"${deLogicName}" })
<#comment>两个服务接口引用同一个实体时,会产生两个Resource,通过dev模式代理启动两个服务时,会产生bean同名冲突,所以需要进行区分</#comment>
@RestController("${itemSysApiCodeName}-${itemCodeName?lower_case}")
@RequestMapping("")
public class ${itemCodeName}Resource {
@Autowired
public I${deCodeName}Service ${deCodeNameLC}Service;
@Autowired
@Lazy
public ${itemCodeName}Mapping ${itemCodeNameLC}Mapping;
<#-- 嵌套服务对象 -->
<#if item.getPSDEServiceAPIRSs()??>
<#list item.getPSDEServiceAPIRSs() as apider>
<#assign deapide=apider.getMinorPSDEServiceAPI().getPSDataEntity()>
<#assign deapideCN=deapide.getCodeName()>
<#assign deapideModuleCNLC=deapide.getPSSystemModule().getCodeName()?lower_case>
<#if apider.getMinorPSDEServiceAPI().isNested() && (deapide.getStorageMode()==1||deapide.getStorageMode()==2||deapide.getStorageMode()==4)>
<#if deapideCN != deCodeName>
@Autowired
private I${deapideCN}Service ${deapideCN?lower_case}Service;
</#if>
</#if>
</#list>
</#if>
<#-- 主接口 start -->
<#if item.isMajor()>
<#--<#assign parentPath = "/" + item.getPSSysServiceAPI().getCodeName()?lower_case >-->
<#--<#assign selfPath="/" + srfpluralize(itemCodeNameLC) >-->
<#assign parentPath = "" >
<#assign selfPath= "/" +srfpluralize(itemCodeNameLC) >
<#assign parentParams = "">
<#assign parentSearchParams = "" >
<#assign parentParams2 = "">
<#assign parentParams3 = "">
<#assign idParams = "">
<#assign idParams2 = "">
<#assign idParams3 = "">
<#assign etParams = "">
<#assign etParamsList = "">
<#assign etParams2 = "">
<#assign etParams3 = "">
<#assign id_etParams = "">
<#assign id_etParams_get = "">
<#assign id_etParams4 = "">
<#assign id_etParams4_batch = "">
<#assign etParams = etParams + "@RequestBody " + itemCodeName + "DTO " + itemCodeNameLC + "dto">
<#assign etParamsList = etParamsList + "@RequestBody List<" + itemCodeName + "DTO> " + itemCodeNameLC + "dtos">
<#assign etParams2 = etParams2 + itemCodeName + "DTO " + itemCodeNameLC + "dto">
<#assign etParams3 = etParams3 + itemCodeNameLC + "dto">
<#assign idParams = idParams + "@PathVariable(\"" + itemCodeNameLC + keyCNLC + "\") " + srfr7javatype(de.getKeyPSDEField().getStdDataType()) + " " + itemCodeNameLC + keyCNLC >
<#assign idParams2 = idParams2 + " " + srfr7javatype(de.getKeyPSDEField().getStdDataType()) + " " + itemCodeNameLC + keyCNLC >
<#assign idParams3 = idParams3 + " " + itemCodeNameLC + keyCNLC >
<#assign id_etParams_get = id_etParams + "@PathVariable(\"" + itemCodeNameLC + keyCNLC + "\") " + srfr7javatype(de.getKeyPSDEField().getStdDataType())+" " + itemCodeNameLC + keyCNLC + ", " + itemCodeName + "DTO " + itemCodeNameLC + "dto" >
<#assign id_etParams = id_etParams + "@PathVariable(\"" + itemCodeNameLC + keyCNLC + "\") " + srfr7javatype(de.getKeyPSDEField().getStdDataType())+" " + itemCodeNameLC + keyCNLC + ", @RequestBody " + itemCodeName + "DTO " + itemCodeNameLC + "dto" >
<#assign id_etParams4 = id_etParams4 + "@RequestBody " + itemCodeName + "DTO " + itemCodeNameLC + "dto" >
<#assign id_etParams4_batch = id_etParams4_batch + "@RequestBody List<" + itemCodeName + "DTO> " + itemCodeNameLC + "dtos" >
<#assign dtoCodeName=itemCodeName + "DTO">
<#assign fullPath = parentPath + selfPath>
<#if item.getPSDEServiceAPIMethods()??>
<#list item.getPSDEServiceAPIMethods() as apiMethod>
<#assign reqMtd = apiMethod.getRequestMethod()>
<#assign statusCode = "HttpStatus.OK">
<#if apiMethod.getActionType()=='DEACTION'>
<#assign deaction = apiMethod.getPSDEAction()>
<#assign deactionName = deaction.getName()>
<#assign deactionCodeName = deaction.getCodeName()>
<#assign apiReturnValueType=itemCodeName+"DTO">
<#if apiMethod.getReturnValueType()?? && apiMethod.getReturnValueType()?lower_case =='void' >
<#assign apiReturnValueType = "Void">
</#if>
<#comment>输出主接口测试行为</#comment>
<@outputTestActionDetail deaction/>
<#if deaction.codeName?lower_case == 'create'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "新建${deLogicName}", tags = {"${deLogicName}" }, notes = "新建${deLogicName}")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}")
public ResponseEntity<${itemCodeName}DTO> create(@Validated ${etParams}) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
${deCodeNameLC}Service.create(domain);
${itemCodeName}DTO dto = ${itemCodeNameLC}Mapping.toDto(domain);
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "批量新建${deLogicName}", tags = {"${deLogicName}" }, notes = "批量新建${deLogicName}")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}/batch")
public ResponseEntity<Boolean> createBatch(${etParamsList}) {
${deCodeNameLC}Service.createBatch(${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos));
return ResponseEntity.status(HttpStatus.OK).body(true);
}
<#elseif deaction.codeName?lower_case == 'update'>
<@VersionCheckAnnotation/>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "更新${deLogicName}", tags = {"${deLogicName}" }, notes = "更新${deLogicName}")
@RequestMapping(method = RequestMethod.PUT, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}")
public ResponseEntity<${itemCodeName}DTO> update(${id_etParams}) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
domain .set${dePKCodeName}(${itemCodeNameLC + keyCNLC});
${deCodeNameLC}Service.update(domain );
${itemCodeName}DTO dto = ${itemCodeNameLC}Mapping.toDto(domain);
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "批量更新${deLogicName}", tags = {"${deLogicName}" }, notes = "批量更新${deLogicName}")
@RequestMapping(method = RequestMethod.PUT, value = "${fullPath}/batch")
public ResponseEntity<Boolean> updateBatch(${etParamsList}) {
${deCodeNameLC}Service.updateBatch(${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos));
return ResponseEntity.status(HttpStatus.OK).body(true);
}
<#elseif deaction.codeName?lower_case == 'save'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "保存${deLogicName}", tags = {"${deLogicName}" }, notes = "保存${deLogicName}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}")
public ResponseEntity<${itemCodeName}DTO> save(${etParams}) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
${deCodeNameLC}Service.save(domain);
return ResponseEntity.status(HttpStatus.OK).body(${itemCodeNameLC}Mapping.toDto(domain));
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "批量保存${deLogicName}", tags = {"${deLogicName}" }, notes = "批量保存${deLogicName}")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}/savebatch")
public ResponseEntity<Boolean> saveBatch(${etParamsList}) {
${deCodeNameLC}Service.saveBatch(${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos));
return ResponseEntity.status(HttpStatus.OK).body(true);
}
<#elseif deaction.codeName?lower_case == 'remove'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "删除${deLogicName}", tags = {"${deLogicName}" }, notes = "删除${deLogicName}")
@RequestMapping(method = RequestMethod.DELETE, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}")
public ResponseEntity<Boolean> remove(${idParams}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.remove(${itemCodeNameLC + keyCNLC}));
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "批量删除${deLogicName}", tags = {"${deLogicName}" }, notes = "批量删除${deLogicName}")
@RequestMapping(method = RequestMethod.DELETE, value = "${fullPath}/batch")
public ResponseEntity<Boolean> removeBatch(@RequestBody List<${srfr7javatype(de.getKeyPSDEField().getStdDataType())}> ids) {
${deCodeNameLC}Service.removeBatch(ids);
return ResponseEntity.status(HttpStatus.OK).body(true);
}
<#elseif deaction.codeName?lower_case == 'get'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "获取${deLogicName}", tags = {"${deLogicName}" }, notes = "获取${deLogicName}")
@RequestMapping(method = RequestMethod.GET, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}")
public ResponseEntity<${itemCodeName}DTO> get(${idParams}) {
${deCodeName} domain = ${deCodeNameLC}Service.get(${itemCodeNameLC + keyCNLC});
${itemCodeName}DTO dto = ${itemCodeNameLC}Mapping.toDto(domain);
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
<#elseif deaction.codeName?lower_case == 'checkkey'>
@ApiOperation(value = "检查${deLogicName}", tags = {"${deLogicName}" }, notes = "检查${deLogicName}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}")
public ResponseEntity<Boolean> checkKey(${etParams}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.checkKey(${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto)));
}
<#elseif deaction.codeName?lower_case == 'getdraft'><#comment>前端支持临时模式,后台不做处理</#comment>
@ApiOperation(value = "获取${deLogicName}草稿", tags = {"${deLogicName}" }, notes = "获取${deLogicName}草稿")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}")
public ResponseEntity<${itemCodeName}DTO> ${deactionCodeName?uncap_first}(${itemCodeName}DTO dto) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(dto);
return ResponseEntity.status(HttpStatus.OK).body(${itemCodeNameLC}Mapping.toDto(${deCodeNameLC}Service.getDraft(domain)));
}
<#elseif deaction.codeName?lower_case == 'createbatch'>
<#elseif deaction.codeName?lower_case == 'updatebatch'>
<#elseif deaction.codeName?lower_case == 'removebatch'>
<#elseif deaction.codeName?lower_case == 'savebatch'>
<#elseif deaction.getUserTag()?? && deaction.getActionType()?? && deaction.getUserTag() == 'REGIST' && deaction.getActionType() == 'USERCREATE'>
<#else>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${deaction.getLogicName()}", tags = {"${deLogicName}" }, notes = "${deaction.getLogicName()}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}<#if deaction.getRequestParamType() == 'NONE'><#else>/{${itemCodeNameLC + keyCNLC}}</#if>/${deactionCodeName?lower_case}")
public ResponseEntity<${apiReturnValueType}> ${deactionCodeName?uncap_first}(<#if deaction.getRequestParamType() == 'NONE'><#else><#if reqMtd?lower_case =='get'>${id_etParams_get}<#else>${id_etParams}</#if></#if>) {
<#if deaction.getRequestParamType() == 'NONE'>
${deCodeName} domain =new ${deCodeName}();
domain = ${deCodeNameLC}Service.${srfmethodname(deactionCodeName)}(domain);
${dtoCodeName} ${itemCodeNameLC}dto = ${itemCodeNameLC}Mapping.toDto(domain);
<#else>
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
domain.set${dePKCodeName}(${itemCodeNameLC + keyCNLC});
domain = ${deCodeNameLC}Service.${srfmethodname(deactionCodeName)}(domain);
${itemCodeNameLC}dto = ${itemCodeNameLC}Mapping.toDto(domain);
</#if>
<#if apiReturnValueType?lower_case =='void'>
return ResponseEntity.status(HttpStatus.OK).build();
<#else>
return ResponseEntity.status(HttpStatus.OK).body(${itemCodeNameLC}dto);
</#if>
}
<#comment>自定义行为批处理</#comment>
<#if (deaction.getActionType()=='USERCUSTOM' || deaction.getActionType()=='DELOGIC')>
<@customBatchAction deaction/>
</#if>
</#if>
<#elseif apiMethod.getActionType()=='FETCH'>
<#assign deds = apiMethod.getPSDEDataSet()>
<@DataQuerySecurityAnnotation deds/>
@ApiOperation(value = "获取${deds.getLogicName()}", tags = {"${deLogicName}" } ,notes = "获取${deds.getLogicName()}")
@RequestMapping(method= RequestMethod.${reqMtd} , value="${fullPath}/fetch<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()?lower_case}<#else>${deds.getCodeName()?lower_case}</#if>")
public ResponseEntity<List<<#if deds.isEnableGroup()>Map<#else>${itemCodeName}DTO</#if>>> fetch<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()}<#else>${deds.getCodeName()}</#if>(<#if reqMtd!='GET'>@RequestBody </#if>${deCodeName}SearchContext context) {
<#--${parentSearchParams}-->
<#if deds.isEnableGroup()>
Page<Map> domains = ${deCodeNameLC}Service.search${deds.getCodeName()}(context) ;
return ResponseEntity.status(${statusCode})
.header("x-page", String.valueOf(context.getPageable().getPageNumber()))
.header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
.header("x-total", String.valueOf(domains.getTotalElements()))
.body(domains.getContent());
<#else>
Page<${deCodeName}> domains = ${deCodeNameLC}Service.search${deds.getCodeName()}(context) ;
List<${itemCodeName}DTO> list = ${itemCodeNameLC}Mapping.toDto(domains.getContent());
return ResponseEntity.status(${statusCode})
.header("x-page", String.valueOf(context.getPageable().getPageNumber()))
.header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
.header("x-total", String.valueOf(domains.getTotalElements()))
.body(list);
</#if>
}
<@DataQuerySecurityAnnotation deds/>
@ApiOperation(value = "查询${deds.getLogicName()}", tags = {"${deLogicName}" } ,notes = "查询${deds.getLogicName()}")
@RequestMapping(method= RequestMethod.POST , value="${fullPath}/search<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()?lower_case}<#else>${deds.getCodeName()?lower_case}</#if>")
public ResponseEntity<Page<<#if deds.isEnableGroup()>Map<#else>${itemCodeName}DTO</#if>>> search<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()}<#else>${deds.getCodeName()}</#if>(@RequestBody ${deCodeName}SearchContext context) {
<#--${parentSearchParams}-->
<#if deds.isEnableGroup()>
Page<Map> domains = ${deCodeNameLC}Service.search${deds.getCodeName()}(context) ;
return ResponseEntity.status(${statusCode})
.body(new PageImpl(domains.getContent(), context.getPageable(), domains.getTotalElements()));
<#else>
Page<${deCodeName}> domains = ${deCodeNameLC}Service.search${deds.getCodeName()}(context) ;
return ResponseEntity.status(${statusCode})
.body(new PageImpl(${itemCodeNameLC}Mapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
</#if>
}
<#if de.getUserTag()?? && de.getUserTag()=='elasticsearch'>
<@DataQuerySecurityAnnotation deds/>
@ApiOperation(value = "获取${deds.getLogicName()}", tags = {"${deLogicName}" } ,notes = "获取${deds.getLogicName()}")
@RequestMapping(method= RequestMethod.${reqMtd} , value="${fullPath}/fetch<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()?lower_case}<#else>${deds.getCodeName()?lower_case}</#if>/es")
public ResponseEntity<List<${itemCodeName}DTO>> esFetch<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()}<#else>${deds.getCodeName()}</#if>(${deCodeName}SearchContext context) {
Page<{{packageName}}.core.es.domain.${item.codeName}> domains = esService.search${deds.getCodeName()}(context) ;
List<${itemCodeName}DTO> list = ${itemCodeNameLC}Mapping.toDto(esMapping.toDomain(domains.getContent()));
return ResponseEntity.status(${statusCode})
.header("x-page", String.valueOf(context.getPageable().getPageNumber()))
.header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
.header("x-total", String.valueOf(domains.getTotalElements()))
.body(list);
}
</#if>
</#if>
</#list>
</#if>
<#comment>es get行为</#comment>
<#if de.getUserTag()?? && de.getUserTag()=='elasticsearch'>
@Autowired
@Lazy
{{packageName}}.core.es.service.I${de.codeName}ESService esService;
@Autowired
@Lazy
{{packageName}}.core.${de.getPSSystemModule().codeName?lower_case}.mapping.${de.codeName}ESMapping esMapping;
@PostAuthorize("hasPermission(this.${itemCodeNameLC}Mapping.toDomain(returnObject.body),'${sys.codeName}-${de.codeName}-Get')")
@ApiOperation(value = "获取${deLogicName}", tags = {"${deLogicName}" }, notes = "获取${deLogicName}")
@RequestMapping(method = RequestMethod.GET, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}/es")
public ResponseEntity<${itemCodeName}DTO> esGet(${idParams}) {
{{packageName}}.core.es.domain.${item.codeName} domain = esService.get(${itemCodeNameLC + keyCNLC});
${itemCodeName}DTO dto = ${itemCodeNameLC}Mapping.toDto(esMapping.toDomain(domain));
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
</#if>
<#comment>动态行为服务接口</#comment>
<#if pub.isEnableDynaModel()?? && pub.isEnableDynaModel()== true>
<#assign dynamic_id_Params ="@PathVariable(\"" + itemCodeNameLC + keyCNLC + "\") " + srfr7javatype(de.getKeyPSDEField().getStdDataType())+" " + itemCodeNameLC + keyCNLC +" , @PathVariable(\"action\") String action , @RequestBody " + itemCodeName + "DTO " + itemCodeNameLC + "dto" >
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN')")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}/{action}")
public ResponseEntity<${itemCodeName}DTO> dynamicCall(${dynamic_id_Params}) {
${deCodeName} domain = ${deCodeNameLC}Service.dynamicCall(${itemCodeNameLC + keyCNLC}, action, ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC + "dto"}));
${itemCodeNameLC}dto = ${itemCodeNameLC}Mapping.toDto(domain);
return ResponseEntity.status(HttpStatus.OK).body(${itemCodeNameLC + "dto"});
}
</#if>
</#if>
<#-- 主接口 end -->
<#-- 关系接口 start -->
<#if item.getPSDEServiceAPIRSPathCount() gt 0>
<#list 0..1000 as x>
<#if x gte item.getPSDEServiceAPIRSPathCount()>
<#break>
<#else>
<#assign parentPath = "">
<#assign selfPath="/" + srfpluralize(itemCodeNameLC) >
<#assign parentParams = "">
<#assign byParams = "By">
<#assign byTagParams = "根据">
<#assign parentSearchParams = "" >
<#assign parentSetParams = "" >
<#assign parentParams2 = "">
<#assign parentParams3 = "">
<#assign idParams = "">
<#assign idParams2 = "">
<#assign idParams3 = "">
<#assign etParams = "">
<#assign etParamsList = "">
<#assign etParams2 = "">
<#assign etParams3 = "">
<#assign id_etParams = "">
<#assign id_etParams_get= "">
<#assign id_etParams4 = "">
<#assign id_etParams4_batch = "">
<#assign apiRsPathLast = item.getPSDEServiceAPIRSPathLast(x)>
<#list item.getPSDEServiceAPIRSPath(x) as rs>
<#assign rsMainDEServiceAPI = rs.getMajorPSDEServiceAPI()>
<#assign rsMainDe = rsMainDEServiceAPI.getPSDataEntity()>
<#assign rsMainDeCN = rsMainDe.codeName >
<#assign rsMainDeLogicName = rsMainDe.getLogicName() >
<#assign rsMainDeCNLC = rsMainDeCN?lower_case >
<#assign rsMainDePKCN = rsMainDe.getKeyPSDEField().codeName >
<#assign rsMainDePKCNLC = rsMainDePKCN?lower_case >
<#assign rsMainDePKDataType = rsMainDe.getKeyPSDEField().getStdDataType() >
<#assign parentPath += "/" + srfpluralize(rsMainDEServiceAPI.codeName)?lower_case + "/{" + rsMainDeCNLC + keyCNLC + "}" >
<#if rs_index != 0 && parentParams!= "">
<#assign parentParams += ", ">
</#if>
<#assign parentParams += "@PathVariable(\"" + rsMainDeCNLC + keyCNLC + "\") " + srfr7javatype(rsMainDePKDataType) + " " + rsMainDeCNLC + keyCNLC >
<#assign byParams += rsMainDeCN >
<#assign byTagParams += rsMainDeLogicName >
<#if rs.getPSDER1N()?? && apiRsPathLast.getCodeName() == rs.getCodeName()>
<#assign parentSearchParams += "context.setN_" + rs.getPSDER1N().getPSPickupDEField().getName()?lower_case + "_eq("+ rsMainDeCNLC + keyCNLC +");" >
<#assign parentSetParams += "domain.set" + srfr7templcaseformat(rs.getPSDER1N().getPSPickupDEField().getCodeName())?cap_first + "("+ rsMainDeCNLC + keyCNLC +");" >
</#if>
<#assign parentParams2 += "" + srfr7javatype(rsMainDePKDataType)+" " + rsMainDeCNLC + keyCNLC >
<#assign parentParams3 += "" + rsMainDeCNLC + keyCNLC >
</#list>
<#if parentParams != "" >
<#assign idParams = parentParams + ", ">
<#assign idParams2 = parentParams2 + ", ">
<#assign idParams3 = parentParams3 + ", ">
<#assign etParams = parentParams + ", ">
<#assign etParamsList = parentParams + ", ">
<#assign etParams2 = parentParams2 + ", ">
<#assign etParams3 = parentParams3 + ", ">
<#assign id_etParams = parentParams + ", ">
<#assign id_etParams4 = parentParams + ", ">
<#assign id_etParams4_batch = parentParams + ", ">
</#if>
<#assign etParams = etParams + "@RequestBody " + itemCodeName + "DTO " + itemCodeNameLC + "dto">
<#assign etParamsList = etParamsList + "@RequestBody List<" + itemCodeName + "DTO> " + itemCodeNameLC + "dtos">
<#assign etParams2 = etParams2 + itemCodeName + "DTO " + itemCodeNameLC + "dto">
<#assign etParams3 = etParams3 + itemCodeNameLC + "dto">
<#assign idParams = idParams + "@PathVariable(\"" + itemCodeNameLC + keyCNLC + "\") " + srfr7javatype(de.getKeyPSDEField().getStdDataType()) + " " + itemCodeNameLC + keyCNLC >
<#assign idParams2 = idParams2 + " " + srfr7javatype(de.getKeyPSDEField().getStdDataType()) + " " + itemCodeNameLC + keyCNLC >
<#assign idParams3 = idParams3 + " " + itemCodeNameLC + keyCNLC >
<#assign id_etParams_get = id_etParams + "@PathVariable(\"" + itemCodeNameLC + keyCNLC + "\") " + srfr7javatype(de.getKeyPSDEField().getStdDataType())+" " + itemCodeNameLC + keyCNLC + ", " + itemCodeName + "DTO " + itemCodeNameLC + "dto" >
<#assign id_etParams = id_etParams + "@PathVariable(\"" + itemCodeNameLC + keyCNLC + "\") " + srfr7javatype(de.getKeyPSDEField().getStdDataType())+" " + itemCodeNameLC + keyCNLC + ", @RequestBody " + itemCodeName + "DTO " + itemCodeNameLC + "dto" >
<#assign id_etParams4 = id_etParams4 + "@RequestBody " + itemCodeName + "DTO " + itemCodeNameLC + "dto" >
<#assign id_etParams4_batch = id_etParams4_batch + "@RequestBody List<" + itemCodeName + "DTO> " + itemCodeNameLC + "dtos" >
<#assign fullPath = parentPath + selfPath>
<#if item.getPSDEServiceAPIMethods()??>
<#list item.getPSDEServiceAPIMethods() as apiMethod>
<#assign reqMtd = apiMethod.getRequestMethod()>
<#assign statusCode = "HttpStatus.OK" >
<#if apiMethod.getActionType()=='DEACTION'>
<#assign deaction = apiMethod.getPSDEAction()>
<#assign deactionName = deaction.getName()>
<#assign deactionCodeName = deaction.getCodeName()>
<#assign apiReturnValueType=itemCodeName+"DTO">
<#if apiMethod.getReturnValueType()?? && apiMethod.getReturnValueType()?lower_case =='void' >
<#assign apiReturnValueType = "Void">
</#if>
<#comment>输出从接口测试行为</#comment>
<@outputTestActionDetail2 deaction/>
<#if deaction.codeName?lower_case == 'create'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${byTagParams}建立${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}建立${deLogicName}")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}")
public ResponseEntity<${itemCodeName}DTO> ${deactionCodeName?uncap_first}${byParams}(${etParams}) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
${parentSetParams}
${deCodeNameLC}Service.create(domain);
${itemCodeName}DTO dto = ${itemCodeNameLC}Mapping.toDto(domain);
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "${byTagParams}批量建立${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}批量建立${deLogicName}")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}/batch")
public ResponseEntity<Boolean> createBatch${byParams}(${etParamsList}) {
List<${deCodeName}> domainlist=${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos);
for(${deCodeName} domain:domainlist){
${parentSetParams}
}
${deCodeNameLC}Service.createBatch(domainlist);
return ResponseEntity.status(HttpStatus.OK).body(true);
}
<#elseif deaction.codeName?lower_case == 'update'>
<@VersionCheckAnnotation/>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${byTagParams}更新${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}更新${deLogicName}")
@RequestMapping(method = RequestMethod.PUT, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}")
public ResponseEntity<${itemCodeName}DTO> ${deactionCodeName?uncap_first}${byParams}(${id_etParams}) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
${parentSetParams}
domain.set${dePKCodeName}(${itemCodeNameLC + keyCNLC});
${deCodeNameLC}Service.update(domain);
${itemCodeName}DTO dto = ${itemCodeNameLC}Mapping.toDto(domain);
<#--
<#if item.getPSDEServiceAPIRSs()??>
<#list item.getPSDEServiceAPIRSs() as apider>
<#assign deMinApi = apider.getMinorPSDEServiceAPI()>
<#assign deMinApiCN = deMinApi.getCodeName()>
<#assign deMinApiCNLC = deMinApi.getCodeName()?lower_case>
<#assign deapide=deMinApi.getPSDataEntity()>
<#if deMinApi.isNested()>
<#assign subDTOs = srfpluralize(deMinApiCN)?lower_case >
List<${deMinApiCN}DTO> ${deMinApiCNLC}dtos = ${itemCodeNameLC}dto.get${subDTOs?cap_first}();
Page<${deapide.getCodeName()}> ${deMinApiCNLC}DOs = ${deapide.getCodeName()?lower_case}Service.selectBy${apider.getPSDER1N().getCodeName()}(${itemCodeNameLC + keyCNLC});
List<${srfr7javatype(deapide.getKeyPSDEField().getStdDataType())}> ${deMinApiCNLC}Ids = new ArrayList<${srfr7javatype(deapide.getKeyPSDEField().getStdDataType())}>();
if (${deMinApiCNLC}DOs != null && !${deMinApiCNLC}DOs.isEmpty()) {
for (${deapide.getCodeName()} minorDO : ${deMinApiCNLC}DOs) {
${deMinApiCNLC}Ids.add(minorDO.get${deapide.getKeyPSDEField().getCodeName()?cap_first}());
}
}
List<${deMinApiCN}DTO> ${deMinApiCNLC}dtos2 = new ArrayList<${deapide.getCodeName()}DTO>();
if (${deapide.getCodeName()?lower_case}dtos != null && ${deapide.getCodeName()?lower_case}dtos.size() > 0) {
for (${deMinApiCN}DTO ${deapide.getCodeName()?lower_case}dto : ${deapide.getCodeName()?lower_case}dtos) {
${deapide.getCodeName()} ${deapide.getCodeName()?lower_case}Do = ${deapide.getCodeName()?lower_case}dto.toDO();
${deapide.getCodeName()?lower_case}Do.set${dePKCodeName?cap_first}(dto.get${dePKCodeName?cap_first}());
if ( StringUtils.isEmpty( ${deapide.getCodeName()?lower_case}Do.get${deapide.getKeyPSDEField().getCodeName()?cap_first}()) || (${deMinApiCNLC}Ids != null && !${deMinApiCNLC}Ids.isEmpty() && ${deMinApiCNLC}Ids.contains(${deapide.getCodeName()?lower_case}Do.get${deapide.getKeyPSDEField().getCodeName()?cap_first}()))) {
${deapide.getCodeName()?lower_case}Service.save(${deapide.getCodeName()?lower_case}Do);
${deapide.getCodeName()?lower_case}dto.fromDO(${deapide.getCodeName()?lower_case}Do);
${deapide.getCodeName()?lower_case}dtos2.add(${deapide.getCodeName()?lower_case}dto);
} else {
${deapide.getCodeName()?lower_case}Service.remove(${deapide.getCodeName()?lower_case}Do.get${deapide.getKeyPSDEField().getCodeName()?cap_first}());
}
}
} else {
${deapide.getCodeName()?lower_case}dtos2 = ${deapide.getCodeName()?lower_case}dtos;
}
dto.set${subDTOs?cap_first}(${deapide.getCodeName()?lower_case}dtos2);
</#if>
</#list>
</#if>
-->
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "${byTagParams}批量更新${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}批量更新${deLogicName}")
@RequestMapping(method = RequestMethod.PUT, value = "${fullPath}/batch")
public ResponseEntity<Boolean> updateBatch${byParams}(${etParamsList}) {
List<${deCodeName}> domainlist=${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos);
for(${deCodeName} domain:domainlist){
${parentSetParams}
}
${deCodeNameLC}Service.updateBatch(domainlist);
return ResponseEntity.status(HttpStatus.OK).body(true);
}
<#elseif deaction.codeName?lower_case == 'remove'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${byTagParams}删除${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}删除${deLogicName}")
@RequestMapping(method = RequestMethod.DELETE, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}")
public ResponseEntity<Boolean> ${deactionCodeName?uncap_first}${byParams}(${idParams}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.remove(${itemCodeNameLC + keyCNLC}));
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "${byTagParams}批量删除${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}批量删除${deLogicName}")
@RequestMapping(method = RequestMethod.DELETE, value = "${fullPath}/batch")
public ResponseEntity<Boolean> removeBatch${byParams}(@RequestBody List<${srfr7javatype(de.getKeyPSDEField().getStdDataType())}> ids) {
${deCodeNameLC}Service.removeBatch(ids);
return ResponseEntity.status(HttpStatus.OK).body(true);
}
<#elseif deaction.codeName?lower_case == 'save'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${byTagParams}保存${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}保存${deLogicName}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}")
public ResponseEntity<${itemCodeName}DTO> ${deactionCodeName?uncap_first}${byParams}(${etParams}) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
${parentSetParams}
${deCodeNameLC}Service.save(domain);
return ResponseEntity.status(HttpStatus.OK).body(${itemCodeNameLC}Mapping.toDto(domain));
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "${byTagParams}批量保存${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}批量保存${deLogicName}")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}/savebatch")
public ResponseEntity<Boolean> saveBatch${byParams}(${etParamsList}) {
List<${deCodeName}> domainlist=${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos);
for(${deCodeName} domain:domainlist){
${parentSetParams}
}
${deCodeNameLC}Service.saveBatch(domainlist);
return ResponseEntity.status(HttpStatus.OK).body(true);
}
<#elseif deaction.codeName?lower_case == 'get'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${byTagParams}获取${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}获取${deLogicName}")
@RequestMapping(method = RequestMethod.GET, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}")
public ResponseEntity<${itemCodeName}DTO> ${deactionCodeName?uncap_first}${byParams}(${idParams}) {
${deCodeName} domain = ${deCodeNameLC}Service.get(${itemCodeNameLC + keyCNLC});
${itemCodeName}DTO dto = ${itemCodeNameLC}Mapping.toDto(domain);
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
<#elseif deaction.codeName?lower_case == 'checkkey'>
@ApiOperation(value = "${byTagParams}检查${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}检查${deLogicName}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}")
public ResponseEntity<Boolean> ${deactionCodeName?uncap_first}${byParams}(${etParams}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.checkKey(${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto)));
}
<#elseif deaction.codeName?lower_case == 'getdraft'>
@ApiOperation(value = "${byTagParams}获取${deLogicName}草稿", tags = {"${deLogicName}" }, notes = "${byTagParams}获取${deLogicName}草稿")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}")
public ResponseEntity<${itemCodeName}DTO> ${deactionCodeName?uncap_first}${byParams}(${parentParams}, ${itemCodeName}DTO dto) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(dto);
${parentSetParams}
return ResponseEntity.status(HttpStatus.OK).body(${itemCodeNameLC}Mapping.toDto(${deCodeNameLC}Service.getDraft(domain)));
}
<#elseif deaction.codeName?lower_case == 'createbatch'>
<#elseif deaction.codeName?lower_case == 'updatebatch'>
<#elseif deaction.codeName?lower_case == 'removebatch'>
<#elseif deaction.codeName?lower_case == 'savebatch'>
<#elseif deaction.getUserTag()?? && deaction.getActionType()?? && deaction.getUserTag() == 'REGIST' && deaction.getActionType() == 'USERCREATE'>
<#else>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${byTagParams}${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}${deLogicName}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}<#if deaction.getRequestParamType() == 'NONE'><#else>/{${itemCodeNameLC + keyCNLC}}</#if>/${deactionCodeName?lower_case}")
public ResponseEntity<${apiReturnValueType}> ${deactionCodeName?uncap_first}${byParams}(<#if deaction.getRequestParamType() == 'NONE'><#else><#if reqMtd?lower_case =='get'>${id_etParams_get}<#else>${id_etParams}</#if></#if>) {
<#if deaction.getRequestParamType() == 'NONE'>
${deCodeName} domain =new ${deCodeName}();
domain = ${deCodeNameLC}Service.${srfmethodname(deactionCodeName)}(domain) ;
${dtoCodeName} ${itemCodeNameLC}dto = ${itemCodeNameLC}Mapping.toDto(domain);
<#else>
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
${parentSetParams}
domain = ${deCodeNameLC}Service.${srfmethodname(deactionCodeName)}(domain) ;
${itemCodeNameLC}dto = ${itemCodeNameLC}Mapping.toDto(domain);
</#if>
<#if apiReturnValueType?lower_case =='void'>
return ResponseEntity.status(HttpStatus.OK).build();
<#else>
return ResponseEntity.status(HttpStatus.OK).body(${itemCodeNameLC}dto);
</#if>
}
<#comment>自定义行为批处理</#comment>
<#if (deaction.getActionType()=='USERCUSTOM' || deaction.getActionType()=='DELOGIC')>
<@customBatchActionRS deaction/>
</#if>
</#if>
<#elseif apiMethod.getActionType()=='FETCH'>
<#assign deds = apiMethod.getPSDEDataSet()>
<@DataQuerySecurityAnnotation deds/>
@ApiOperation(value = "${byTagParams}获取${deds.getLogicName()}", tags = {"${deLogicName}" } ,notes = "${byTagParams}获取${deds.getLogicName()}")
@RequestMapping(method= RequestMethod.${reqMtd} , value="${fullPath}/fetch<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()?lower_case}<#else>${deds.getCodeName()?lower_case}</#if>")
public ResponseEntity<List<<#if deds.isEnableGroup()>Map<#else>${itemCodeName}DTO</#if>>> fetch${itemCodeName}<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()}<#else>${deds.getCodeName()}</#if>${byParams}(<#if parentParams!="">${parentParams},</#if><#if reqMtd!='GET'>@RequestBody </#if>${deCodeName}SearchContext context) {
${parentSearchParams}
<#if deds.isEnableGroup()>
Page<Map> domains = ${deCodeNameLC}Service.search${deds.getCodeName()}(context) ;
return ResponseEntity.status(${statusCode})
.header("x-page", String.valueOf(context.getPageable().getPageNumber()))
.header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
.header("x-total", String.valueOf(domains.getTotalElements()))
.body(domains.getContent());
<#else>
Page<${deCodeName}> domains = ${deCodeNameLC}Service.search${deds.getCodeName()}(context) ;
List<${itemCodeName}DTO> list = ${itemCodeNameLC}Mapping.toDto(domains.getContent());
return ResponseEntity.status(${statusCode})
.header("x-page", String.valueOf(context.getPageable().getPageNumber()))
.header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
.header("x-total", String.valueOf(domains.getTotalElements()))
.body(list);
</#if>
}
<@DataQuerySecurityAnnotation deds/>
@ApiOperation(value = "${byTagParams}查询${deds.getLogicName()}", tags = {"${deLogicName}" } ,notes = "${byTagParams}查询${deds.getLogicName()}")
@RequestMapping(method= RequestMethod.POST , value="${fullPath}/search<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()?lower_case}<#else>${deds.getCodeName()?lower_case}</#if>")
public ResponseEntity<Page<<#if deds.isEnableGroup()>Map<#else>${itemCodeName}DTO</#if>>> search${itemCodeName}<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()}<#else>${deds.getCodeName()}</#if>${byParams}(<#if parentParams!="">${parentParams}, @RequestBody </#if>${deCodeName}SearchContext context) {
${parentSearchParams}
<#if deds.isEnableGroup()>
Page<Map> domains = ${deCodeNameLC}Service.search${deds.getCodeName()}(context) ;
return ResponseEntity.status(${statusCode})
.body(new PageImpl(domains.getContent(), context.getPageable(), domains.getTotalElements()));
<#else>
Page<${deCodeName}> domains = ${deCodeNameLC}Service.search${deds.getCodeName()}(context) ;
return ResponseEntity.status(${statusCode})
.body(new PageImpl(${itemCodeNameLC}Mapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
</#if>
}
</#if>
</#list>
</#if>
</#if>
</#list>
</#if>
<#comment>实体数据导入</#comment>
<#if hasDEImport>
<#list de.getAllPSDEDataImports() as deImport>
@Autowired
{{packageName}}.core.${de.getPSSystemModule().codeName?lower_case}.mapping.${deCodeName}${deImport.codeName} ${deImport.codeName?lower_case}ImpMapping;
</#list>
@RequestMapping(method = RequestMethod.POST, value = "/${srfpluralize(itemCodeNameLC)}/import")
public ResponseEntity<JSONObject> importData(@RequestParam(value = "config") String config , @RequestBody List<${deCodeName}> dtos){
JSONObject rs=new JSONObject();
if(dtos.size()==0){
rs.put("rst", 1);
rs.put("msg", "未传入内容");
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(rs);
}
else{
<#list de.getAllPSDEDataImports() as deImport>
<#if deImport_index==0>
if("${deImport.codeName}".equals(config)){
rs=${deCodeNameLC}Service.importData(${deImport.codeName?lower_case}ImpMapping.toDomain(dtos),${deImport.getBatchSize()?c},${deImport.isIgnoreError()?c});
}
<#else>
else if("${deImport.codeName}".equals(config)){
rs=${deCodeNameLC}Service.importData(${deImport.codeName?lower_case}ImpMapping.toDomain(dtos),${deImport.getBatchSize()?c},${deImport.isIgnoreError()?c});
}
</#if>
</#list>
return ResponseEntity.status(HttpStatus.OK).body(rs);
}
}
</#if>
}
</#if>
</#if>
<#comment>数据查询Security权限校验(分组不鉴权、配置[NONE]操作标识不鉴权)</#comment>
<#macro DataQuerySecurityAnnotation dataset>
<#if ((dataset.getPSDEOPPriv().getName())!'')!='NONE' >
<#if (de.getStorageMode()==1 || de.getStorageMode()==2 ||de.getStorageMode()==4) && dataset.isEnableGroup()==false>
<#if hasDEPrefield==false>
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','${sys.codeName}-${de.codeName}-search${dataset.codeName}-all')")
<#else>
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','${sys.codeName}-${de.codeName}-search${dataset.codeName}-all') and hasPermission(#context,'${sys.codeName}-${de.codeName}-Get')")
</#if>
</#if>
</#if>
</#macro>
<#comment>单条数据Security权限校验(配置[NONE]操作标识不鉴权)</#comment>
<#macro SecurityAnnotation deaction>
<#if ((deaction.getPSDEOPPriv().getName())!'')!='NONE' >
<#if de.getStorageMode()==1 || de.getStorageMode()==2 ||de.getStorageMode()==4>
<#if hasDEPrefield==false>
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','${sys.codeName}-${de.codeName}-${deaction.codeName}-all')")
<#else>
<#if deaction.codeName?lower_case=='create' || deaction.codeName?lower_case=='save'>
@PreAuthorize("hasPermission(this.${itemCodeNameLC}Mapping.toDomain(#${itemCodeNameLC}dto),'${sys.codeName}-${de.codeName}-${deaction.codeName}')")
<#elseif deaction.codeName?lower_case=='update' || deaction.codeName?lower_case=='remove'>
@PreAuthorize("hasPermission(this.${deCodeNameLC}Service.get(#${itemCodeNameLC + keyCNLC}),'${sys.codeName}-${de.codeName}-${deaction.codeName}')")
<#elseif deaction.codeName?lower_case=='get'>
@PostAuthorize("hasPermission(this.${itemCodeNameLC}Mapping.toDomain(returnObject.body),'${sys.codeName}-${de.codeName}-${deaction.codeName}')")
<#else>
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','${sys.codeName}-${de.codeName}-${deaction.codeName}-all')")
</#if>
</#if>
</#if>
</#if>
</#macro>
<#comment>批量数据Security权限校验(配置[NONE]操作标识不鉴权)</#comment>
<#macro SecurityBatchAnnotation deaction>
<#if ((deaction.getPSDEOPPriv().getName())!'')!='NONE' >
<#if de.getStorageMode()==1 || de.getStorageMode()==2 ||de.getStorageMode()==4>
<#if hasDEPrefield==false>
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','${sys.codeName}-${de.codeName}-${deaction.codeName}-all')")
<#else>
<#if deaction.codeName?lower_case=='remove'>
@PreAuthorize("hasPermission(this.${deCodeNameLC}Service.get${deCodeNameCamel}ByIds(#ids),'${sys.codeName}-${de.codeName}-${deaction.codeName}')")
<#elseif deaction.codeName?lower_case=='update'>
@PreAuthorize("hasPermission(this.${deCodeNameLC}Service.get${deCodeNameCamel}ByEntities(this.${itemCodeNameLC}Mapping.toDomain(#${itemCodeNameLC}dtos)),'${sys.codeName}-${de.codeName}-${deaction.codeName}')")
<#else>
@PreAuthorize("hasPermission(this.${itemCodeNameLC}Mapping.toDomain(#${itemCodeNameLC}dtos),'${sys.codeName}-${de.codeName}-${deaction.codeName}')")
</#if>
</#if>
</#if>
</#if>
</#macro>
<#comment>数据库版本检查注解</#comment>
<#macro VersionCheckAnnotation>
<#if item.getPSDEServiceAPIFields()??>
<#list item.getPSDEServiceAPIFields() as apifield>
<#if apifield.getPSDEField?? && apifield.getPSDEField()??>
<#assign defield=apifield.getPSDEField()>
<#if defield.getPredefinedType?? && defield.getPredefinedType()??>
<#if defield.getPredefinedType()=='UPDATEDATE'>
<#assign updatedateField=srfr7templcaseformat(defield.codeName)>
@VersionCheck(entity = "${deCodeNameLC}" , versionfield = "${updatedateField}")
<#break>
</#if>
</#if>
</#if>
</#list>
</#if>
</#macro>
<#comment>输出主接口测试行为</#comment>
<#macro outputTestActionDetail deaction>
<#if deaction.getTestActionMode?? && deaction.getTestActionMode()?? && (deaction.getTestActionMode() ==3) >
<#assign deactionName = deaction.getName()>
<#assign deactionCodeName = deaction.getCodeName()>
<#if deaction.codeName?lower_case == 'create'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "新建${deLogicName}", tags = {"${deLogicName}" }, notes = "新建${deLogicName}")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}/test")
public ResponseEntity<Boolean> testCreate(${etParams}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testCreate(${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto)));
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "批量新建${deLogicName}", tags = {"${deLogicName}" }, notes = "批量新建${deLogicName}")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}/batch/test")
public ResponseEntity<Boolean> testCreateBatch(${etParamsList}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testCreateBatch(${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos)));
}
<#elseif deaction.codeName?lower_case == 'update'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "更新${deLogicName}", tags = {"${deLogicName}" }, notes = "更新${deLogicName}")
@RequestMapping(method = RequestMethod.PUT, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}/test")
public ResponseEntity<Boolean> testUpdate(${id_etParams}) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
domain .set${dePKCodeName}(${itemCodeNameLC + keyCNLC});
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testUpdate(domain));
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "批量更新${deLogicName}", tags = {"${deLogicName}" }, notes = "批量更新${deLogicName}")
@RequestMapping(method = RequestMethod.PUT, value = "${fullPath}/batch/test")
public ResponseEntity<Boolean> testUpdateBatch(${etParamsList}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testUpdateBatch(${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos)));
}
<#elseif deaction.codeName?lower_case == 'save'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "保存${deLogicName}", tags = {"${deLogicName}" }, notes = "保存${deLogicName}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}/test")
public ResponseEntity<Boolean> testSave(${etParams}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testSave(${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto)));
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "批量保存${deLogicName}", tags = {"${deLogicName}" }, notes = "批量保存${deLogicName}")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}/savebatch/test")
public ResponseEntity<Boolean> testSaveBatch(${etParamsList}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testSaveBatch(${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos)));
}
<#elseif deaction.codeName?lower_case == 'remove'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "删除${deLogicName}", tags = {"${deLogicName}" }, notes = "删除${deLogicName}")
@RequestMapping(method = RequestMethod.DELETE, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}/test")
public ResponseEntity<Boolean> testRemove(${idParams}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testRemove(${itemCodeNameLC + keyCNLC}));
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "批量删除${deLogicName}", tags = {"${deLogicName}" }, notes = "批量删除${deLogicName}")
@RequestMapping(method = RequestMethod.DELETE, value = "${fullPath}/batch/test")
public ResponseEntity<Boolean> testRemoveBatch(@RequestBody List<${srfr7javatype(de.getKeyPSDEField().getStdDataType())}> ids) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testRemoveBatch(ids));
}
<#elseif deaction.codeName?lower_case == 'get'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "获取${deLogicName}", tags = {"${deLogicName}" }, notes = "获取${deLogicName}")
@RequestMapping(method = RequestMethod.GET, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}/test")
public ResponseEntity<Boolean> testGet(${idParams}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testGet(${itemCodeNameLC + keyCNLC}));
}
<#elseif deaction.codeName?lower_case == 'checkkey'>
@ApiOperation(value = "检查${deLogicName}", tags = {"${deLogicName}" }, notes = "检查${deLogicName}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}/test")
public ResponseEntity<Boolean> testCheckKey(${etParams}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testCheckKey(${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto)));
}
<#elseif deaction.codeName?lower_case == 'getdraft'><#comment>前端支持临时模式,后台不做处理</#comment>
@ApiOperation(value = "获取${deLogicName}草稿", tags = {"${deLogicName}" }, notes = "获取${deLogicName}草稿")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}/test")
public ResponseEntity<Boolean> testGetDraft(${itemCodeName}DTO dto) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(dto);
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testGetDraft(domain));
}
<#elseif deaction.codeName?lower_case == 'createbatch'>
<#elseif deaction.codeName?lower_case == 'updatebatch'>
<#elseif deaction.codeName?lower_case == 'removebatch'>
<#elseif deaction.codeName?lower_case == 'savebatch'>
<#elseif deaction.getUserTag()?? && deaction.getActionType()?? && deaction.getUserTag() == 'REGIST' && deaction.getActionType() == 'USERCREATE'>
<#else>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${deaction.getLogicName()}", tags = {"${deLogicName}" }, notes = "${deaction.getLogicName()}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}<#if deaction.getRequestParamType() == 'NONE'><#else>/{${itemCodeNameLC + keyCNLC}}</#if>/${deactionCodeName?lower_case}/test")
public ResponseEntity<Boolean> test${deactionCodeName?cap_first}(<#if deaction.getRequestParamType() == 'NONE'><#else>${id_etParams}</#if>) {
<#if deaction.getRequestParamType() == 'NONE'>
${deCodeName} domain = new ${deCodeName}();
<#else>
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
</#if>
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.test${srfmethodname(deactionCodeName)?cap_first}(domain));
}
</#if>
</#if>
</#macro>
<#comment>输出关系接口测试行为</#comment>
<#macro outputTestActionDetail2 deaction>
<#if deaction.getTestActionMode?? && deaction.getTestActionMode()?? && (deaction.getTestActionMode() ==3) >
<#assign deactionName = deaction.getName()>
<#assign deactionCodeName = deaction.getCodeName()>
<#if deaction.codeName?lower_case == 'create'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${byTagParams}建立${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}建立${deLogicName}")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}/test")
public ResponseEntity<Boolean> testCreate${byParams}(${etParams}) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
${parentSetParams}
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testCreate(domain));
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "${byTagParams}批量建立${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}批量建立${deLogicName}")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}/batch/test")
public ResponseEntity<Boolean> testCreateBatch${byParams}(${etParamsList}) {
List<${deCodeName}> domainlist=${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos);
for(${deCodeName} domain:domainlist){
${parentSetParams}
}
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testCreateBatch(domainlist));
}
<#elseif deaction.codeName?lower_case == 'update'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${byTagParams}更新${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}更新${deLogicName}")
@RequestMapping(method = RequestMethod.PUT, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}/test")
public ResponseEntity<Boolean> testUpdate${byParams}(${id_etParams}) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
${parentSetParams}
domain.set${dePKCodeName}(${itemCodeNameLC + keyCNLC});
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testUpdate(domain));
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "${byTagParams}批量更新${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}批量更新${deLogicName}")
@RequestMapping(method = RequestMethod.PUT, value = "${fullPath}/batch/test")
public ResponseEntity<Boolean> testUpdateBatch${byParams}(${etParamsList}) {
List<${deCodeName}> domainlist=${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos);
for(${deCodeName} domain:domainlist){
${parentSetParams}
}
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testUpdateBatch(domainlist));
}
<#elseif deaction.codeName?lower_case == 'remove'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${byTagParams}删除${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}删除${deLogicName}")
@RequestMapping(method = RequestMethod.DELETE, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}/test")
public ResponseEntity<Boolean> testRemove${byParams}(${idParams}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testRemove(${itemCodeNameLC + keyCNLC}));
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "${byTagParams}批量删除${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}批量删除${deLogicName}")
@RequestMapping(method = RequestMethod.DELETE, value = "${fullPath}/batch/test")
public ResponseEntity<Boolean> testRemoveBatch${byParams}(@RequestBody List<${srfr7javatype(de.getKeyPSDEField().getStdDataType())}> ids) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testRemoveBatch(ids));
}
<#elseif deaction.codeName?lower_case == 'save'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${byTagParams}保存${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}保存${deLogicName}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}/test")
public ResponseEntity<Boolean> testSave${byParams}(${etParams}) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
${parentSetParams}
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testSave(domain));
}
<@SecurityBatchAnnotation deaction/>
@ApiOperation(value = "${byTagParams}批量保存${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}批量保存${deLogicName}")
@RequestMapping(method = RequestMethod.POST, value = "${fullPath}/savebatch/test")
public ResponseEntity<Boolean> testSaveBatch${byParams}(${etParamsList}) {
List<${deCodeName}> domainlist=${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos);
for(${deCodeName} domain:domainlist){
${parentSetParams}
}
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testSaveBatch(domainlist));
}
<#elseif deaction.codeName?lower_case == 'get'>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${byTagParams}获取${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}获取${deLogicName}")
@RequestMapping(method = RequestMethod.GET, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}/test")
public ResponseEntity<Boolean> testGet${byParams}(${idParams}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testGet(${itemCodeNameLC + keyCNLC}));
}
<#elseif deaction.codeName?lower_case == 'checkkey'>
@ApiOperation(value = "${byTagParams}检查${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}检查${deLogicName}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}/test")
public ResponseEntity<Boolean> testCheckKey${byParams}(${etParams}) {
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.testCheckKey(${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto)));
}
<#elseif deaction.codeName?lower_case == 'getdraft'>
@ApiOperation(value = "${byTagParams}获取${deLogicName}草稿", tags = {"${deLogicName}" }, notes = "${byTagParams}获取${deLogicName}草稿")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}/test")
public ResponseEntity<Boolean> testGetDraft${byParams}(${parentParams}, ${itemCodeName}DTO dto) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(dto);
${parentSetParams}
return ResponseEntity.status(HttpStatus.OK).body(${itemCodeNameLC}Mapping.toDto(${deCodeNameLC}Service.testGetDraft(domain)));
}
<#elseif deaction.codeName?lower_case == 'createbatch'>
<#elseif deaction.codeName?lower_case == 'updatebatch'>
<#elseif deaction.codeName?lower_case == 'removebatch'>
<#elseif deaction.codeName?lower_case == 'savebatch'>
<#elseif deaction.getUserTag()?? && deaction.getActionType()?? && deaction.getUserTag() == 'REGIST' && deaction.getActionType() == 'USERCREATE'>
<#else>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "${byTagParams}${deLogicName}", tags = {"${deLogicName}" }, notes = "${byTagParams}${deLogicName}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}/${deactionCodeName?lower_case}/test")
public ResponseEntity<Boolean> test${deactionCodeName?cap_first}${byParams}(${id_etParams}) {
${deCodeName} domain = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dto);
${parentSetParams}
return ResponseEntity.status(HttpStatus.OK).body(${deCodeNameLC}Service.test${srfmethodname(deactionCodeName)?cap_first}(domain));
}
</#if>
</#if>
</#macro>
<#comment>用户自定义行为批处理-主实体关系</#comment>
<#macro customBatchAction deaction>
<#assign resultValueType="Boolean">
<#if apiReturnValueType?? && apiReturnValueType?lower_case=='void'>
<#assign resultValueType='Void'>
</#if>
<@SecurityAnnotation deaction/>
@ApiOperation(value = "批量处理[${deaction.getLogicName()}]", tags = {"${deLogicName}" }, notes = "批量处理[${deaction.getLogicName()}]")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}batch")
public ResponseEntity<${resultValueType}> ${deactionCodeName?uncap_first}Batch(<#if deaction.getRequestParamType() == 'NONE'><#else>${etParamsList}</#if>) {
<#if deaction.getRequestParamType() == 'NONE'>
List<${deCodeName}> domains = new ArrayList<${deCodeName}>();
boolean result = ${deCodeNameLC}Service.${srfmethodname(deactionCodeName)}Batch(domains);
<#else>
List<${deCodeName}> domains = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos);
boolean result = ${deCodeNameLC}Service.${srfmethodname(deactionCodeName)}Batch(domains);
</#if>
<#if resultValueType?lower_case =='void'>
return ResponseEntity.status(HttpStatus.OK).build();
<#else>
return ResponseEntity.status(HttpStatus.OK).body(result);
</#if>
}
</#macro>
<#comment>用户自定义行为批处理-从实体关系</#comment>
<#macro customBatchActionRS deaction>
<#assign resultValueType="Boolean">
<#if apiReturnValueType?? && apiReturnValueType?lower_case=='void'>
<#assign resultValueType='Void'>
</#if>
@ApiOperation(value = "批量处理[${byTagParams}${deLogicName}]", tags = {"${deLogicName}" }, notes = "批量处理[${byTagParams}${deLogicName}]")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}batch")
public ResponseEntity<${resultValueType}> ${deactionCodeName?uncap_first}${byParams}(<#if deaction.getRequestParamType() == 'NONE'><#else>${etParamsList}</#if>) {
<#if deaction.getRequestParamType() == 'NONE'>
List<${deCodeName}> domains = new ArrayList<${deCodeName}>();
boolean result = ${deCodeNameLC}Service.${srfmethodname(deactionCodeName)}Batch(domains);
<#else>
List<${deCodeName}> domains = ${itemCodeNameLC}Mapping.toDomain(${itemCodeNameLC}dtos);
boolean result = ${deCodeNameLC}Service.${srfmethodname(deactionCodeName)}Batch(domains);
</#if>
<#if resultValueType?lower_case =='void'>
return ResponseEntity.status(HttpStatus.OK).build();
<#else>
return ResponseEntity.status(HttpStatus.OK).body(result);
</#if>
}
</#macro>
\ No newline at end of file
package {{packageName}}.{{apis}};
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import cn.ibizlab.util.web.SearchContextHandlerMethodArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
@Slf4j
@EnableDiscoveryClient
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = {"{{packageName}}"}
// ,excludeFilters={
// @ComponentScan.Filter(type= org.springframework.context.annotation.FilterType.REGEX,pattern="{{packageName}}.${item.codeName?lower_case}.rest.xxx"),
// }
)
@EnableMongoRepositories(basePackages = {"{{packageName}}"})
@MapperScan("{{packageName}}.*.mapper")
@SpringBootApplication(exclude = {
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class,
{{#unless system.enableMongo}}
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.class,
{{/unless}}
{{#if system.enableDS}}
com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.class
{{/if}}
})
@Import({
org.springframework.cloud.openfeign.FeignClientsConfiguration.class
})
@EnableFeignClients(basePackages = {"{{packageName}}" })
@EnableAsync
@EnableScheduling
public class {{system.codeName}}{{api.codeName}}Application extends WebMvcConfigurerAdapter{
@Autowired
SearchContextHandlerMethodArgumentResolver resolver;
public static void main(String[] args) {
SpringApplication.run({{system.codeName}}{{api.codeName}}Application.class, args);
}
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
super.addArgumentResolvers(argumentResolvers);
argumentResolvers.add(resolver);
}
}
package {{packageName}}.{{apis}};
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
/**
* 提供外部容器启动服务能力
*/
@Slf4j
public class {{system.codeName}}{{api.codeName}}Initializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
log.info("--正在使用外部容器启动服务--");
return builder.sources({{system.codeName}}{{api.codeName}}Application.class);
}
}
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册