微服务版后端初始化
This commit is contained in:
16
xjrsoft-service/xjrsoft-service-generate/Dockerfile
Normal file
16
xjrsoft-service/xjrsoft-service-generate/Dockerfile
Normal file
@ -0,0 +1,16 @@
|
||||
# 基础镜像
|
||||
FROM nexus.gdyditc.com:8082/openjdk:11-arm64
|
||||
# author
|
||||
MAINTAINER xjrsoft
|
||||
|
||||
# 挂载目录
|
||||
VOLUME /home/xjrsoft
|
||||
# 创建目录
|
||||
RUN mkdir -p /home/xjrsoft
|
||||
# 指定路径
|
||||
WORKDIR /home/xjrsoft
|
||||
# 复制jar文件到路径
|
||||
RUN ls
|
||||
COPY ./target/xjrsoft-service-generate.jar /home/xjrsoft/xjrsoft-service-generate.jar
|
||||
# 启动认证服务
|
||||
ENTRYPOINT ["java","-Dfile.encoding=utf-8","--add-opens","java.base/java.lang.reflect=ALL-UNNAMED","-jar","xjrsoft-service-generate.jar"]
|
||||
103
xjrsoft-service/xjrsoft-service-generate/pom.xml
Normal file
103
xjrsoft-service/xjrsoft-service-generate/pom.xml
Normal file
@ -0,0 +1,103 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>xjrsoft-service</artifactId>
|
||||
<groupId>com.xjrsoft</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>xjrsoft-service-generate</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--引入模板依赖-->
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xjrsoft</groupId>
|
||||
<artifactId>xjrsoft-common-core</artifactId>
|
||||
<version>${xjrsoft.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xjrsoft</groupId>
|
||||
<artifactId>xjrsoft-common-mybatis</artifactId>
|
||||
<version>${xjrsoft.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xjrsoft</groupId>
|
||||
<artifactId>xjrsoft-service-generate-api</artifactId>
|
||||
<version>${xjrsoft.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xjrsoft</groupId>
|
||||
<artifactId>xjrsoft-service-system-api</artifactId>
|
||||
<version>${xjrsoft.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xjrsoft</groupId>
|
||||
<artifactId>xjrsoft-service-app-api</artifactId>
|
||||
<version>${xjrsoft.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xjrsoft</groupId>
|
||||
<artifactId>xjrsoft-service-form-api</artifactId>
|
||||
<version>${xjrsoft.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xjrsoft</groupId>
|
||||
<artifactId>xjrsoft-common-redis</artifactId>
|
||||
<version>${xjrsoft.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 第三方拼音依赖包,配合 hutool-all 包中的 PinyinUtil 拼音工具使用 start -->
|
||||
<dependency>
|
||||
<groupId>com.belerweb</groupId>
|
||||
<artifactId>pinyin4j</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,25 @@
|
||||
package com.xjrsoft.generate;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
|
||||
/**
|
||||
* @Author: tzx
|
||||
* @Date: 2023/10/10 17:16
|
||||
*/
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients(basePackages = "com.xjrsoft")
|
||||
@MapperScan(value = "com.xjrsoft.**.mapper")
|
||||
@ComponentScan(value = "com.xjrsoft")
|
||||
public class GenerateApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GenerateApplication.class, args);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package com.xjrsoft.generate.client;
|
||||
|
||||
import com.xjrsoft.common.generate.model.FrontCode;
|
||||
import com.xjrsoft.generate.dto.DataFirstPreviewDto;
|
||||
import com.xjrsoft.generate.dto.GeneratorAppDto;
|
||||
import com.xjrsoft.generate.service.IGeneratorService;
|
||||
import com.xjrsoft.generate.utils.GeneratorUtil;
|
||||
import com.xjrsoft.generate.vo.GeneratorCodeVo;
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @Author: tzx
|
||||
* @Date: 2023/10/10 19:10
|
||||
*/
|
||||
@Hidden
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
public class GeneratorClient implements IGenerateClient {
|
||||
|
||||
private final IGeneratorService generatorService;
|
||||
|
||||
@Override
|
||||
public void generateAppCodesFeign(@RequestBody GeneratorAppDto dto) {
|
||||
FrontCode frontCode = new FrontCode();
|
||||
frontCode.setApiCode(dto.getApiCode());
|
||||
frontCode.setListCode(dto.getListCode());
|
||||
frontCode.setFormCode(dto.getFormCode());
|
||||
frontCode.setConfigJsonCode(dto.getConfigJsonCode());
|
||||
frontCode.setContainerCode(dto.getContainerCode());
|
||||
GeneratorUtil.createAppCodeFile(frontCode, dto.getClassName(), dto.getOutputValue());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorCodeVo getPreviewCodesFeign(DataFirstPreviewDto dto) {
|
||||
|
||||
|
||||
return generatorService.getPreviewCodes(dto);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.xjrsoft.generate.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @Author: tzx
|
||||
* @Date: 2022/5/20 15:56
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties("xjrsoft.generate")
|
||||
@Data
|
||||
public class GenerateConfig {
|
||||
|
||||
private String servicePath;
|
||||
|
||||
private String apiPath;
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
package com.xjrsoft.generate.controller;
|
||||
|
||||
import com.xjrsoft.common.core.annotation.XjrLog;
|
||||
import com.xjrsoft.common.core.constant.GlobalConstant;
|
||||
import com.xjrsoft.common.core.domain.result.R;
|
||||
import com.xjrsoft.generate.dto.*;
|
||||
import com.xjrsoft.generate.service.IGeneratorService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* @title: GeneratorController
|
||||
* @Author tzx
|
||||
* @Date: 2022/4/12 21:00
|
||||
* @Version 1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(GlobalConstant.SYSTEM_MODULE_PREFIX + "/generator")
|
||||
@Tag(name = GlobalConstant.SYSTEM_MODULE_PREFIX + "/generator", description = "代码生成器")
|
||||
@AllArgsConstructor
|
||||
public class GeneratorController {
|
||||
|
||||
private final IGeneratorService generatorService;
|
||||
|
||||
@PostMapping("/preview-code/data-first")
|
||||
@Operation(summary = "数据优先-预览代码")
|
||||
@XjrLog(value = "数据优先预览代码")
|
||||
public R previewCode(@Valid @RequestBody DataFirstPreviewDto dto) {
|
||||
return R.ok(generatorService.getPreviewCodes(dto));
|
||||
}
|
||||
|
||||
@PostMapping("/generator-code/data-first")
|
||||
@Operation(summary = "数据优先-生成代码")
|
||||
@XjrLog(value = "数据优先生成代码")
|
||||
public R generatorCode(@Valid @RequestBody DataFirstGeneratorDto dto) {
|
||||
return R.ok(generatorService.generateCodes(dto));
|
||||
}
|
||||
|
||||
@PostMapping("/preview-code/code-first")
|
||||
@Operation(summary = "代码优先-预览代码")
|
||||
@XjrLog(value = "界面优先预览代码")
|
||||
public R previewCodeByCodeFirst(@Valid @RequestBody CodeFirstPreviewDto dto) throws Exception {
|
||||
return R.ok(generatorService.getCodeFirstPreviewCodes(dto));
|
||||
}
|
||||
|
||||
@PostMapping("/generator-code/code-first")
|
||||
@Operation(summary = "代码优先-生成代码")
|
||||
@XjrLog(value = "界面优先生成代码")
|
||||
public R generatorCodeByCodeFirst(@Valid @RequestBody CodeFirstGeneratorDto dto) throws Exception {
|
||||
return R.ok(generatorService.generateCodeFirstCodes(dto));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/generator-code/batch")
|
||||
@Operation(summary = "批量生成模板-生成代码")
|
||||
@XjrLog(value = "批量生成代码")
|
||||
public R generatorCodeBatch(@Valid @RequestBody BatchGeneratorDto dto) {
|
||||
return R.ok(generatorService.generatorCodeBatch(dto));
|
||||
}
|
||||
|
||||
@GetMapping("/table-info")
|
||||
@Operation(summary = "根据 tabconfig 获取 表结构信息 用于生成前端model")
|
||||
@XjrLog(value = "获取表结构信息生成前端model")
|
||||
public R tableInfo(@Valid @RequestBody TableInfoDto dto) {
|
||||
return R.ok(generatorService.getTableInfo(dto));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/generator-app-code")
|
||||
@Operation(summary = "生成手机端代码")
|
||||
@XjrLog(value = "生成手机端代码")
|
||||
public R generatorAppCode(@Valid @RequestBody GeneratorAppDto dto) {
|
||||
return R.ok(generatorService.generateAppCodes(dto));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
package com.xjrsoft.generate.service;
|
||||
|
||||
import com.xjrsoft.generate.dto.*;
|
||||
import com.xjrsoft.generate.vo.GeneratorCodeVo;
|
||||
import com.xjrsoft.generate.vo.TableInfoVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IGeneratorService {
|
||||
/**
|
||||
* 根据参数生产代码预览
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
GeneratorCodeVo getPreviewCodes(DataFirstPreviewDto dto);
|
||||
|
||||
/**
|
||||
* 生成代码
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Boolean generateCodes(DataFirstGeneratorDto dto);
|
||||
|
||||
/**
|
||||
* 预览代码优先 的代码
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
GeneratorCodeVo getCodeFirstPreviewCodes(CodeFirstPreviewDto dto) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 生成 代码优先的代码
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Boolean generateCodeFirstCodes(CodeFirstGeneratorDto dto) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 生成 代码优先的代码
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Boolean generatorCodeBatch(BatchGeneratorDto dto);
|
||||
|
||||
|
||||
/**
|
||||
* 根据 tabconfig 获取 表结构信息 用于生成前端model
|
||||
* @param dto 表关系配置
|
||||
* @return
|
||||
*/
|
||||
List<TableInfoVo> getTableInfo(TableInfoDto dto);
|
||||
|
||||
/**
|
||||
* 生成APP代码
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Boolean generateAppCodes(GeneratorAppDto dto);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,4 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: public
|
||||
|
||||
@ -0,0 +1,79 @@
|
||||
server:
|
||||
port: 3009
|
||||
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: generate-service
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
autoconfigure:
|
||||
#自动化配置 例外处理
|
||||
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
dynamic:
|
||||
primary: master
|
||||
datasource:
|
||||
master:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://new-energy-mysqlt.itc.gdyd.com:3307/fcd2-msat-init?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
|
||||
username: learun4dev
|
||||
password: ABcd1234@
|
||||
|
||||
cloud:
|
||||
nacos: #nacos监控
|
||||
discovery:
|
||||
server-addr: 10.0.252.1:8848
|
||||
namespace: ITC
|
||||
group: DNE
|
||||
username: nacos
|
||||
password: ABcd1234@
|
||||
config:
|
||||
server-addr: 10.0.252.1:8848 # nacos 配置中心地址
|
||||
namespace: ITC
|
||||
group: DNE
|
||||
username: nacos
|
||||
password: ABcd1234@
|
||||
file-extension: yml # 指定格式 xjrsoft-demo-service-dev.yml
|
||||
extension-configs:
|
||||
- data-id: global-config.yml #导入全局配置
|
||||
refresh: true
|
||||
group: DNE
|
||||
- data-id: mybatis-plus-config.yml #导入mybatisplus 配置
|
||||
refresh: true
|
||||
group: DNE
|
||||
- data-id: sa-token-client-config.yml #导入sa-token配置
|
||||
refresh: true
|
||||
group: DNE
|
||||
- data-id: redis-config.yml #导入redis配置
|
||||
refresh: true
|
||||
group: DNE
|
||||
- data-id: seata-config.yml #导入seata配置
|
||||
refresh: true
|
||||
group: DNE
|
||||
sentinel:
|
||||
transport:
|
||||
dashboard: localhost:8080 #sentinel dashboard 地址
|
||||
port: 8719 #默认端口, 如果 被占用,会一直+1 直到未被占用为止
|
||||
|
||||
|
||||
|
||||
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
path: /swagger-ui.html
|
||||
tags-sorter: alpha
|
||||
operations-sorter: alpha
|
||||
show-extensions: true
|
||||
api-docs:
|
||||
path: /generate/v3/api-docs
|
||||
group-configs:
|
||||
- group: 'default'
|
||||
paths-to-match: '/generate/**'
|
||||
packages-to-scan: com.xjrsoft.generate
|
||||
default-flat-param-object: false
|
||||
|
||||
|
||||
xjrsoft:
|
||||
generate:
|
||||
@ -0,0 +1,54 @@
|
||||
package ${package};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.time.LocalDateTime;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
<#--子表遍历-->
|
||||
<#if childTables?? >
|
||||
<#list childTables as childTable>
|
||||
import com.xjrsoft.${outputArea}.entity.${childTable.tableName?cap_first};
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @title: ${tableComment}
|
||||
* @Author ${author}
|
||||
* @Date: ${date}
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class Add${entityClass}Dto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
<#--属性遍历-->
|
||||
<#list fields as field>
|
||||
/**
|
||||
* ${(field.fieldComment)!''}
|
||||
*/
|
||||
@Schema(name = "${(field.fieldComment)!''}")
|
||||
<#if field.fieldType == "LocalDateTime" && field.pattern??>
|
||||
@JsonFormat(pattern = "${field.pattern}")
|
||||
</#if>
|
||||
private ${field.fieldType} ${field.fieldName};
|
||||
</#list>
|
||||
|
||||
<#--子表遍历-->
|
||||
<#if childTables?? >
|
||||
<#list childTables as childTable>
|
||||
/**
|
||||
* ${childTable.tableName}
|
||||
*/
|
||||
@Schema(name = "${childTable.tableName}子表")
|
||||
private List<Add${childTable.tableName?cap_first}Dto> ${childTable.tableName?uncap_first}List;
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
||||
@ -0,0 +1,258 @@
|
||||
package ${package};
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.xjrsoft.common.core.constant.GlobalConstant;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.xjrsoft.common.mybatis.utils.ConventPage;
|
||||
import com.xjrsoft.common.core.domain.page.PageOutput;
|
||||
import com.xjrsoft.common.core.domain.result.R;
|
||||
import com.xjrsoft.common.core.uitls.VoToColumnUtil;
|
||||
import com.xjrsoft.${outputArea}.dto.Add${entityClass}Dto;
|
||||
import com.xjrsoft.${outputArea}.dto.Update${entityClass}Dto;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
<#if codeRules != "">
|
||||
import com.xjrsoft.system.client.ICodeRuleClient;
|
||||
</#if>
|
||||
<#if isImport || isExport>
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.xjrsoft.system.utils.ExcelUtil;
|
||||
</#if>
|
||||
<#if isImport>
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.IOException;
|
||||
</#if>
|
||||
<#if isExport>
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
</#if>
|
||||
|
||||
<#if !isPage>
|
||||
import com.xjrsoft.${outputArea}.dto.${entityClass}ListDto;
|
||||
<#else>
|
||||
import com.xjrsoft.${outputArea}.dto.${entityClass}PageDto;
|
||||
</#if>
|
||||
import com.xjrsoft.${outputArea}.entity.${entityClass};
|
||||
import com.xjrsoft.${outputArea}.service.I${className}Service;
|
||||
<#if !isPage>
|
||||
import com.xjrsoft.${outputArea}.vo.${entityClass}ListVo;
|
||||
<#else>
|
||||
import com.xjrsoft.${outputArea}.vo.${entityClass}PageVo;
|
||||
</#if>
|
||||
<#if isDataAuth>
|
||||
import com.xjrsoft.system.dto.BatchSetDataAuthDto;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.ArrayList;
|
||||
</#if>
|
||||
|
||||
import com.xjrsoft.${outputArea}.vo.${entityClass}Vo;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @title: ${tableComment}
|
||||
* @Author ${author}
|
||||
* @Date: ${date}
|
||||
* @Version 1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/${outputArea}" + "/${className?lower_case}")
|
||||
@Tag(name = "/${outputArea}" + "/${className?lower_case}",description = "${tableComment}代码")
|
||||
@AllArgsConstructor
|
||||
public class ${className}Controller {
|
||||
|
||||
|
||||
private final I${className}Service ${className?uncap_first}Service;
|
||||
<#if codeRules != "">
|
||||
private final ICodeRuleClient codeRuleClient;
|
||||
</#if>
|
||||
|
||||
<#if !isPage>
|
||||
@GetMapping(value = "/list")
|
||||
@Operation(summary = "${entityClass}列表(不分页)")
|
||||
@SaCheckPermission("${className?lower_case}:detail")
|
||||
public R list(@Valid ${entityClass}ListDto dto){
|
||||
|
||||
LambdaQueryWrapper<${entityClass}> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper
|
||||
<#--属性遍历-->
|
||||
<#list fields as field>
|
||||
<#if field.fieldType == "String">
|
||||
.like(StrUtil.isNotBlank(dto.get${field.fieldName?cap_first}()),${entityClass}::get${field.fieldName?cap_first},dto.get${field.fieldName?cap_first}())
|
||||
<#elseif field.fieldType == "Integer" || field.fieldType == "Long"|| field.fieldType == "Double"|| field.fieldType == "Float"|| field.fieldType == "Boolean"|| field.fieldType == "BigDecimal" >
|
||||
.eq(ObjectUtil.isNotNull(dto.get${field.fieldName?cap_first}()),${entityClass}::get${field.fieldName?cap_first},dto.get${field.fieldName?cap_first}())
|
||||
<#elseif field.fieldType == "LocalDateTime" || field.fieldType == "LocalTime">
|
||||
.between(ObjectUtil.isNotNull(dto.get${field.fieldName?cap_first}Start()) && ObjectUtil.isNotNull(dto.get${field.fieldName?cap_first}End()),${entityClass}::get${field.fieldName?cap_first},dto.get${field.fieldName?cap_first}Start(),dto.get${field.fieldName?cap_first}End())
|
||||
<#else>
|
||||
.like(StrUtil.isNotBlank(dto.get${field.fieldName?cap_first}()),${entityClass}::get${field.fieldName?cap_first},dto.get${field.fieldName?cap_first}())
|
||||
</#if>
|
||||
</#list>
|
||||
<#--默认排序-->
|
||||
<#if orderField?? && orderField != "">
|
||||
<#if orderType>
|
||||
.orderByDesc(${entityClass}::get${orderField?cap_first})
|
||||
<#else>
|
||||
.orderByAsc(${entityClass}::get${orderField?cap_first})
|
||||
</#if>
|
||||
<#-- 如果需要根据前端所传字段排序 屏蔽上面 放开下面-->
|
||||
<#-- .orderBy(StrUtil.isBlank(dto.getOrderField()),${orderType?string("false","true")},${entityClass}::get${orderField?cap_first})-->
|
||||
<#-- .last(StrUtil.isNotBlank(dto.getOrderField()) && StrUtil.isNotBlank(dto.getOrder()),"order by " + dto.getOrderField() + StringPool.SPACE + dto.getOrder())-->
|
||||
</#if>
|
||||
.select(${entityClass}.class,x -> VoToColumnUtil.fieldsToColumns(${entityClass}ListVo.class).contains(x.getProperty()));
|
||||
|
||||
List<${entityClass}> list = ${className?uncap_first}Service.list(queryWrapper);
|
||||
List<${entityClass}ListVo> listVos = BeanUtil.copyToList(list, ${entityClass}ListVo.class);
|
||||
return R.ok(listVos);
|
||||
}
|
||||
<#else>
|
||||
@GetMapping(value = "/page")
|
||||
@Operation(summary = "${entityClass}列表(分页)")
|
||||
@SaCheckPermission("${className?lower_case}:detail")
|
||||
public R page(@Valid ${entityClass}PageDto dto){
|
||||
|
||||
LambdaQueryWrapper<${entityClass}> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper
|
||||
<#--属性遍历-->
|
||||
<#list fields as field>
|
||||
<#if field.fieldType == "String">
|
||||
.like(StrUtil.isNotBlank(dto.get${field.fieldName?cap_first}()),${entityClass}::get${field.fieldName?cap_first},dto.get${field.fieldName?cap_first}())
|
||||
<#elseif field.fieldType == "Integer" || field.fieldType == "Long"|| field.fieldType == "Double"|| field.fieldType == "Float"|| field.fieldType == "Boolean" || field.fieldType == "BigDecimal" >
|
||||
.eq(ObjectUtil.isNotNull(dto.get${field.fieldName?cap_first}()),${entityClass}::get${field.fieldName?cap_first},dto.get${field.fieldName?cap_first}())
|
||||
<#elseif field.fieldType == "LocalDateTime" || field.fieldType == "LocalTime">
|
||||
.between(ObjectUtil.isNotNull(dto.get${field.fieldName?cap_first}Start()) && ObjectUtil.isNotNull(dto.get${field.fieldName?cap_first}End()),${entityClass}::get${field.fieldName?cap_first},dto.get${field.fieldName?cap_first}Start(),dto.get${field.fieldName?cap_first}End())
|
||||
<#else>
|
||||
.like(StrUtil.isNotBlank(dto.get${field.fieldName?cap_first}()),${entityClass}::get${field.fieldName?cap_first},dto.get${field.fieldName?cap_first}())
|
||||
</#if>
|
||||
</#list>
|
||||
<#--默认排序-->
|
||||
<#if orderField?? && orderField != "">
|
||||
<#if orderType>
|
||||
.orderByDesc(${entityClass}::get${orderField?cap_first})
|
||||
<#else>
|
||||
.orderByAsc(${entityClass}::get${orderField?cap_first})
|
||||
</#if>
|
||||
<#-- .orderBy(StrUtil.isBlank(dto.getOrderField()),${orderType?string("false","true")},${entityClass}::get${orderField?cap_first})-->
|
||||
</#if>
|
||||
.select(${entityClass}.class,x -> VoToColumnUtil.fieldsToColumns(${entityClass}PageVo.class).contains(x.getProperty()));
|
||||
IPage<${entityClass}> page = ${className?uncap_first}Service.page(ConventPage.getPage(dto), queryWrapper);
|
||||
PageOutput<${entityClass}PageVo> pageOutput = ConventPage.getPageOutput(page, ${entityClass}PageVo.class);
|
||||
return R.ok(pageOutput);
|
||||
}
|
||||
</#if>
|
||||
|
||||
@GetMapping(value = "/info")
|
||||
@Operation(summary = "根据id查询${entityClass}信息")
|
||||
@SaCheckPermission("${className?lower_case}:detail")
|
||||
public R info(@RequestParam ${pkType} id){
|
||||
${entityClass} ${entityClass?uncap_first} = ${className?uncap_first}Service.${isMulti?string("getByIdDeep","getById")}(id);
|
||||
if (${entityClass?uncap_first} == null) {
|
||||
return R.error("找不到此数据!");
|
||||
}
|
||||
return R.ok(BeanUtil.toBean(${entityClass?uncap_first}, ${entityClass}Vo.class));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "新增${entityClass}")
|
||||
@SaCheckPermission("${className?lower_case}:add")
|
||||
public R add(@Valid @RequestBody Add${entityClass}Dto dto){
|
||||
<#if isMulti>
|
||||
${entityClass} ${entityClass?uncap_first} = BeanUtil.toBean(dto, ${entityClass}.class);
|
||||
boolean isSuccess = ${className?uncap_first}Service.add(${entityClass?uncap_first});
|
||||
<#else >
|
||||
${entityClass} ${entityClass?uncap_first} = BeanUtil.toBean(dto, ${entityClass}.class);
|
||||
boolean isSuccess = ${className?uncap_first}Service.save(${entityClass?uncap_first});
|
||||
</#if>
|
||||
<#if codeRules != "">
|
||||
codeRuleClient.useEnCodeFeign("${codeRules}");
|
||||
</#if>
|
||||
return R.ok(${entityClass?uncap_first}.get${pkField?cap_first}());
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "修改${entityClass}")
|
||||
@SaCheckPermission("${className?lower_case}:edit")
|
||||
public R update(@Valid @RequestBody Update${entityClass}Dto dto){
|
||||
|
||||
<#if isMulti>
|
||||
${entityClass} ${entityClass?uncap_first} = BeanUtil.toBean(dto, ${entityClass}.class);
|
||||
return R.ok(${className?uncap_first}Service.update(${entityClass?uncap_first}));
|
||||
<#else >
|
||||
${entityClass} ${entityClass?uncap_first} = BeanUtil.toBean(dto, ${entityClass}.class);
|
||||
return R.ok(${className?uncap_first}Service.updateById(${entityClass?uncap_first}));
|
||||
</#if>
|
||||
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Operation(summary = "删除")
|
||||
@SaCheckPermission("${className?lower_case}:delete")
|
||||
public R delete(@Valid @RequestBody List<${pkType}> ids){
|
||||
<#if isMulti>
|
||||
return R.ok(${className?uncap_first}Service.delete(ids));
|
||||
<#else >
|
||||
return R.ok(${className?uncap_first}Service.removeBatchByIds(ids));
|
||||
</#if>
|
||||
|
||||
}
|
||||
<#if isPage>
|
||||
<#assign importClass = "${entityClass}Page">
|
||||
<#else>
|
||||
<#assign importClass = "${entityClass}List">
|
||||
</#if>
|
||||
<#if isImport>
|
||||
@PostMapping("/import")
|
||||
@Operation(summary = "导入")
|
||||
public R importData(@RequestParam MultipartFile file) throws IOException {
|
||||
List<${importClass}Vo> savedDataList = EasyExcel.read(file.getInputStream()).head(${importClass}Vo.class).sheet().doReadSync();
|
||||
ExcelUtil.transExcelData(savedDataList, true);
|
||||
${className?uncap_first}Service.saveBatch(BeanUtil.copyToList(savedDataList, ${entityClass}.class));
|
||||
return R.ok();
|
||||
}
|
||||
</#if>
|
||||
|
||||
<#if isExport>
|
||||
@GetMapping("/export")
|
||||
@Operation(summary = "导出")
|
||||
public ResponseEntity<byte[]> exportData(@Valid ${importClass}Dto dto, @RequestParam(defaultValue = "false") Boolean isTemplate) {
|
||||
<#if isPage>
|
||||
List<${importClass}Vo> customerList = isTemplate != null && isTemplate ? new ArrayList<>() : ((PageOutput<${importClass}Vo>) page(dto).getData()).getList();
|
||||
<#else>
|
||||
List<${importClass}Vo> customerList = (List<${importClass}Vo>) page(dto).getData());
|
||||
</#if>
|
||||
ExcelUtil.transExcelData(customerList, false);
|
||||
ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
||||
EasyExcel.write(bot, ${importClass}Vo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(customerList);
|
||||
ByteArrayOutputStream resultBot = ExcelUtil.renderExportRequiredHead(bot);
|
||||
|
||||
return R.fileStream(resultBot.toByteArray(), "${className}" + ExcelTypeEnum.XLSX.getValue());
|
||||
}
|
||||
</#if>
|
||||
<#if isDataAuth>
|
||||
@PutMapping("/data-auth")
|
||||
@Operation(summary = "批量设置权限所属人")
|
||||
public R setDataAUth(@RequestBody BatchSetDataAuthDto dto){
|
||||
List<${entityClass}> toUpdateList = new ArrayList<>();
|
||||
<#-- String userIdStr = dto.getUserIdList().stream().collect(Collectors.joining(StringPool.COMMA));-->
|
||||
for (Long dataId : dto.getDataIdList()) {
|
||||
${entityClass} ${entityClass?uncap_first} = new ${entityClass}();
|
||||
${entityClass?uncap_first}.set${pkField?cap_first}(dataId);
|
||||
${entityClass?uncap_first}.setRuleUserId(dto.getUserIdList().get(0));
|
||||
toUpdateList.add(${entityClass?uncap_first});
|
||||
}
|
||||
return R.ok(${className?uncap_first}Service.updateBatchById(toUpdateList));
|
||||
}
|
||||
</#if>
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package ${package};
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.github.yulichang.annotation.EntityMapping;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalTime;
|
||||
import java.time.LocalDateTime;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @title: ${tableComment}
|
||||
* @Author ${author}
|
||||
* @Date: ${date}
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("${tableName}")
|
||||
@Tag(name = "${tableComment}对象", description = "${tableComment}")
|
||||
public class ${entityClass} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
<#--属性遍历-->
|
||||
<#list fields as field>
|
||||
/**
|
||||
* ${(field.fieldComment)!''}
|
||||
*/
|
||||
@Schema(name = "${(field.fieldComment)!''}")
|
||||
<#if field.autoInsert?? >
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
</#if>
|
||||
<#if field.autoUpdate?? >
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
</#if>
|
||||
<#if field.deleteMark?? >
|
||||
@TableLogic
|
||||
</#if>
|
||||
<#if field.pk>
|
||||
@TableId
|
||||
</#if>
|
||||
private ${field.fieldType} ${field.fieldName};
|
||||
</#list>
|
||||
|
||||
<#--子表遍历-->
|
||||
<#if childTables?? >
|
||||
<#list childTables as childTable>
|
||||
/**
|
||||
* ${childTable.tableName}
|
||||
*/
|
||||
@Schema(name = "${childTable.tableName}子表")
|
||||
@TableField(exist = false)
|
||||
@EntityMapping(thisField = "${childTable.relationTableField}", joinField = "${childTable.relationField}")
|
||||
private List<${childTable.tableName?cap_first}> ${childTable.tableName}List;
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package ${package};
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.xjrsoft.${outputArea}.entity.${entityClass};
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @title: ${tableComment}
|
||||
* @Author ${author}
|
||||
* @Date: ${date}
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface ${entityClass}Mapper extends ${isMulti?string("MPJBaseMapper","BaseMapper")}<${entityClass}> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package ${package};
|
||||
|
||||
${isPage?string("import com.xjrsoft.common.core.domain.page.PageInput;","import com.xjrsoft.common.core.domain.page.ListInput;")}
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.time.LocalDateTime;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
||||
/**
|
||||
* @title: ${tableComment}
|
||||
* @Author ${author}
|
||||
* @Date: ${date}
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ${entityClass}${isPage?string("Page","List")}Dto ${isPage?string("extends PageInput","extends ListInput")} {
|
||||
|
||||
<#--属性遍历-->
|
||||
<#list fields as field>
|
||||
/**
|
||||
* ${(field.fieldComment)!''}
|
||||
*/
|
||||
@Schema(name = "${(field.fieldComment)!''}")
|
||||
<#if field.fieldType == "LocalDateTime" >
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
</#if>
|
||||
private ${field.fieldType} ${field.fieldName};
|
||||
</#list>
|
||||
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package ${package};
|
||||
|
||||
<#if isImport || isExport>
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.write.style.ContentStyle;
|
||||
</#if>
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import com.xjrsoft.common.core.annotation.Trans;
|
||||
import com.xjrsoft.common.core.enums.TransType;
|
||||
import java.time.LocalTime;
|
||||
import java.time.LocalDateTime;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @title: ${tableComment}
|
||||
* @Author ${author}
|
||||
* @Date: ${date}
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class ${entityClass}${isPage?string("Page","List")}Vo {
|
||||
|
||||
<#--属性遍历-->
|
||||
<#list fields as field>
|
||||
/**
|
||||
* ${(field.fieldComment)!''}
|
||||
*/
|
||||
<#if !(field.pk || field.fieldName == "ruleUserId")>
|
||||
<#if isImport || isExport>
|
||||
<#-- 所有单元格设置成文本格式-->
|
||||
@ContentStyle(dataFormat = 49)
|
||||
@ExcelProperty("${field.label}<#if field.required>${requiredSuffix}</#if>")
|
||||
</#if>
|
||||
<#else>
|
||||
<#if isImport || isExport>
|
||||
@ExcelIgnore
|
||||
</#if>
|
||||
</#if>
|
||||
@Schema(name = "${(field.fieldComment)!''}")
|
||||
<#if field.fieldType == "LocalDateTime" && field.pattern??>
|
||||
@JsonFormat(pattern = "${field.pattern}")
|
||||
</#if>
|
||||
<#if field.datasourceType??>
|
||||
<#assign multi = "">
|
||||
<#if field.multi><#assign multi = ", isMulti = true"></#if>
|
||||
<#if field.datasourceType = "dic">
|
||||
@Trans(type = TransType.DIC, id = "${field.datasourceId}"${multi})
|
||||
</#if>
|
||||
<#if field.datasourceType = "api">
|
||||
@Trans(type = TransType.API, id = "${field.datasourceId}"${multi})
|
||||
</#if>
|
||||
</#if>
|
||||
<#if field.componentType??>
|
||||
<#if field.componentType = "user">
|
||||
@Trans(type = TransType.USER)
|
||||
</#if>
|
||||
<#if field.componentType = "organization">
|
||||
@Trans(type = TransType.DEPT)
|
||||
</#if>
|
||||
<#if field.componentType = "area">
|
||||
@Trans(type = TransType.AREA)
|
||||
</#if>
|
||||
<#if field.componentType = "cascader">
|
||||
@Trans(type = TransType.CASCADE, id = "${field.datasourceId}", separator = "${field.separator}", showFormat = "${field.showFormat}")
|
||||
</#if>
|
||||
</#if>
|
||||
private ${field.fieldType} ${field.fieldName};
|
||||
</#list>
|
||||
|
||||
}
|
||||
@ -0,0 +1,113 @@
|
||||
package ${package};
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.base.MPJBaseServiceImpl;
|
||||
<#if isMulti>
|
||||
<#--子表遍历-->
|
||||
<#list childTables as childTable>
|
||||
import com.xjrsoft.${outputArea}.entity.${childTable.tableName?cap_first};
|
||||
import com.xjrsoft.${outputArea}.mapper.${childTable.tableName?cap_first}Mapper;
|
||||
</#list>
|
||||
</#if>
|
||||
import com.xjrsoft.${outputArea}.entity.${entityClass};
|
||||
import com.xjrsoft.${outputArea}.mapper.${entityClass}Mapper;
|
||||
import com.xjrsoft.${outputArea}.service.I${className}Service;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
<#if databaseId?? && databaseId != "master">
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
</#if>
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
|
||||
/**
|
||||
* @title: ${tableComment}
|
||||
* @Author ${author}
|
||||
* @Date: ${date}
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
<#if databaseId?? && databaseId != "master">
|
||||
@DS("${databaseId}")
|
||||
</#if>
|
||||
public class ${className}ServiceImpl extends ${isMulti?string("MPJBaseService","Service")}Impl<${entityClass}Mapper, ${entityClass}> implements I${className}Service {
|
||||
<#if isMulti>
|
||||
private final ${entityClass}Mapper ${className?uncap_first}${entityClass}Mapper;
|
||||
|
||||
<#--子表遍历-->
|
||||
<#list childTables as childTable>
|
||||
private final ${childTable.tableName?cap_first}Mapper ${className?uncap_first}${childTable.tableName?cap_first}Mapper;
|
||||
</#list>
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean add(${entityClass} ${entityClass?uncap_first}) {
|
||||
${className?uncap_first}${entityClass}Mapper.insert(${entityClass?uncap_first});
|
||||
<#--子表遍历-->
|
||||
<#list childTables as childTable>
|
||||
for (${childTable.tableName?cap_first} ${childTable.tableName} : ${entityClass?uncap_first}.get${childTable.tableName?cap_first}List()) {
|
||||
${childTable.tableName}.set${childTable.relationField?cap_first}(${entityClass?uncap_first}.get${childTable.relationTableField?cap_first}());
|
||||
${className?uncap_first}${childTable.tableName?cap_first}Mapper.insert(${childTable.tableName});
|
||||
}
|
||||
</#list>
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean update(${entityClass} ${entityClass?uncap_first}) {
|
||||
${className?uncap_first}${entityClass}Mapper.updateById(${entityClass?uncap_first});
|
||||
<#--子表遍历-->
|
||||
<#list childTables as childTable>
|
||||
//********************************* ${childTable.tableName?cap_first} 增删改 开始 *******************************************/
|
||||
{
|
||||
// 查出所有子级的id
|
||||
List<${childTable.tableName?cap_first}> ${childTable.tableName}List = ${className?uncap_first}${childTable.tableName?cap_first}Mapper.selectList(Wrappers.lambdaQuery(${childTable.tableName?cap_first}.class).eq(${childTable.tableName?cap_first}::get${childTable.relationField?cap_first}, ${entityClass?uncap_first}.get${childTable.relationTableField?cap_first}()).select(${childTable.tableName?cap_first}::get${childTable.pkField?cap_first}));
|
||||
List<${childTable.pkType}> ${childTable.tableName}Ids = ${childTable.tableName}List.stream().map(${childTable.tableName?cap_first}::get${childTable.pkField?cap_first}).collect(Collectors.toList());
|
||||
//原有子表单 没有被删除的主键
|
||||
List<${childTable.pkType}> ${childTable.tableName}OldIds = ${entityClass?uncap_first}.get${childTable.tableName?cap_first}List().stream().map(${childTable.tableName?cap_first}::get${childTable.pkField?cap_first}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
//找到需要删除的id
|
||||
List<${childTable.pkType}> ${childTable.tableName}RemoveIds = ${childTable.tableName}Ids.stream().filter(item -> !${childTable.tableName}OldIds.contains(item)).collect(Collectors.toList());
|
||||
|
||||
for (${childTable.tableName?cap_first} ${childTable.tableName} : ${entityClass?uncap_first}.get${childTable.tableName?cap_first}List()) {
|
||||
//如果不等于空则修改
|
||||
if (${childTable.tableName}.get${childTable.pkField?cap_first}() != null) {
|
||||
${className?uncap_first}${childTable.tableName?cap_first}Mapper.updateById(${childTable.tableName});
|
||||
}
|
||||
//如果等于空 则新增
|
||||
else {
|
||||
//已经不存在的id 删除
|
||||
${childTable.tableName}.set${childTable.relationField?cap_first}(${entityClass?uncap_first}.get${childTable.relationTableField?cap_first}());
|
||||
${className?uncap_first}${childTable.tableName?cap_first}Mapper.insert(${childTable.tableName});
|
||||
}
|
||||
}
|
||||
//已经不存在的id 删除
|
||||
if(${childTable.tableName}RemoveIds.size() > 0){
|
||||
${className?uncap_first}${childTable.tableName?cap_first}Mapper.deleteBatchIds(${childTable.tableName}RemoveIds);
|
||||
}
|
||||
}
|
||||
//********************************* ${childTable.tableName?cap_first} 增删改 结束 *******************************************/
|
||||
|
||||
</#list>
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean delete(List<${pkType}> ids) {
|
||||
${className?uncap_first}${entityClass}Mapper.deleteBatchIds(ids);
|
||||
<#--子表遍历-->
|
||||
<#list childTables as childTable>
|
||||
${className?uncap_first}${childTable.tableName?cap_first}Mapper.delete(Wrappers.lambdaQuery(${childTable.tableName?cap_first}.class).in(${childTable.tableName?cap_first}::get${childTable.relationField?cap_first}, ids));
|
||||
</#list>
|
||||
|
||||
return true;
|
||||
}
|
||||
</#if>
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package ${package};
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.github.yulichang.base.MPJBaseService;
|
||||
import com.xjrsoft.${outputArea}.entity.${entityClass};
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @title: ${tableComment}
|
||||
* @Author ${author}
|
||||
* @Date: ${date}
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
public interface I${className}Service extends ${isMulti?string("MPJBaseService","IService")}<${entityClass}> {
|
||||
<#if isMulti>
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param ${entityClass?uncap_first}
|
||||
* @return
|
||||
*/
|
||||
Boolean add(${entityClass} ${entityClass?uncap_first});
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param ${entityClass?uncap_first}
|
||||
* @return
|
||||
*/
|
||||
Boolean update(${entityClass} ${entityClass?uncap_first});
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
Boolean delete(List<${pkType}> ids);
|
||||
</#if>
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package ${package};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.time.LocalDateTime;
|
||||
import java.math.BigDecimal;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import java.util.List;
|
||||
<#--子表遍历-->
|
||||
<#if childTables?? >
|
||||
<#list childTables as childTable>
|
||||
import com.xjrsoft.${outputArea}.entity.${childTable.tableName?cap_first};
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @title: ${tableComment}
|
||||
* @Author ${author}
|
||||
* @Date: ${date}
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class Update${entityClass}Dto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
<#--属性遍历-->
|
||||
<#list fields as field>
|
||||
/**
|
||||
* ${(field.fieldComment)!''}
|
||||
*/
|
||||
@Schema(name = "${(field.fieldComment)!''}")
|
||||
<#if field.fieldType == "LocalDateTime" && field.pattern??>
|
||||
@JsonFormat(pattern = "${field.pattern}")
|
||||
</#if>
|
||||
private ${field.fieldType} ${field.fieldName};
|
||||
</#list>
|
||||
|
||||
<#--子表遍历-->
|
||||
<#if childTables?? >
|
||||
<#list childTables as childTable>
|
||||
/**
|
||||
* ${childTable.tableName}
|
||||
*/
|
||||
@Schema(name = "${childTable.tableName}子表")
|
||||
private List<Update${childTable.tableName?cap_first}Dto> ${childTable.tableName}List;
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package ${package};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.time.LocalDateTime;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
<#--子表遍历-->
|
||||
<#if childTables?? >
|
||||
<#list childTables as childTable>
|
||||
import com.xjrsoft.${outputArea}.entity.${childTable.tableName?cap_first};
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
/**
|
||||
* @title: ${tableComment}
|
||||
* @Author ${author}
|
||||
* @Date: ${date}
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class ${entityClass}Vo {
|
||||
|
||||
<#--属性遍历-->
|
||||
<#list fields as field>
|
||||
/**
|
||||
* ${(field.fieldComment)!''}
|
||||
*/
|
||||
@Schema(name = "${(field.fieldComment)!''}")
|
||||
private ${field.fieldType} ${field.fieldName};
|
||||
</#list>
|
||||
|
||||
|
||||
<#--子表遍历-->
|
||||
<#if childTables?? >
|
||||
<#list childTables as childTable>
|
||||
/**
|
||||
* ${childTable.tableName}
|
||||
*/
|
||||
@Schema(name = "${childTable.tableName}子表")
|
||||
private List<${childTable.tableName?cap_first}Vo> ${childTable.tableName}List;
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user