添加mybatisplus父模块,调整依赖关系,增加P结尾的mp代码生成器
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
package co.yixiang;
|
||||
|
||||
import co.yixiang.modules.activity.service.YxStoreCouponUserService;
|
||||
import co.yixiang.annotation.AnonymousAccess;
|
||||
import co.yixiang.utils.SpringContextHolder;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
@ -44,7 +44,7 @@ public class RedisServiceImpl implements RedisService {
|
||||
continue;
|
||||
}
|
||||
DataType dataType = redisTemplate.type(s.toString());
|
||||
if(!dataType.code().equals("string")) continue;
|
||||
if(!"string".equals(dataType.code())) continue;
|
||||
RedisVo redisVo = new RedisVo(s.toString(),redisTemplate.opsForValue().get(s.toString()).toString());
|
||||
redisVos.add(redisVo);
|
||||
}
|
||||
|
@ -109,6 +109,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.antMatchers("/swagger-resources/**").permitAll()
|
||||
.antMatchers("/webjars/**").permitAll()
|
||||
.antMatchers("/*/api-docs").permitAll()
|
||||
.antMatchers("/v2/api-docs-ext").permitAll()
|
||||
//.antMatchers("/api/wxmp/**").permitAll()
|
||||
|
||||
// 文件
|
||||
.antMatchers("/avatar/**").permitAll()
|
||||
.antMatchers("/file/**").permitAll()
|
||||
|
@ -122,7 +122,12 @@ public class AuthController {
|
||||
// 几位数运算,默认是两位
|
||||
captcha.setLen(2);
|
||||
// 获取运算的结果
|
||||
String result = captcha.text();
|
||||
String result ="";
|
||||
try {
|
||||
result = new Double(Double.parseDouble(captcha.text())).intValue()+"";
|
||||
}catch (Exception e){
|
||||
result = captcha.text();
|
||||
}
|
||||
String uuid = properties.getCodeKey() + IdUtil.simpleUUID();
|
||||
// 保存
|
||||
redisUtils.set(uuid, result, expiration, TimeUnit.MINUTES);
|
||||
|
@ -1,10 +1,12 @@
|
||||
#配置数据源
|
||||
spring:
|
||||
application:
|
||||
name: yshop-system
|
||||
datasource:
|
||||
druid:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||
url: jdbc:log4jdbc:mysql://localhost:3306/yxshop?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
|
||||
url: jdbc:log4jdbc:mysql://localhost:3306/yxshop?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: root
|
||||
password: root
|
||||
|
||||
@ -77,14 +79,25 @@ generator:
|
||||
swagger:
|
||||
enabled: true
|
||||
title: yshop商城管理后台API
|
||||
serverUrl: http://localhost:8000
|
||||
version: 2.0
|
||||
serverUrl:
|
||||
version: 2.1
|
||||
|
||||
# 文件存储路径
|
||||
file:
|
||||
path: D:\yshop\file\
|
||||
avatar: D:\yshop\avatar\
|
||||
path: D:\upload\file\
|
||||
avatar: D:\upload\avatar\
|
||||
# 文件大小 /M
|
||||
maxSize: 100
|
||||
avatarMaxSize: 5
|
||||
localUrl: http://localhost:8000
|
||||
localUrl:
|
||||
|
||||
mybatis-plus:
|
||||
check-config-location: true
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: auto
|
||||
logic-delete-value: 1
|
||||
logic-not-delete-value: 0
|
||||
mapper-locations: classpath*:mapper/**/*Mapper.xml
|
||||
|
@ -1,12 +1,14 @@
|
||||
#配置数据源
|
||||
spring:
|
||||
application:
|
||||
name: yshop-system
|
||||
datasource:
|
||||
druid:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||
url: jdbc:log4jdbc:mysql://localhost:3306/yshop?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
|
||||
username: yshop
|
||||
password:
|
||||
url: jdbc:log4jdbc:mysql://localhost:3366/yxshop?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
|
||||
username: root
|
||||
password: root
|
||||
|
||||
# 初始化配置
|
||||
initial-size: 3
|
||||
@ -47,7 +49,7 @@ spring:
|
||||
database: 0
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
password:
|
||||
password: root
|
||||
#连接超时时间
|
||||
timeout: 5000
|
||||
|
||||
@ -80,14 +82,29 @@ generator:
|
||||
swagger:
|
||||
enabled: true
|
||||
title: yshop商城管理后台API
|
||||
serverUrl: http://localhost:8000
|
||||
serverUrl: http://127.0.0.1:8000
|
||||
version: 2.1
|
||||
|
||||
# 文件存储路径
|
||||
file:
|
||||
path: /home/yshop/file/
|
||||
avatar: /home/yshop/avatar/
|
||||
path: D:\upload\file\
|
||||
avatar: D:\upload\avatar\
|
||||
# 文件大小 /M
|
||||
maxSize: 100
|
||||
avatarMaxSize: 5
|
||||
localUrl:
|
||||
localUrl: https://cdn.jidanguo10.com
|
||||
mybatis-plus:
|
||||
check-config-location: true
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: id_worker
|
||||
logic-delete-value: 1
|
||||
logic-not-delete-value: 0
|
||||
mapper-locations: classpath*:mapper/**/*Mapper.xml
|
||||
|
||||
yshop:
|
||||
hApi: https://127.0.0.1:8000
|
||||
wechatCode: http://127.0.0.1:8000/upload/qrcode_for_gh_2ac8f422a79f_258.jpg
|
||||
miniAppID:
|
||||
|
@ -58,4 +58,12 @@ yshop:
|
||||
enable: true
|
||||
appId: 1607734
|
||||
appKey: 81f43a2e-f504-45c4-9b54-2637d59f8190
|
||||
apiUrl: http://127.0.0.1:8009/api
|
||||
apiUrl: https://zapi.jidanguo10.com/api
|
||||
|
||||
|
||||
# PageHelper分页插件
|
||||
pagehelper:
|
||||
helperDialect: mysql
|
||||
reasonable: true
|
||||
supportMethodsArguments: true
|
||||
params: count=countSql
|
@ -3,7 +3,7 @@
|
||||
<contextName>yshop</contextName>
|
||||
<property name="log.charset" value="utf-8" />
|
||||
<property name="log.pattern" value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %gray(%msg%n)" />
|
||||
|
||||
<property name="log.path" value="logs/yshop_system"/>
|
||||
<!--输出到控制台-->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
@ -12,9 +12,60 @@
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- Log file debug output -->
|
||||
<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/debug.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- Log file error output -->
|
||||
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- Log file info output -->
|
||||
<appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/info.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>INFO</level>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!--普通日志输出到控制台-->
|
||||
<root level="info">
|
||||
<appender-ref ref="console" />
|
||||
<appender-ref ref="debug"/>
|
||||
<appender-ref ref="error"/>
|
||||
<appender-ref ref="info"/>
|
||||
</root>
|
||||
|
||||
<!--监控sql日志输出 -->
|
||||
|
@ -0,0 +1,77 @@
|
||||
package ${package}.rest;
|
||||
import java.util.Arrays;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import co.yixiang.aop.log.Log;
|
||||
import ${package}.domain.${className};
|
||||
import ${package}.service.${className}Service;
|
||||
import ${package}.service.dto.${className}QueryCriteria;
|
||||
import ${package}.service.dto.${className}Dto;
|
||||
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 ${author}
|
||||
* @date ${date}
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Api(tags = "${apiAlias}管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/${changeClassName}")
|
||||
public class ${className}Controller {
|
||||
|
||||
private final ${className}Service ${changeClassName}Service;
|
||||
private final IGenerator generator;
|
||||
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('admin','${changeClassName}:list')")
|
||||
public void download(HttpServletResponse response, ${className}QueryCriteria criteria) throws IOException {
|
||||
${changeClassName}Service.download(generator.convert(${changeClassName}Service.queryAll(criteria), ${className}Dto.class), response);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Log("查询${apiAlias}")
|
||||
@ApiOperation("查询${apiAlias}")
|
||||
@PreAuthorize("@el.check('admin','${changeClassName}:list')")
|
||||
public ResponseEntity<Object> get${className}s(${className}QueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(${changeClassName}Service.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增${apiAlias}")
|
||||
@ApiOperation("新增${apiAlias}")
|
||||
@PreAuthorize("@el.check('admin','${changeClassName}:add')")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody ${className} resources){
|
||||
return new ResponseEntity<>(${changeClassName}Service.save(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改${apiAlias}")
|
||||
@ApiOperation("修改${apiAlias}")
|
||||
@PreAuthorize("@el.check('admin','${changeClassName}:edit')")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody ${className} resources){
|
||||
${changeClassName}Service.updateById(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除${apiAlias}")
|
||||
@ApiOperation("删除${apiAlias}")
|
||||
@PreAuthorize("@el.check('admin','${changeClassName}:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> deleteAll(@RequestBody ${pkColumnType}[] ids) {
|
||||
Arrays.asList(ids).forEach(id->{
|
||||
${changeClassName}Service.removeById(id);
|
||||
});
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package ${package}.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
<#if hasTimestamp>
|
||||
import java.sql.Timestamp;
|
||||
</#if>
|
||||
<#if hasBigDecimal>
|
||||
import java.math.BigDecimal;
|
||||
</#if>
|
||||
import java.io.Serializable;
|
||||
<#if !auto && pkColumnType == 'Long'>
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
</#if>
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
*/
|
||||
@Data
|
||||
public class ${className}Dto implements Serializable {
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
|
||||
<#if column.remark != ''>
|
||||
/** ${column.remark} */
|
||||
</#if>
|
||||
<#if column.columnKey = 'PRI'>
|
||||
<#if !auto && pkColumnType = 'Long'>
|
||||
/** 防止精度丢失 */
|
||||
@JsonSerialize(using= ToStringSerializer.class)
|
||||
</#if>
|
||||
</#if>
|
||||
<#if column.changeColumnName != 'delFlag'>
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package ${package}.domain;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import lombok.Data;
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import javax.persistence.*;
|
||||
<#if isNotNullColumns??>
|
||||
import javax.validation.constraints.*;
|
||||
</#if>
|
||||
<#if hasDateAnnotation>
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import org.hibernate.annotations.*;
|
||||
</#if>
|
||||
<#if hasTimestamp>
|
||||
import java.sql.Timestamp;
|
||||
</#if>
|
||||
<#if hasBigDecimal>
|
||||
import java.math.BigDecimal;
|
||||
</#if>
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="${tableName}")
|
||||
public class ${className} implements Serializable {
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
|
||||
<#if column.remark != ''>
|
||||
/** ${column.remark} */
|
||||
</#if>
|
||||
<#if column.columnKey = 'PRI'>
|
||||
@Id
|
||||
<#if auto>
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
</#if>
|
||||
</#if>
|
||||
@Column(name = "${column.columnName}"<#if column.columnKey = 'UNI'>,unique = true</#if><#if column.istNotNull && column.columnKey != 'PRI'>,nullable = false</#if>)
|
||||
<#if column.istNotNull && column.columnKey != 'PRI'>
|
||||
<#if column.columnType = 'String'>
|
||||
@NotBlank
|
||||
<#else>
|
||||
@NotNull
|
||||
</#if>
|
||||
</#if>
|
||||
<#if column.dateAnnotation??>
|
||||
<#if column.dateAnnotation = 'CreationTimestamp'>
|
||||
@CreationTimestamp
|
||||
<#else>
|
||||
@UpdateTimestamp
|
||||
</#if>
|
||||
</#if>
|
||||
<#if column.changeColumnName = 'updateTime'|| column.changeColumnName = 'updateDate'>
|
||||
@TableField(fill= FieldFill.INSERT_UPDATE)
|
||||
</#if>
|
||||
<#if column.changeColumnName = 'createTime' || column.changeColumnName = 'createDate'>
|
||||
@TableField(fill= FieldFill.INSERT)
|
||||
</#if>
|
||||
<#if column.changeColumnName = 'delFlag'>
|
||||
@TableLogic
|
||||
@TableField(fill=FieldFill.INSERT_UPDATE)
|
||||
private Boolean ${column.changeColumnName};
|
||||
<#else>
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
public void copy(${className} source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package ${package}.service.mapper;
|
||||
|
||||
import co.yixiang.common.mapper.CoreMapper;
|
||||
import ${package}.domain.${className};
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
*/
|
||||
@Repository
|
||||
@Mapper
|
||||
public interface ${className}Mapper extends CoreMapper<${className}> {
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package ${package}.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
<#if queryHasTimestamp>
|
||||
import java.sql.Timestamp;
|
||||
</#if>
|
||||
<#if queryHasBigDecimal>
|
||||
import java.math.BigDecimal;
|
||||
</#if>
|
||||
<#if betweens??>
|
||||
import java.util.List;
|
||||
</#if>
|
||||
<#if queryColumns??>
|
||||
import co.yixiang.annotation.Query;
|
||||
</#if>
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
*/
|
||||
@Data
|
||||
public class ${className}QueryCriteria{
|
||||
<#if queryColumns??>
|
||||
<#list queryColumns as column>
|
||||
|
||||
<#if column.queryType = '='>
|
||||
/** 精确 */
|
||||
@Query
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
<#if column.queryType = 'Like'>
|
||||
/** 模糊 */
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
<#if column.queryType = '!='>
|
||||
/** 不等于 */
|
||||
@Query(type = Query.Type.NOT_EQUAL)
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
<#if column.queryType = 'NotNull'>
|
||||
/** 不为空 */
|
||||
@Query(type = Query.Type.NOT_NULL)
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
<#if column.queryType = '>='>
|
||||
/** 大于等于 */
|
||||
@Query(type = Query.Type.GREATER_THAN)
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
<#if column.queryType = '<='>
|
||||
/** 小于等于 */
|
||||
@Query(type = Query.Type.LESS_THAN)
|
||||
private ${column.columnType} ${column.changeColumnName};
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
<#if betweens??>
|
||||
<#list betweens as column>
|
||||
/** BETWEEN */
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<${column.columnType}> createTime;
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package ${package}.service.impl;
|
||||
|
||||
import ${package}.domain.${className};
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
<#if column.columnKey = 'UNI'>
|
||||
<#if column_index = 1>
|
||||
import co.yixiang.exception.EntityExistException;
|
||||
</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
import co.yixiang.common.service.impl.BaseServiceImpl;
|
||||
import lombok.AllArgsConstructor;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import co.yixiang.common.utils.QueryHelpPlus;
|
||||
import co.yixiang.utils.ValidationUtil;
|
||||
import co.yixiang.utils.FileUtil;
|
||||
import ${package}.service.${className}Service;
|
||||
import ${package}.service.dto.${className}Dto;
|
||||
import ${package}.service.dto.${className}QueryCriteria;
|
||||
import ${package}.service.mapper.${className}Mapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
<#if !auto && pkColumnType = 'Long'>
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
</#if>
|
||||
<#if !auto && pkColumnType = 'String'>
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
</#if>
|
||||
// 默认不使用缓存
|
||||
//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 co.yixiang.utils.PageUtil;
|
||||
import co.yixiang.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 ${author}
|
||||
* @date ${date}
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
//@CacheConfig(cacheNames = "${changeClassName}")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class ${className}ServiceImpl extends BaseServiceImpl<${className}Mapper, ${className}> implements ${className}Service {
|
||||
|
||||
private final IGenerator generator;
|
||||
|
||||
@Override
|
||||
//@Cacheable
|
||||
public Map<String, Object> queryAll(${className}QueryCriteria criteria, Pageable pageable) {
|
||||
getPage(pageable);
|
||||
PageInfo<${className}> page = new PageInfo<>(queryAll(criteria));
|
||||
Map<String, Object> map = new LinkedHashMap<>(2);
|
||||
map.put("content", generator.convert(page.getList(), ${className}Dto.class));
|
||||
map.put("totalElements", page.getTotal());
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
//@Cacheable
|
||||
public List<${className}> queryAll(${className}QueryCriteria criteria){
|
||||
return baseMapper.selectList(QueryHelpPlus.getPredicate(${className}.class, criteria));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void download(List<${className}Dto> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (${className}Dto ${changeClassName} : all) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
<#list columns as column>
|
||||
<#if column.columnKey != 'PRI'>
|
||||
<#if column.remark != ''>
|
||||
map.put("${column.remark}", ${changeClassName}.get${column.capitalColumnName}());
|
||||
<#else>
|
||||
map.put(" ${column.changeColumnName}", ${changeClassName}.get${column.capitalColumnName}());
|
||||
</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package ${package}.service;
|
||||
import co.yixiang.common.service.BaseService;
|
||||
import ${package}.domain.${className};
|
||||
import ${package}.service.dto.${className}Dto;
|
||||
import ${package}.service.dto.${className}QueryCriteria;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
*/
|
||||
public interface ${className}Service extends BaseService<${className}>{
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(${className}QueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<${className}Dto>
|
||||
*/
|
||||
List<${className}> queryAll(${className}QueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param all 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<${className}Dto> all, HttpServletResponse response) throws IOException;
|
||||
}
|
@ -61,6 +61,15 @@
|
||||
<#else>
|
||||
未设置字典,请手动设置 Select
|
||||
</#if>
|
||||
<#elseif column.formType = 'Imges'>
|
||||
<MaterialList
|
||||
v-model="${column.changeColumnName}Arr"
|
||||
style="width: 915px;"
|
||||
type="image"
|
||||
:num="1"
|
||||
:width="150"
|
||||
:height="150"
|
||||
/>
|
||||
<#else>
|
||||
<el-date-picker v-model="form.${column.changeColumnName}" type="datetime" style="width: 370px;" />
|
||||
</#if>
|
||||
@ -78,25 +87,33 @@
|
||||
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
|
||||
<el-table-column type="selection" width="55" />
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
<#if column.columnShow>
|
||||
<#if column.dictName??>
|
||||
<#list columns as column>
|
||||
<#if column.columnShow>
|
||||
<#if column.dictName??>
|
||||
<el-table-column v-if="columns.visible('${column.changeColumnName}')" prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>">
|
||||
<template slot-scope="scope">
|
||||
{{ dict.label.${column.dictName}[scope.row.${column.changeColumnName}] }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<#elseif column.columnType != 'Timestamp'>
|
||||
<#elseif column.formType = 'Imges'>
|
||||
<el-table-column v-if="columns.visible('${column.changeColumnName}')" prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>">
|
||||
<template slot-scope="scope">
|
||||
<a :href="scope.row.${column.changeColumnName}" style="color: #42b983" target="_blank">
|
||||
<img :src="scope.row.${column.changeColumnName}" alt="点击打开" class="table-img" />
|
||||
</a>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<#elseif column.columnType != 'Timestamp'>
|
||||
<el-table-column v-if="columns.visible('${column.changeColumnName}')" prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>" />
|
||||
<#else>
|
||||
<#else>
|
||||
<el-table-column v-if="columns.visible('${column.changeColumnName}')" prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ parseTime(scope.row.${column.changeColumnName}) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
<el-table-column v-permission="['admin','${changeClassName}:edit','${changeClassName}:del']" label="操作" width="150px" align="center">
|
||||
<template slot-scope="scope">
|
||||
@ -120,19 +137,21 @@ import rrOperation from '@crud/RR.operation'
|
||||
import crudOperation from '@crud/CRUD.operation'
|
||||
import udOperation from '@crud/UD.operation'
|
||||
import pagination from '@crud/Pagination'
|
||||
<#if hasImages??>import MaterialList from "@/components/material";</#if>
|
||||
|
||||
// crud交由presenter持有
|
||||
const defaultCrud = CRUD({ title: '${apiAlias}', url: 'api/${changeClassName}', sort: '${pkChangeColName},desc', crudMethod: { ...crud${className} }})
|
||||
const defaultForm = { <#if columns??><#list columns as column>${column.changeColumnName}: null<#if column_has_next>, </#if></#list></#if> }
|
||||
export default {
|
||||
name: '${className}',
|
||||
components: { pagination, crudOperation, rrOperation, udOperation },
|
||||
components: { pagination, crudOperation, rrOperation, udOperation <#if hasImages??>,MaterialList</#if>},
|
||||
mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
|
||||
<#if hasDict>
|
||||
dicts: [<#if hasDict??><#list dicts as dict>'${dict}'<#if dict_has_next>, </#if></#list></#if>],
|
||||
</#if>
|
||||
data() {
|
||||
return {
|
||||
<#if columns??><#list columns as column><#if column.formShow><#if column.formType = 'Imges'>${column.changeColumnName}Arr:[],</#if></#if></#list></#if>
|
||||
permission: {
|
||||
add: ['admin', '${changeClassName}:add'],
|
||||
edit: ['admin', '${changeClassName}:edit'],
|
||||
@ -161,6 +180,21 @@ export default {
|
||||
</#if>
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
<#if column.formShow>
|
||||
<#if column.formType = 'Imges'>
|
||||
"${column.changeColumnName}Arr":function(val) {
|
||||
if (val) {
|
||||
this.form.${column.changeColumnName} = val.join(",");
|
||||
}
|
||||
},
|
||||
</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
},
|
||||
methods: {
|
||||
// 获取数据前设置好接口地址
|
||||
[CRUD.HOOK.beforeRefresh]() {
|
||||
@ -168,14 +202,52 @@ export default {
|
||||
const query = this.query
|
||||
if (query.type && query.value) {
|
||||
this.crud.params[query.type] = query.value
|
||||
}else{
|
||||
<#if queryColumns??>
|
||||
<#list queryColumns as column>
|
||||
delete this.crud.params.${column.changeColumnName}
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
||||
</#if>
|
||||
return true
|
||||
}
|
||||
}, // 新增与编辑前做的操作
|
||||
[CRUD.HOOK.afterToCU](crud, form) {
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
<#if column.formShow>
|
||||
<#if column.formType = 'Imges'>
|
||||
if (form.${column.changeColumnName} && form.id) {
|
||||
this.${column.changeColumnName}Arr = form.${column.changeColumnName}.split(",");
|
||||
}else{
|
||||
this.${column.changeColumnName}Arr=[]
|
||||
}
|
||||
</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
<#if hasImages??>
|
||||
.table-img {
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
background: #ccc;
|
||||
color: #fff;
|
||||
white-space: nowrap;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
vertical-align: middle;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
}
|
||||
</#if>
|
||||
</style>
|
||||
|
Reference in New Issue
Block a user