mirror of https://github.com/elunez/eladmin
代码生成器优化,生成代码更加便捷
parent
e4ca7afc70
commit
203c1d692c
|
@ -30,6 +30,9 @@ public class GenConfig {
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String tableName;
|
private String tableName;
|
||||||
|
|
||||||
|
/** 接口名称 **/
|
||||||
|
private String apiAlias;
|
||||||
|
|
||||||
/** 包路径 */
|
/** 包路径 */
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String pack;
|
private String pack;
|
||||||
|
|
|
@ -58,13 +58,14 @@ public class GenUtil {
|
||||||
List<String> templateNames = new ArrayList<>();
|
List<String> templateNames = new ArrayList<>();
|
||||||
templateNames.add("api");
|
templateNames.add("api");
|
||||||
templateNames.add("index");
|
templateNames.add("index");
|
||||||
templateNames.add("eForm");
|
|
||||||
return templateNames;
|
return templateNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generatorCode(List<ColumnInfo> columnInfos, GenConfig genConfig) throws IOException {
|
public static void generatorCode(List<ColumnInfo> columnInfos, GenConfig genConfig) throws IOException {
|
||||||
// 存储模版字段数据
|
// 存储模版字段数据
|
||||||
Map<String,Object> genMap = new HashMap<>(16);
|
Map<String,Object> genMap = new HashMap<>(16);
|
||||||
|
// 接口别名
|
||||||
|
genMap.put("apiAlias",genConfig.getApiAlias());
|
||||||
// 包名称
|
// 包名称
|
||||||
genMap.put("package",genConfig.getPack());
|
genMap.put("package",genConfig.getPack());
|
||||||
// 模块名称
|
// 模块名称
|
||||||
|
@ -110,8 +111,8 @@ public class GenUtil {
|
||||||
List<Map<String,Object>> queryColumns = new ArrayList<>();
|
List<Map<String,Object>> queryColumns = new ArrayList<>();
|
||||||
// 存储字典信息
|
// 存储字典信息
|
||||||
List<String> dicts = new ArrayList<>();
|
List<String> dicts = new ArrayList<>();
|
||||||
// 存储 DateRange 信息
|
// 存储 between 信息
|
||||||
List<Map<String,Object>> dateRanges = new ArrayList<>();
|
List<Map<String,Object>> betweens = new ArrayList<>();
|
||||||
// 存储不为空的字段信息
|
// 存储不为空的字段信息
|
||||||
List<Map<String,Object>> isNotNullColumns = new ArrayList<>();
|
List<Map<String,Object>> isNotNullColumns = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -194,8 +195,8 @@ public class GenUtil {
|
||||||
// 查询中存储 BigDecimal 类型
|
// 查询中存储 BigDecimal 类型
|
||||||
genMap.put("queryHasBigDecimal",true);
|
genMap.put("queryHasBigDecimal",true);
|
||||||
}
|
}
|
||||||
if("DateRange".equalsIgnoreCase(column.getQueryType())){
|
if("between".equalsIgnoreCase(column.getQueryType())){
|
||||||
dateRanges.add(listMap);
|
betweens.add(listMap);
|
||||||
} else {
|
} else {
|
||||||
// 添加到查询列表中
|
// 添加到查询列表中
|
||||||
queryColumns.add(listMap);
|
queryColumns.add(listMap);
|
||||||
|
@ -211,7 +212,7 @@ public class GenUtil {
|
||||||
// 保存字段列表
|
// 保存字段列表
|
||||||
genMap.put("dicts",dicts);
|
genMap.put("dicts",dicts);
|
||||||
// 保存查询列表
|
// 保存查询列表
|
||||||
genMap.put("dateRanges",dateRanges);
|
genMap.put("betweens",betweens);
|
||||||
// 保存非空字段信息
|
// 保存非空字段信息
|
||||||
genMap.put("isNotNullColumns",isNotNullColumns);
|
genMap.put("isNotNullColumns",isNotNullColumns);
|
||||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||||
|
@ -277,7 +278,7 @@ public class GenUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("Dto".equals(templateName)) {
|
if ("Dto".equals(templateName)) {
|
||||||
return packagePath + "service" + File.separator + "dto" + File.separator + className + "DTO.java";
|
return packagePath + "service" + File.separator + "dto" + File.separator + className + "Dto.java";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("QueryCriteria".equals(templateName)) {
|
if ("QueryCriteria".equals(templateName)) {
|
||||||
|
@ -309,9 +310,6 @@ public class GenUtil {
|
||||||
return path + File.separator + "index.vue";
|
return path + File.separator + "index.vue";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("eForm".equals(templateName)) {
|
|
||||||
return path + File.separator + File.separator + "form.vue";
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package me.zhengjie.gen.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
|
import javax.persistence.*;
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import org.hibernate.annotations.*;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zheng Jie
|
||||||
|
* @date 2019-11-25
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
@Table(name="gen_test")
|
||||||
|
public class GenTest implements Serializable {
|
||||||
|
|
||||||
|
/** ID */
|
||||||
|
@Id
|
||||||
|
@Column(name = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 名称 */
|
||||||
|
@Column(name = "name",nullable = false)
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 状态 */
|
||||||
|
@Column(name = "status",nullable = false)
|
||||||
|
@NotNull
|
||||||
|
private Boolean status;
|
||||||
|
|
||||||
|
/** 日期 */
|
||||||
|
@Column(name = "date",nullable = false)
|
||||||
|
@NotNull
|
||||||
|
private Timestamp date;
|
||||||
|
|
||||||
|
/** 创建日期 */
|
||||||
|
@Column(name = "create_time")
|
||||||
|
@CreationTimestamp
|
||||||
|
private Timestamp createTime;
|
||||||
|
|
||||||
|
public void copy(GenTest source){
|
||||||
|
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package me.zhengjie.gen.repository;
|
||||||
|
|
||||||
|
import me.zhengjie.gen.domain.GenTest;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zheng Jie
|
||||||
|
* @date 2019-11-25
|
||||||
|
*/
|
||||||
|
public interface GenTestRepository extends JpaRepository<GenTest, Long>, JpaSpecificationExecutor<GenTest> {
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
package me.zhengjie.gen.rest;
|
||||||
|
|
||||||
|
import me.zhengjie.aop.log.Log;
|
||||||
|
import me.zhengjie.gen.domain.GenTest;
|
||||||
|
import me.zhengjie.gen.service.GenTestService;
|
||||||
|
import me.zhengjie.gen.service.dto.GenTestQueryCriteria;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.annotations.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zheng Jie
|
||||||
|
* @date 2019-11-25
|
||||||
|
*/
|
||||||
|
@Api(tags = "测试生成管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/genTest")
|
||||||
|
public class GenTestController {
|
||||||
|
|
||||||
|
private final GenTestService genTestService;
|
||||||
|
|
||||||
|
public GenTestController(GenTestService genTestService) {
|
||||||
|
this.genTestService = genTestService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log("导出数据")
|
||||||
|
@ApiOperation("导出数据")
|
||||||
|
@GetMapping(value = "/download")
|
||||||
|
@PreAuthorize("@el.check('genTest:list')")
|
||||||
|
public void download(HttpServletResponse response, GenTestQueryCriteria criteria) throws IOException {
|
||||||
|
genTestService.download(genTestService.queryAll(criteria), response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@Log("查询测试生成")
|
||||||
|
@ApiOperation("查询测试生成")
|
||||||
|
@PreAuthorize("@el.check('genTest:list')")
|
||||||
|
public ResponseEntity getGenTests(GenTestQueryCriteria criteria, Pageable pageable){
|
||||||
|
return new ResponseEntity<>(genTestService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
@Log("新增测试生成")
|
||||||
|
@ApiOperation("新增测试生成")
|
||||||
|
@PreAuthorize("@el.check('genTest:add')")
|
||||||
|
public ResponseEntity create(@Validated @RequestBody GenTest resources){
|
||||||
|
return new ResponseEntity<>(genTestService.create(resources),HttpStatus.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping
|
||||||
|
@Log("修改测试生成")
|
||||||
|
@ApiOperation("修改测试生成")
|
||||||
|
@PreAuthorize("@el.check('genTest:edit')")
|
||||||
|
public ResponseEntity update(@Validated @RequestBody GenTest resources){
|
||||||
|
genTestService.update(resources);
|
||||||
|
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping(value = "/{id}")
|
||||||
|
@Log("删除测试生成")
|
||||||
|
@ApiOperation("删除测试生成")
|
||||||
|
@PreAuthorize("@el.check('genTest:del')")
|
||||||
|
public ResponseEntity delete(@PathVariable Long id){
|
||||||
|
genTestService.delete(id);
|
||||||
|
return new ResponseEntity(HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log("多选删除测试生成")
|
||||||
|
@ApiOperation("多选删除测试生成")
|
||||||
|
@PreAuthorize("@el.check('genTest:del')")
|
||||||
|
@DeleteMapping
|
||||||
|
public ResponseEntity deleteAll(@RequestBody Long[] ids) {
|
||||||
|
genTestService.deleteAll(ids);
|
||||||
|
return new ResponseEntity(HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package me.zhengjie.gen.service;
|
||||||
|
|
||||||
|
import me.zhengjie.gen.domain.GenTest;
|
||||||
|
import me.zhengjie.gen.service.dto.GenTestDto;
|
||||||
|
import me.zhengjie.gen.service.dto.GenTestQueryCriteria;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.List;
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zheng Jie
|
||||||
|
* @date 2019-11-25
|
||||||
|
*/
|
||||||
|
public interface GenTestService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据分页
|
||||||
|
* @param criteria 条件
|
||||||
|
* @param pageable 分页参数
|
||||||
|
* @return Map<String,Object>
|
||||||
|
*/
|
||||||
|
Map<String,Object> queryAll(GenTestQueryCriteria criteria, Pageable pageable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有数据不分页
|
||||||
|
* @param criteria 条件参数
|
||||||
|
* @return List<GenTestDto>
|
||||||
|
*/
|
||||||
|
List<GenTestDto> queryAll(GenTestQueryCriteria criteria);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
* @param id ID
|
||||||
|
* @return GenTestDto
|
||||||
|
*/
|
||||||
|
GenTestDto findById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建
|
||||||
|
* @param resources /
|
||||||
|
* @return GenTestDto
|
||||||
|
*/
|
||||||
|
GenTestDto create(GenTest resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑
|
||||||
|
* @param resources /
|
||||||
|
*/
|
||||||
|
void update(GenTest resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
* @param id /
|
||||||
|
*/
|
||||||
|
void delete(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多选删除
|
||||||
|
* @param ids /
|
||||||
|
*/
|
||||||
|
void deleteAll(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出数据
|
||||||
|
* @param all 待导出的数据
|
||||||
|
* @param response /
|
||||||
|
* @throws IOException /
|
||||||
|
*/
|
||||||
|
void download(List<GenTestDto> all, HttpServletResponse response) throws IOException;
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package me.zhengjie.gen.service.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zheng Jie
|
||||||
|
* @date 2019-11-25
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class GenTestDto implements Serializable {
|
||||||
|
|
||||||
|
/** ID */
|
||||||
|
/** 防止精度丢失 */
|
||||||
|
@JsonSerialize(using= ToStringSerializer.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 名称 */
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 状态 */
|
||||||
|
private Boolean status;
|
||||||
|
|
||||||
|
/** 日期 */
|
||||||
|
private Timestamp date;
|
||||||
|
|
||||||
|
/** 创建日期 */
|
||||||
|
private Timestamp createTime;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package me.zhengjie.gen.service.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
|
import me.zhengjie.annotation.Query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zheng Jie
|
||||||
|
* @date 2019-11-25
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class GenTestQueryCriteria{
|
||||||
|
|
||||||
|
/** 模糊 */
|
||||||
|
@Query(type = Query.Type.INNER_LIKE)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 精确 */
|
||||||
|
@Query
|
||||||
|
private Boolean status;
|
||||||
|
/** BETWEEN */
|
||||||
|
@Query(type = Query.Type.BETWEEN)
|
||||||
|
private List<Timestamp> createTime;
|
||||||
|
}
|
|
@ -0,0 +1,116 @@
|
||||||
|
package me.zhengjie.gen.service.impl;
|
||||||
|
|
||||||
|
import me.zhengjie.gen.domain.GenTest;
|
||||||
|
import me.zhengjie.utils.ValidationUtil;
|
||||||
|
import me.zhengjie.utils.FileUtil;
|
||||||
|
import me.zhengjie.gen.repository.GenTestRepository;
|
||||||
|
import me.zhengjie.gen.service.GenTestService;
|
||||||
|
import me.zhengjie.gen.service.dto.GenTestDto;
|
||||||
|
import me.zhengjie.gen.service.dto.GenTestQueryCriteria;
|
||||||
|
import me.zhengjie.gen.service.mapper.GenTestMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import cn.hutool.core.lang.Snowflake;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import me.zhengjie.utils.PageUtil;
|
||||||
|
import me.zhengjie.utils.QueryHelp;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zheng Jie
|
||||||
|
* @date 2019-11-25
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@CacheConfig(cacheNames = "genTest")
|
||||||
|
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||||
|
public class GenTestServiceImpl implements GenTestService {
|
||||||
|
|
||||||
|
private final GenTestRepository genTestRepository;
|
||||||
|
|
||||||
|
private final GenTestMapper genTestMapper;
|
||||||
|
|
||||||
|
public GenTestServiceImpl(GenTestRepository genTestRepository, GenTestMapper genTestMapper) {
|
||||||
|
this.genTestRepository = genTestRepository;
|
||||||
|
this.genTestMapper = genTestMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Cacheable
|
||||||
|
public Map<String,Object> queryAll(GenTestQueryCriteria criteria, Pageable pageable){
|
||||||
|
Page<GenTest> page = genTestRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||||
|
return PageUtil.toPage(page.map(genTestMapper::toDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Cacheable
|
||||||
|
public List<GenTestDto> queryAll(GenTestQueryCriteria criteria){
|
||||||
|
return genTestMapper.toDto(genTestRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Cacheable(key = "#p0")
|
||||||
|
public GenTestDto findById(Long id) {
|
||||||
|
GenTest genTest = genTestRepository.findById(id).orElseGet(GenTest::new);
|
||||||
|
ValidationUtil.isNull(genTest.getId(),"GenTest","id",id);
|
||||||
|
return genTestMapper.toDto(genTest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@CacheEvict(allEntries = true)
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public GenTestDto create(GenTest resources) {
|
||||||
|
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
||||||
|
resources.setId(snowflake.nextId());
|
||||||
|
return genTestMapper.toDto(genTestRepository.save(resources));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@CacheEvict(allEntries = true)
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void update(GenTest resources) {
|
||||||
|
GenTest genTest = genTestRepository.findById(resources.getId()).orElseGet(GenTest::new);
|
||||||
|
ValidationUtil.isNull( genTest.getId(),"GenTest","id",resources.getId());
|
||||||
|
genTest.copy(resources);
|
||||||
|
genTestRepository.save(genTest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@CacheEvict(allEntries = true)
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void delete(Long id) {
|
||||||
|
genTestRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@CacheEvict(allEntries = true)
|
||||||
|
public void deleteAll(Long[] ids) {
|
||||||
|
for (Long id : ids) {
|
||||||
|
genTestRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download(List<GenTestDto> all, HttpServletResponse response) throws IOException {
|
||||||
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
|
for (GenTestDto genTest : all) {
|
||||||
|
Map<String,Object> map = new LinkedHashMap<>();
|
||||||
|
map.put("名称", genTest.getName());
|
||||||
|
map.put("状态", genTest.getStatus());
|
||||||
|
map.put("日期", genTest.getDate());
|
||||||
|
map.put("创建日期", genTest.getCreateTime());
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
FileUtil.downloadExcel(list, response);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package me.zhengjie.gen.service.mapper;
|
||||||
|
|
||||||
|
import me.zhengjie.base.BaseMapper;
|
||||||
|
import me.zhengjie.gen.domain.GenTest;
|
||||||
|
import me.zhengjie.gen.service.dto.GenTestDto;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.ReportingPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zheng Jie
|
||||||
|
* @date 2019-11-25
|
||||||
|
*/
|
||||||
|
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||||
|
public interface GenTestMapper extends BaseMapper<GenTestDto, GenTest> {
|
||||||
|
|
||||||
|
}
|
|
@ -17,7 +17,7 @@ public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificat
|
||||||
/**
|
/**
|
||||||
* 根据 PID 查询
|
* 根据 PID 查询
|
||||||
* @param id pid
|
* @param id pid
|
||||||
* @return 、
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Dept> findByPid(Long id);
|
List<Dept> findByPid(Long id);
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @date ${date}
|
* @date ${date}
|
||||||
*/
|
*/
|
||||||
@Api(tags = "${className}管理")
|
@Api(tags = "${apiAlias}管理")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/${changeClassName}")
|
@RequestMapping("/api/${changeClassName}")
|
||||||
public class ${className}Controller {
|
public class ${className}Controller {
|
||||||
|
@ -38,24 +38,24 @@ public class ${className}Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@Log("查询${className}")
|
@Log("查询${apiAlias}")
|
||||||
@ApiOperation("查询${className}")
|
@ApiOperation("查询${apiAlias}")
|
||||||
@PreAuthorize("@el.check('${changeClassName}:list')")
|
@PreAuthorize("@el.check('${changeClassName}:list')")
|
||||||
public ResponseEntity get${className}s(${className}QueryCriteria criteria, Pageable pageable){
|
public ResponseEntity get${className}s(${className}QueryCriteria criteria, Pageable pageable){
|
||||||
return new ResponseEntity<>(${changeClassName}Service.queryAll(criteria,pageable),HttpStatus.OK);
|
return new ResponseEntity<>(${changeClassName}Service.queryAll(criteria,pageable),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@Log("新增${className}")
|
@Log("新增${apiAlias}")
|
||||||
@ApiOperation("新增${className}")
|
@ApiOperation("新增${apiAlias}")
|
||||||
@PreAuthorize("@el.check('${changeClassName}:add')")
|
@PreAuthorize("@el.check('${changeClassName}:add')")
|
||||||
public ResponseEntity create(@Validated @RequestBody ${className} resources){
|
public ResponseEntity create(@Validated @RequestBody ${className} resources){
|
||||||
return new ResponseEntity<>(${changeClassName}Service.create(resources),HttpStatus.CREATED);
|
return new ResponseEntity<>(${changeClassName}Service.create(resources),HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@Log("修改${className}")
|
@Log("修改${apiAlias}")
|
||||||
@ApiOperation("修改${className}")
|
@ApiOperation("修改${apiAlias}")
|
||||||
@PreAuthorize("@el.check('${changeClassName}:edit')")
|
@PreAuthorize("@el.check('${changeClassName}:edit')")
|
||||||
public ResponseEntity update(@Validated @RequestBody ${className} resources){
|
public ResponseEntity update(@Validated @RequestBody ${className} resources){
|
||||||
${changeClassName}Service.update(resources);
|
${changeClassName}Service.update(resources);
|
||||||
|
@ -63,16 +63,16 @@ public class ${className}Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping(value = "/{${pkChangeColName}}")
|
@DeleteMapping(value = "/{${pkChangeColName}}")
|
||||||
@Log("删除${className}")
|
@Log("删除${apiAlias}")
|
||||||
@ApiOperation("删除${className}")
|
@ApiOperation("删除${apiAlias}")
|
||||||
@PreAuthorize("@el.check('${changeClassName}:del')")
|
@PreAuthorize("@el.check('${changeClassName}:del')")
|
||||||
public ResponseEntity delete(@PathVariable ${pkColumnType} ${pkChangeColName}){
|
public ResponseEntity delete(@PathVariable ${pkColumnType} ${pkChangeColName}){
|
||||||
${changeClassName}Service.delete(${pkChangeColName});
|
${changeClassName}Service.delete(${pkChangeColName});
|
||||||
return new ResponseEntity(HttpStatus.OK);
|
return new ResponseEntity(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Log("多选删除${className}")
|
@Log("多选删除${apiAlias}")
|
||||||
@ApiOperation("多选删除${className}")
|
@ApiOperation("多选删除${apiAlias}")
|
||||||
@PreAuthorize("@el.check('${changeClassName}:del')")
|
@PreAuthorize("@el.check('${changeClassName}:del')")
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
public ResponseEntity deleteAll(@RequestBody ${pkColumnType}[] ids) {
|
public ResponseEntity deleteAll(@RequestBody ${pkColumnType}[] ids) {
|
||||||
|
|
|
@ -13,22 +13,21 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @date ${date}
|
* @date ${date}
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class ${className}DTO implements Serializable {
|
public class ${className}Dto implements Serializable {
|
||||||
<#if columns??>
|
<#if columns??>
|
||||||
<#list columns as column>
|
<#list columns as column>
|
||||||
|
|
||||||
<#if column.remark != ''>
|
<#if column.remark != ''>
|
||||||
// ${column.remark}
|
/** ${column.remark} */
|
||||||
</#if>
|
</#if>
|
||||||
<#if column.columnKey = 'PRI'>
|
<#if column.columnKey = 'PRI'>
|
||||||
<#if !auto && pkColumnType = 'Long'>
|
<#if !auto && pkColumnType = 'Long'>
|
||||||
// 处理精度丢失问题
|
/** 防止精度丢失 */
|
||||||
@JsonSerialize(using= ToStringSerializer.class)
|
@JsonSerialize(using= ToStringSerializer.class)
|
||||||
</#if>
|
</#if>
|
||||||
</#if>
|
</#if>
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class ${className} implements Serializable {
|
||||||
<#list columns as column>
|
<#list columns as column>
|
||||||
|
|
||||||
<#if column.remark != ''>
|
<#if column.remark != ''>
|
||||||
// ${column.remark}
|
/** ${column.remark} */
|
||||||
</#if>
|
</#if>
|
||||||
<#if column.columnKey = 'PRI'>
|
<#if column.columnKey = 'PRI'>
|
||||||
@Id
|
@Id
|
||||||
|
|
|
@ -2,7 +2,7 @@ package ${package}.service.mapper;
|
||||||
|
|
||||||
import me.zhengjie.base.BaseMapper;
|
import me.zhengjie.base.BaseMapper;
|
||||||
import ${package}.domain.${className};
|
import ${package}.domain.${className};
|
||||||
import ${package}.service.dto.${className}DTO;
|
import ${package}.service.dto.${className}Dto;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.ReportingPolicy;
|
import org.mapstruct.ReportingPolicy;
|
||||||
|
|
||||||
|
@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
|
||||||
* @date ${date}
|
* @date ${date}
|
||||||
*/
|
*/
|
||||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||||
public interface ${className}Mapper extends BaseMapper<${className}DTO, ${className}> {
|
public interface ${className}Mapper extends BaseMapper<${className}Dto, ${className}> {
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@ import java.sql.Timestamp;
|
||||||
<#if queryHasBigDecimal>
|
<#if queryHasBigDecimal>
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
</#if>
|
</#if>
|
||||||
<#if dateRanges??>
|
<#if betweens??>
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
</#if>
|
</#if>
|
||||||
<#if queryColumns??>
|
<#if queryColumns??>
|
||||||
|
@ -24,34 +24,35 @@ public class ${className}QueryCriteria{
|
||||||
<#list queryColumns as column>
|
<#list queryColumns as column>
|
||||||
|
|
||||||
<#if column.queryType = '='>
|
<#if column.queryType = '='>
|
||||||
// 精确
|
/** 精确 */
|
||||||
@Query
|
@Query
|
||||||
private ${column.columnType} ${column.changeColumnName};
|
private ${column.columnType} ${column.changeColumnName};
|
||||||
</#if>
|
</#if>
|
||||||
<#if column.queryType = 'Like'>
|
<#if column.queryType = 'Like'>
|
||||||
// 模糊
|
/** 模糊 */
|
||||||
@Query(type = Query.Type.INNER_LIKE)
|
@Query(type = Query.Type.INNER_LIKE)
|
||||||
private ${column.columnType} ${column.changeColumnName};
|
private ${column.columnType} ${column.changeColumnName};
|
||||||
</#if>
|
</#if>
|
||||||
<#if column.queryType = '!='>
|
<#if column.queryType = '!='>
|
||||||
// 不等于
|
/** 不等于 */
|
||||||
@Query(type = Query.Type.NOT_EQUAL)
|
@Query(type = Query.Type.NOT_EQUAL)
|
||||||
private ${column.columnType} ${column.changeColumnName};
|
private ${column.columnType} ${column.changeColumnName};
|
||||||
</#if>
|
</#if>
|
||||||
<#if column.queryType = '>='>
|
<#if column.queryType = '>='>
|
||||||
// 大于等于
|
/** 大于等于 */
|
||||||
@Query(type = Query.Type.GREATER_THAN)
|
@Query(type = Query.Type.GREATER_THAN)
|
||||||
private ${column.columnType} ${column.changeColumnName};
|
private ${column.columnType} ${column.changeColumnName};
|
||||||
</#if>
|
</#if>
|
||||||
<#if column.queryType = '<='>
|
<#if column.queryType = '<='>
|
||||||
// 小于等于
|
/** 小于等于 */
|
||||||
@Query(type = Query.Type.LESS_THAN)
|
@Query(type = Query.Type.LESS_THAN)
|
||||||
private ${column.columnType} ${column.changeColumnName};
|
private ${column.columnType} ${column.changeColumnName};
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
</#if>
|
</#if>
|
||||||
<#if dateRanges??>
|
<#if betweens??>
|
||||||
<#list dateRanges as column>
|
<#list betweens as column>
|
||||||
|
/** BETWEEN */
|
||||||
@Query(type = Query.Type.BETWEEN)
|
@Query(type = Query.Type.BETWEEN)
|
||||||
private List<${column.columnType}> createTime;
|
private List<${column.columnType}> createTime;
|
||||||
</#list>
|
</#list>
|
||||||
|
|
|
@ -12,7 +12,11 @@ public interface ${className}Repository extends JpaRepository<${className}, ${pk
|
||||||
<#if columns??>
|
<#if columns??>
|
||||||
<#list columns as column>
|
<#list columns as column>
|
||||||
<#if column.columnKey = 'UNI'>
|
<#if column.columnKey = 'UNI'>
|
||||||
|
/**
|
||||||
|
* 根据 ${column.capitalColumnName} 查询
|
||||||
|
* @param ${column.columnName} /
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
${className} findBy${column.capitalColumnName}(${column.columnType} ${column.columnName});
|
${className} findBy${column.capitalColumnName}(${column.columnType} ${column.columnName});
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
|
|
|
@ -17,7 +17,7 @@ public interface ${className}Service {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询数据分页
|
* 查询数据分页
|
||||||
* @param criteria 条件参数
|
* @param criteria 条件
|
||||||
* @param pageable 分页参数
|
* @param pageable 分页参数
|
||||||
* @return Map<String,Object>
|
* @return Map<String,Object>
|
||||||
*/
|
*/
|
||||||
|
@ -37,13 +37,36 @@ public interface ${className}Service {
|
||||||
*/
|
*/
|
||||||
${className}Dto findById(${pkColumnType} ${pkChangeColName});
|
${className}Dto findById(${pkColumnType} ${pkChangeColName});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建
|
||||||
|
* @param resources /
|
||||||
|
* @return ${className}Dto
|
||||||
|
*/
|
||||||
${className}Dto create(${className} resources);
|
${className}Dto create(${className} resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑
|
||||||
|
* @param resources /
|
||||||
|
*/
|
||||||
void update(${className} resources);
|
void update(${className} resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
* @param ${pkChangeColName} /
|
||||||
|
*/
|
||||||
void delete(${pkColumnType} ${pkChangeColName});
|
void delete(${pkColumnType} ${pkChangeColName});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多选删除
|
||||||
|
* @param ids /
|
||||||
|
*/
|
||||||
void deleteAll(${pkColumnType}[] ids);
|
void deleteAll(${pkColumnType}[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出数据
|
||||||
|
* @param all 待导出的数据
|
||||||
|
* @param response /
|
||||||
|
* @throws IOException /
|
||||||
|
*/
|
||||||
void download(List<${className}Dto> all, HttpServletResponse response) throws IOException;
|
void download(List<${className}Dto> all, HttpServletResponse response) throws IOException;
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@ import me.zhengjie.utils.ValidationUtil;
|
||||||
import me.zhengjie.utils.FileUtil;
|
import me.zhengjie.utils.FileUtil;
|
||||||
import ${package}.repository.${className}Repository;
|
import ${package}.repository.${className}Repository;
|
||||||
import ${package}.service.${className}Service;
|
import ${package}.service.${className}Service;
|
||||||
import ${package}.service.dto.${className}DTO;
|
import ${package}.service.dto.${className}Dto;
|
||||||
import ${package}.service.dto.${className}QueryCriteria;
|
import ${package}.service.dto.${className}QueryCriteria;
|
||||||
import ${package}.service.mapper.${className}Mapper;
|
import ${package}.service.mapper.${className}Mapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -68,13 +68,13 @@ public class ${className}ServiceImpl implements ${className}Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable
|
@Cacheable
|
||||||
public List<${className}DTO> queryAll(${className}QueryCriteria criteria){
|
public List<${className}Dto> queryAll(${className}QueryCriteria criteria){
|
||||||
return ${changeClassName}Mapper.toDto(${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
return ${changeClassName}Mapper.toDto(${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable(key = "#p0")
|
@Cacheable(key = "#p0")
|
||||||
public ${className}DTO findById(${pkColumnType} ${pkChangeColName}) {
|
public ${className}Dto findById(${pkColumnType} ${pkChangeColName}) {
|
||||||
${className} ${changeClassName} = ${changeClassName}Repository.findById(${pkChangeColName}).orElseGet(${className}::new);
|
${className} ${changeClassName} = ${changeClassName}Repository.findById(${pkChangeColName}).orElseGet(${className}::new);
|
||||||
ValidationUtil.isNull(${changeClassName}.get${pkCapitalColName}(),"${className}","${pkChangeColName}",${pkChangeColName});
|
ValidationUtil.isNull(${changeClassName}.get${pkCapitalColName}(),"${className}","${pkChangeColName}",${pkChangeColName});
|
||||||
return ${changeClassName}Mapper.toDto(${changeClassName});
|
return ${changeClassName}Mapper.toDto(${changeClassName});
|
||||||
|
@ -83,7 +83,7 @@ public class ${className}ServiceImpl implements ${className}Service {
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(allEntries = true)
|
@CacheEvict(allEntries = true)
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ${className}DTO create(${className} resources) {
|
public ${className}Dto create(${className} resources) {
|
||||||
<#if !auto && pkColumnType = 'Long'>
|
<#if !auto && pkColumnType = 'Long'>
|
||||||
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
||||||
resources.set${pkCapitalColName}(snowflake.nextId());
|
resources.set${pkCapitalColName}(snowflake.nextId());
|
||||||
|
@ -142,9 +142,9 @@ public class ${className}ServiceImpl implements ${className}Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(List<${className}DTO> all, HttpServletResponse response) throws IOException {
|
public void download(List<${className}Dto> all, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (${className}DTO ${changeClassName} : all) {
|
for (${className}Dto ${changeClassName} : all) {
|
||||||
Map<String,Object> map = new LinkedHashMap<>();
|
Map<String,Object> map = new LinkedHashMap<>();
|
||||||
<#list columns as column>
|
<#list columns as column>
|
||||||
<#if column.columnKey != 'PRI'>
|
<#if column.columnKey != 'PRI'>
|
||||||
|
|
|
@ -30,11 +30,4 @@ export function edit(data) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function download${className}(params) {
|
export default { add, edit, del, delAll }
|
||||||
return request({
|
|
||||||
url: 'api/${changeClassName}/download',
|
|
||||||
method: 'get',
|
|
||||||
params,
|
|
||||||
responseType: 'blob'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,152 +0,0 @@
|
||||||
<template>
|
|
||||||
<el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" :title="isAdd ? '新增' : '编辑'" width="500px">
|
|
||||||
<el-form ref="form" :model="form" <#if isNotNullColumns??>:rules="rules"</#if> size="small" label-width="80px">
|
|
||||||
<#if columns??>
|
|
||||||
<#list columns as column>
|
|
||||||
<#if column.formShow>
|
|
||||||
<el-form-item label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>" <#if column.istNotNull>prop="${column.changeColumnName}"</#if>>
|
|
||||||
<#if column.formType = 'Input'>
|
|
||||||
<el-input v-model="form.${column.changeColumnName}" style="width: 370px;"/>
|
|
||||||
<#elseif column.formType = 'Textarea'>
|
|
||||||
<el-input :rows="3" v-model="form.${column.changeColumnName}" type="textarea" style="width: 370px;"/>
|
|
||||||
<#elseif column.formType = 'Radio'>
|
|
||||||
<#if column.dictName??>
|
|
||||||
<el-radio v-for="item in dicts.${column.dictName}" :key="item.id" v-model="form.${column.changeColumnName}" :label="item.value">{{ item.label }}</el-radio>
|
|
||||||
<#else>
|
|
||||||
未设置字典,请手动设置 Radio
|
|
||||||
</#if>
|
|
||||||
<#elseif column.formType = 'Select'>
|
|
||||||
<#if column.dictName??>
|
|
||||||
<el-select v-model="form.${column.changeColumnName}" filterable placeholder="请选择">
|
|
||||||
<el-option
|
|
||||||
v-for="item in dicts.${column.dictName}"
|
|
||||||
:key="item.id"
|
|
||||||
:label="item.label"
|
|
||||||
:value="item.value"/>
|
|
||||||
</el-select>
|
|
||||||
<#else>
|
|
||||||
未设置字典,请手动设置 Select
|
|
||||||
</#if>
|
|
||||||
<#else>
|
|
||||||
<el-date-picker v-model="form.${column.changeColumnName}" type="datetime" style="width: 370px;"/>
|
|
||||||
</#if>
|
|
||||||
</el-form-item>
|
|
||||||
</#if>
|
|
||||||
</#list>
|
|
||||||
</#if>
|
|
||||||
</el-form>
|
|
||||||
<div slot="footer" class="dialog-footer">
|
|
||||||
<el-button type="text" @click="cancel">取消</el-button>
|
|
||||||
<el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
|
|
||||||
</div>
|
|
||||||
</el-dialog>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import { add, edit } from '@/api/${changeClassName}'
|
|
||||||
export default {
|
|
||||||
props: {
|
|
||||||
isAdd: {
|
|
||||||
type: Boolean,
|
|
||||||
required: true
|
|
||||||
}<#if hasDict>,
|
|
||||||
dicts: {
|
|
||||||
type: Object,
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
</#if>
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
loading: false, dialog: false,
|
|
||||||
form: {
|
|
||||||
<#if columns??>
|
|
||||||
<#list columns as column>
|
|
||||||
${column.changeColumnName}: ''<#if column_has_next>,</#if>
|
|
||||||
</#list>
|
|
||||||
</#if>
|
|
||||||
},
|
|
||||||
rules: {
|
|
||||||
<#if isNotNullColumns??>
|
|
||||||
<#list isNotNullColumns as column>
|
|
||||||
<#if column.istNotNull>
|
|
||||||
${column.changeColumnName}: [
|
|
||||||
{ required: true, message: 'please enter', trigger: 'blur' }
|
|
||||||
]<#if column_has_next>,</#if>
|
|
||||||
</#if>
|
|
||||||
</#list>
|
|
||||||
</#if>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
cancel() {
|
|
||||||
this.resetForm()
|
|
||||||
},
|
|
||||||
doSubmit() {
|
|
||||||
<#if isNotNullColumns??>
|
|
||||||
this.$refs['form'].validate((valid) => {
|
|
||||||
if (valid) {
|
|
||||||
this.loading = true
|
|
||||||
if (this.isAdd) {
|
|
||||||
this.doAdd()
|
|
||||||
} else this.doEdit()
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
<#else>
|
|
||||||
this.loading = true
|
|
||||||
if (this.isAdd) {
|
|
||||||
this.doAdd()
|
|
||||||
} else this.doEdit()
|
|
||||||
</#if>
|
|
||||||
},
|
|
||||||
doAdd() {
|
|
||||||
add(this.form).then(res => {
|
|
||||||
this.resetForm()
|
|
||||||
this.$notify({
|
|
||||||
title: '添加成功',
|
|
||||||
type: 'success',
|
|
||||||
duration: 2500
|
|
||||||
})
|
|
||||||
this.loading = false
|
|
||||||
this.$parent.init()
|
|
||||||
}).catch(err => {
|
|
||||||
this.loading = false
|
|
||||||
console.log(err.response.data.message)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
doEdit() {
|
|
||||||
edit(this.form).then(res => {
|
|
||||||
this.resetForm()
|
|
||||||
this.$notify({
|
|
||||||
title: '修改成功',
|
|
||||||
type: 'success',
|
|
||||||
duration: 2500
|
|
||||||
})
|
|
||||||
this.loading = false
|
|
||||||
this.$parent.init()
|
|
||||||
}).catch(err => {
|
|
||||||
this.loading = false
|
|
||||||
console.log(err.response.data.message)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
resetForm() {
|
|
||||||
this.dialog = false
|
|
||||||
this.$refs['form'].resetFields()
|
|
||||||
this.form = {
|
|
||||||
<#if columns??>
|
|
||||||
<#list columns as column>
|
|
||||||
${column.changeColumnName}: ''<#if column_has_next>,</#if>
|
|
||||||
</#list>
|
|
||||||
</#if>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
|
|
||||||
</style>
|
|
|
@ -5,65 +5,80 @@
|
||||||
<div class="head-container">
|
<div class="head-container">
|
||||||
<#if hasQuery>
|
<#if hasQuery>
|
||||||
<!-- 搜索 -->
|
<!-- 搜索 -->
|
||||||
<el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
|
<el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
|
||||||
<el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
|
<el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
|
||||||
<el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
|
<el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
|
||||||
</el-select>
|
</el-select>
|
||||||
<#if dateRanges??>
|
<#if betweens??>
|
||||||
<#list dateRanges as column>
|
<#list betweens as column>
|
||||||
<#if column.queryType = 'DateRange'>
|
<#if column.queryType = 'BetWeen'>
|
||||||
<el-date-picker
|
<el-date-picker
|
||||||
v-model="query.${column.changeColumnName}"
|
v-model="query.${column.changeColumnName}"
|
||||||
:default-time="['00:00:00','23:59:59']"
|
:default-time="['00:00:00','23:59:59']"
|
||||||
type="daterange"
|
type="daterange"
|
||||||
range-separator=":"
|
range-separator=":"
|
||||||
class="el-range-editor--small filter-item"
|
size="small"
|
||||||
style="height: 30.5px;width: 225px;"
|
class="date-item"
|
||||||
value-format="yyyy-MM-dd HH:mm:ss"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
||||||
start-placeholder="${column.changeColumnName}Start"
|
start-placeholder="${column.changeColumnName}Start"
|
||||||
end-placeholder="${column.changeColumnName}End"/>
|
end-placeholder="${column.changeColumnName}End"
|
||||||
|
/>
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
</#if>
|
</#if>
|
||||||
<el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
|
<el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
|
||||||
</#if>
|
</#if>
|
||||||
<!-- 新增 -->
|
<!-- 新增 -->
|
||||||
<div style="display: inline-block;margin: 0px 2px;">
|
<el-button v-permission="['admin','${changeClassName}:add']" class="filter-item" size="mini" type="primary" icon="el-icon-plus" @click="showAddFormDialog">新增</el-button>
|
||||||
<el-button
|
|
||||||
v-permission="['admin','${changeClassName}:add']"
|
|
||||||
class="filter-item"
|
|
||||||
size="mini"
|
|
||||||
type="primary"
|
|
||||||
icon="el-icon-plus"
|
|
||||||
@click="add">新增</el-button>
|
|
||||||
</div>
|
|
||||||
<!-- 导出 -->
|
<!-- 导出 -->
|
||||||
<div style="display: inline-block;">
|
<el-button :loading="downloadLoading" size="mini" class="filter-item" type="warning" icon="el-icon-download" @click="downloadMethod">导出</el-button>
|
||||||
<el-button
|
|
||||||
:loading="downloadLoading"
|
|
||||||
size="mini"
|
|
||||||
class="filter-item"
|
|
||||||
type="warning"
|
|
||||||
icon="el-icon-download"
|
|
||||||
@click="download">导出</el-button>
|
|
||||||
</div>
|
|
||||||
<!-- 多选删除 -->
|
<!-- 多选删除 -->
|
||||||
<div v-permission="['admin','${changeClassName}:del']" style="display: inline-block;">
|
<el-button v-permission="['admin','${changeClassName}:del']" :loading="delAllLoading" :disabled="data.length === 0 || $refs.table.selection.length === 0" class="filter-item" size="mini" type="danger" icon="el-icon-delete" @click="beforeDelAllMethod">删除</el-button>
|
||||||
<el-button
|
|
||||||
:loading="delAllLoading"
|
|
||||||
:disabled="data.length === 0 || $refs.table.selection.length === 0"
|
|
||||||
class="filter-item"
|
|
||||||
size="mini"
|
|
||||||
type="danger"
|
|
||||||
icon="el-icon-delete"
|
|
||||||
@click="open">删除</el-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!--表单组件-->
|
<!--表单组件-->
|
||||||
<eForm ref="form" :is-add="isAdd" <#if hasDict>:dicts="dict"</#if>/>
|
<el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" :title="getFormTitle()" width="500px">
|
||||||
|
<el-form ref="form" :model="form" <#if isNotNullColumns??>:rules="rules"</#if> size="small" label-width="80px">
|
||||||
|
<#if columns??>
|
||||||
|
<#list columns as column>
|
||||||
|
<#if column.formShow>
|
||||||
|
<el-form-item label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>" <#if column.istNotNull>prop="${column.changeColumnName}"</#if>>
|
||||||
|
<#if column.formType = 'Input'>
|
||||||
|
<el-input v-model="form.${column.changeColumnName}" style="width: 370px;" />
|
||||||
|
<#elseif column.formType = 'Textarea'>
|
||||||
|
<el-input :rows="3" v-model="form.${column.changeColumnName}" type="textarea" style="width: 370px;" />
|
||||||
|
<#elseif column.formType = 'Radio'>
|
||||||
|
<#if column.dictName??>
|
||||||
|
<el-radio v-for="item in dict.${column.dictName}" :key="item.id" v-model="form.${column.changeColumnName}" :label="item.value">{{ item.label }}</el-radio>
|
||||||
|
<#else>
|
||||||
|
未设置字典,请手动设置 Radio
|
||||||
|
</#if>
|
||||||
|
<#elseif column.formType = 'Select'>
|
||||||
|
<#if column.dictName??>
|
||||||
|
<el-select v-model="form.${column.changeColumnName}" filterable placeholder="请选择">
|
||||||
|
<el-option
|
||||||
|
v-for="item in dict.${column.dictName}"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value" />
|
||||||
|
</el-select>
|
||||||
|
<#else>
|
||||||
|
未设置字典,请手动设置 Select
|
||||||
|
</#if>
|
||||||
|
<#else>
|
||||||
|
<el-date-picker v-model="form.${column.changeColumnName}" type="datetime" style="width: 370px;" />
|
||||||
|
</#if>
|
||||||
|
</el-form-item>
|
||||||
|
</#if>
|
||||||
|
</#list>
|
||||||
|
</#if>
|
||||||
|
</el-form>
|
||||||
|
<div slot="footer" class="dialog-footer">
|
||||||
|
<el-button type="text" @click="cancel">取消</el-button>
|
||||||
|
<el-button :loading="loading" type="primary" @click="submitMethod">确认</el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
<!--表格渲染-->
|
<!--表格渲染-->
|
||||||
<el-table v-loading="loading" ref="table" :data="data" size="small" style="width: 100%;">
|
<el-table ref="table" v-loading="loading" :data="data" size="small" style="width: 100%;">
|
||||||
<el-table-column type="selection" width="55"/>
|
<el-table-column type="selection" width="55" />
|
||||||
<#if columns??>
|
<#if columns??>
|
||||||
<#list columns as column>
|
<#list columns as column>
|
||||||
<#if column.columnShow>
|
<#if column.columnShow>
|
||||||
|
@ -74,7 +89,7 @@
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<#elseif column.columnType != 'Timestamp'>
|
<#elseif column.columnType != 'Timestamp'>
|
||||||
<el-table-column prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>"/>
|
<el-table-column prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>" />
|
||||||
<#else>
|
<#else>
|
||||||
<el-table-column prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>">
|
<el-table-column prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
|
@ -87,18 +102,19 @@
|
||||||
</#if>
|
</#if>
|
||||||
<el-table-column v-if="checkPermission(['admin','${changeClassName}:edit','${changeClassName}:del'])" label="操作" width="150px" align="center">
|
<el-table-column v-if="checkPermission(['admin','${changeClassName}:edit','${changeClassName}:del'])" label="操作" width="150px" align="center">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button v-permission="['admin','${changeClassName}:edit']" size="mini" type="primary" icon="el-icon-edit" @click="edit(scope.row)"/>
|
<el-button v-permission="['admin','${changeClassName}:edit']" size="mini" type="primary" icon="el-icon-edit" @click="showEditFormDialog(scope.row)" />
|
||||||
<el-popover
|
<el-popover
|
||||||
v-permission="['admin','${changeClassName}:del']"
|
|
||||||
:ref="scope.row.${pkChangeColName}"
|
:ref="scope.row.${pkChangeColName}"
|
||||||
|
v-permission="['admin','${changeClassName}:del']"
|
||||||
placement="top"
|
placement="top"
|
||||||
width="180">
|
width="180"
|
||||||
|
>
|
||||||
<p>确定删除本条数据吗?</p>
|
<p>确定删除本条数据吗?</p>
|
||||||
<div style="text-align: right; margin: 0">
|
<div style="text-align: right; margin: 0">
|
||||||
<el-button size="mini" type="text" @click="$refs[scope.row.${pkChangeColName}].doClose()">取消</el-button>
|
<el-button size="mini" type="text" @click="$refs[scope.row.${pkChangeColName}].doClose()">取消</el-button>
|
||||||
<el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.${pkChangeColName})">确定</el-button>
|
<el-button :loading="delLoading" type="primary" size="mini" @click="delMethod(scope.row.${pkChangeColName})">确定</el-button>
|
||||||
</div>
|
</div>
|
||||||
<el-button slot="reference" type="danger" icon="el-icon-delete" size="mini"/>
|
<el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" />
|
||||||
</el-popover>
|
</el-popover>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
@ -110,32 +126,40 @@
|
||||||
style="margin-top: 8px;"
|
style="margin-top: 8px;"
|
||||||
layout="total, prev, pager, next, sizes"
|
layout="total, prev, pager, next, sizes"
|
||||||
@size-change="sizeChange"
|
@size-change="sizeChange"
|
||||||
@current-change="pageChange"/>
|
@current-change="pageChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import checkPermission from '@/utils/permission'
|
import crud from '@/mixins/crud'
|
||||||
import initData from '@/mixins/initData'
|
import crud${className} from '@/api/${changeClassName}'
|
||||||
import { del, download${className}, delAll } from '@/api/${changeClassName}'
|
|
||||||
<#if hasTimestamp>
|
|
||||||
import { parseTime, downloadFile } from '@/utils/index'
|
|
||||||
</#if>
|
|
||||||
import eForm from './form'
|
|
||||||
export default {
|
export default {
|
||||||
components: { eForm },
|
mixins: [crud],
|
||||||
mixins: [initData],
|
|
||||||
<#if hasDict>
|
<#if hasDict>
|
||||||
dicts: [<#if hasDict??><#list dicts as dict>'${dict}'<#if dict_has_next>, </#if></#list></#if>],
|
dicts: [<#if hasDict??><#list dicts as dict>'${dict}'<#if dict_has_next>, </#if></#list></#if>],
|
||||||
</#if>
|
</#if>
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
delLoading: false, delAllLoading: false,
|
title: '${apiAlias}',
|
||||||
<#if hasQuery>
|
crudMethod: { ...crud${className} },
|
||||||
|
form: { <#if columns??><#list columns as column>${column.changeColumnName}: null<#if column_has_next>, </#if></#list></#if> },
|
||||||
|
rules: {
|
||||||
|
<#if isNotNullColumns??>
|
||||||
|
<#list isNotNullColumns as column>
|
||||||
|
<#if column.istNotNull>
|
||||||
|
${column.changeColumnName}: [
|
||||||
|
{ required: true, message: '<#if column.remark != ''>${column.remark}</#if>不能为空', trigger: 'blur' }
|
||||||
|
]<#if column_has_next>,</#if>
|
||||||
|
</#if>
|
||||||
|
</#list>
|
||||||
|
</#if>
|
||||||
|
}<#if hasQuery>,
|
||||||
queryTypeOptions: [
|
queryTypeOptions: [
|
||||||
<#if queryColumns??>
|
<#if queryColumns??>
|
||||||
<#list queryColumns as column>
|
<#list queryColumns as column>
|
||||||
<#if column.queryType != 'DateRange'>
|
<#if column.queryType != 'BetWeen'>
|
||||||
{ key: '${column.changeColumnName}', display_name: '<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>' }<#if column_has_next>,</#if>
|
{ key: '${column.changeColumnName}', display_name: '<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>' }<#if column_has_next>,</#if>
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
|
@ -150,10 +174,7 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
<#if hasTimestamp>
|
// 获取数据前设置好接口地址
|
||||||
parseTime,
|
|
||||||
</#if>
|
|
||||||
checkPermission,
|
|
||||||
beforeInit() {
|
beforeInit() {
|
||||||
this.url = 'api/${changeClassName}'
|
this.url = 'api/${changeClassName}'
|
||||||
const sort = '${pkChangeColName},desc'
|
const sort = '${pkChangeColName},desc'
|
||||||
|
@ -163,93 +184,8 @@ export default {
|
||||||
const type = query.type
|
const type = query.type
|
||||||
const value = query.value
|
const value = query.value
|
||||||
if (type && value) { this.params[type] = value }
|
if (type && value) { this.params[type] = value }
|
||||||
<#if dateRanges??>
|
|
||||||
<#list dateRanges as column>
|
|
||||||
<#if column.queryType = 'DateRange'>
|
|
||||||
if (query.${column.changeColumnName}) {
|
|
||||||
this.params['${column.changeColumnName}Start'] = query.${column.changeColumnName}[0]
|
|
||||||
this.params['${column.changeColumnName}End'] = query.${column.changeColumnName}[1]
|
|
||||||
}
|
|
||||||
</#if>
|
|
||||||
</#list>
|
|
||||||
</#if>
|
|
||||||
</#if>
|
</#if>
|
||||||
return true
|
return true
|
||||||
},
|
|
||||||
subDelete(${pkChangeColName}) {
|
|
||||||
this.delLoading = true
|
|
||||||
del(${pkChangeColName}).then(res => {
|
|
||||||
this.delLoading = false
|
|
||||||
this.$refs[${pkChangeColName}].doClose()
|
|
||||||
this.dleChangePage()
|
|
||||||
this.init()
|
|
||||||
this.$notify({
|
|
||||||
title: '删除成功',
|
|
||||||
type: 'success',
|
|
||||||
duration: 2500
|
|
||||||
})
|
|
||||||
}).catch(err => {
|
|
||||||
this.delLoading = false
|
|
||||||
this.$refs[${pkChangeColName}].doClose()
|
|
||||||
console.log(err.response.data.message)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
add() {
|
|
||||||
this.isAdd = true
|
|
||||||
this.$refs.form.dialog = true
|
|
||||||
},
|
|
||||||
edit(data) {
|
|
||||||
this.isAdd = false
|
|
||||||
const _this = this.$refs.form
|
|
||||||
_this.form = {
|
|
||||||
<#if columns??>
|
|
||||||
<#list columns as column>
|
|
||||||
${column.changeColumnName}: data.${column.changeColumnName}<#if column_has_next>,</#if>
|
|
||||||
</#list>
|
|
||||||
</#if>
|
|
||||||
}
|
|
||||||
_this.dialog = true
|
|
||||||
},
|
|
||||||
// 导出
|
|
||||||
download() {
|
|
||||||
this.beforeInit()
|
|
||||||
this.downloadLoading = true
|
|
||||||
download${className}(this.params).then(result => {
|
|
||||||
downloadFile(result, '${className}列表', 'xlsx')
|
|
||||||
this.downloadLoading = false
|
|
||||||
}).catch(() => {
|
|
||||||
this.downloadLoading = false
|
|
||||||
})
|
|
||||||
},
|
|
||||||
doDelete() {
|
|
||||||
this.delAllLoading = true
|
|
||||||
const data = this.$refs.table.selection
|
|
||||||
const ids = []
|
|
||||||
for (let i = 0; i < data.length; i++) {
|
|
||||||
ids.push(data[i].id)
|
|
||||||
}
|
|
||||||
delAll(ids).then(res => {
|
|
||||||
this.delAllLoading = false
|
|
||||||
this.init()
|
|
||||||
this.dleChangePage(ids.length)
|
|
||||||
this.$notify({
|
|
||||||
title: '删除成功',
|
|
||||||
type: 'success',
|
|
||||||
duration: 2500
|
|
||||||
})
|
|
||||||
}).catch(err => {
|
|
||||||
this.delAllLoading = false
|
|
||||||
console.log(err.response.data.message)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
open() {
|
|
||||||
this.$confirm('你确定删除选中的数据吗?', '提示', {
|
|
||||||
confirmButtonText: '确定',
|
|
||||||
cancelButtonText: '取消',
|
|
||||||
type: 'warning'
|
|
||||||
}).then(() => {
|
|
||||||
this.doDelete()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue