43 changed files with 1282 additions and 25 deletions
@ -0,0 +1,21 @@ |
|||
package com.qs.serve.modules.exl.common; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2023/8/15 |
|||
*/ |
|||
public interface ExlConst { |
|||
|
|||
String TABLE_NAME_PRE = "exd_"; |
|||
String TABLE_COMMENT_PRE = "excel数据-"; |
|||
|
|||
String DATE_TYPE = "date"; |
|||
String TYPE_INT = "int"; |
|||
String TYPE_MONEY = "money"; |
|||
String TYPE_STRING = "string"; |
|||
|
|||
String PRE_COLUMN_START = "START--"; |
|||
|
|||
String PRE_COLUMN_END = "END--"; |
|||
|
|||
} |
@ -0,0 +1,61 @@ |
|||
package com.qs.serve.modules.exl.common; |
|||
|
|||
import org.apache.ibatis.session.SqlSession; |
|||
import org.mybatis.spring.SqlSessionTemplate; |
|||
import org.mybatis.spring.SqlSessionUtils; |
|||
|
|||
import java.sql.PreparedStatement; |
|||
import java.sql.SQLException; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2023/8/14 |
|||
*/ |
|||
public class QsSqlSessionUtil { |
|||
|
|||
/** |
|||
* 获取sqlSession |
|||
* @return |
|||
*/ |
|||
public static SqlSession getSqlSession(SqlSessionTemplate sqlSessionTemplate){ |
|||
return SqlSessionUtils.getSqlSession(sqlSessionTemplate.getSqlSessionFactory(), |
|||
sqlSessionTemplate.getExecutorType(), sqlSessionTemplate.getPersistenceExceptionTranslator()); |
|||
} |
|||
|
|||
/** |
|||
* 关闭sqlSession |
|||
* @param session |
|||
*/ |
|||
public static void closeSqlSession(SqlSession session,SqlSessionTemplate sqlSessionTemplate) { |
|||
SqlSessionUtils.closeSqlSession(session, sqlSessionTemplate.getSqlSessionFactory()); |
|||
} |
|||
|
|||
/** |
|||
* 执行sql |
|||
* @param sql |
|||
* @param sqlSessionTemplate |
|||
* @return |
|||
*/ |
|||
public static boolean executeSql(String sql,SqlSessionTemplate sqlSessionTemplate){ |
|||
PreparedStatement pst = null; |
|||
SqlSession session = getSqlSession(sqlSessionTemplate); |
|||
try { |
|||
pst = session.getConnection().prepareStatement(sql); |
|||
pst.execute(); |
|||
return true; |
|||
} catch (SQLException e) { |
|||
e.printStackTrace(); |
|||
}finally { |
|||
if(pst!=null){ |
|||
try { |
|||
pst.close(); |
|||
} catch (SQLException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
closeSqlSession(session,sqlSessionTemplate); |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,44 @@ |
|||
package com.qs.serve.modules.exl.common; |
|||
|
|||
import com.qs.serve.modules.exl.entity.ExlColumnConf; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2023/8/14 |
|||
*/ |
|||
public class TableCreateSqlUtil { |
|||
|
|||
public static final Map<String,String> MYSQL_DATA_MAP = new HashMap<>(); |
|||
static { |
|||
MYSQL_DATA_MAP.put("int","bigint"); |
|||
MYSQL_DATA_MAP.put("string","varchar(300)"); |
|||
MYSQL_DATA_MAP.put("date","date"); |
|||
MYSQL_DATA_MAP.put("money","decimal(11, 2)"); |
|||
MYSQL_DATA_MAP.put("datetime","datetime"); |
|||
} |
|||
|
|||
public static final String COLUMN_NULL = " null "; |
|||
public static final String COLUMN_NOT_NULL = " not null "; |
|||
public static final String COLUMN_COMMENT = "COMMENT"; |
|||
|
|||
public static String createMysqlTableSql(String tableName,String tableRemark, List<ExlColumnConf> columnList){ |
|||
StringBuffer result = new StringBuffer("CREATE TABLE `"+tableName+"` ("); |
|||
result.append(" `union_row_id` varchar(255) NOT NULL AUTO_INCREMENT COMMENT 'union_row_id',"); |
|||
for (ExlColumnConf column : columnList) { |
|||
String columnType = MYSQL_DATA_MAP.get(column.getColumnType())==null?column.getColumnType():MYSQL_DATA_MAP.get(column.getColumnType()); |
|||
String nullValue = column.getNotNullFlag().equals(1) ? COLUMN_NOT_NULL:COLUMN_NULL; |
|||
result.append("`"+column.getColumnName()+"` "+ |
|||
columnType + |
|||
nullValue + |
|||
COLUMN_COMMENT + " '"+ |
|||
column.getColumnHeader()+"',"); |
|||
} |
|||
result.append(" PRIMARY KEY (`union_row_id`) USING BTREE "); |
|||
return result.append(") COMMENT = '"+tableRemark+"' ").toString(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,204 @@ |
|||
package com.qs.serve.modules.exl.controller; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.qs.serve.common.model.annotation.SysLog; |
|||
import com.qs.serve.common.model.dto.PageVo; |
|||
import com.qs.serve.common.model.dto.R; |
|||
import com.qs.serve.common.model.enums.BizType; |
|||
import com.qs.serve.common.model.enums.SystemModule; |
|||
import com.qs.serve.common.util.PageUtil; |
|||
import com.qs.serve.common.util.CopierUtil; |
|||
import com.qs.serve.common.util.StringUtils; |
|||
import com.qs.serve.common.util.WordUtil; |
|||
import com.qs.serve.modules.exl.common.ExlConst; |
|||
import com.qs.serve.modules.exl.common.QsSqlSessionUtil; |
|||
import com.qs.serve.modules.exl.common.TableCreateSqlUtil; |
|||
import com.qs.serve.modules.exl.entity.ExlColumnConf; |
|||
import com.qs.serve.modules.exl.entity.dto.ExlQueryFieldDto; |
|||
import com.qs.serve.modules.exl.entity.dto.ExlTableBo; |
|||
import com.qs.serve.modules.exl.service.ExlColumnConfService; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.ibatis.session.SqlSession; |
|||
import org.mybatis.spring.SqlSessionTemplate; |
|||
import org.mybatis.spring.SqlSessionUtils; |
|||
import org.springframework.security.access.prepost.PreAuthorize; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import com.qs.serve.modules.exl.entity.ExlTableConf; |
|||
import com.qs.serve.modules.exl.service.ExlTableConfService; |
|||
|
|||
import javax.validation.Valid; |
|||
import java.time.LocalDateTime; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* 动态Excel表 表配置 |
|||
* @author YenHex |
|||
* @since 2023-08-11 |
|||
*/ |
|||
@Slf4j |
|||
@AllArgsConstructor |
|||
@RestController |
|||
@RequestMapping("exl/tableConf") |
|||
public class ExlTableConfController { |
|||
|
|||
private SqlSessionTemplate sqlSessionTemplate; |
|||
private ExlTableConfService exlTableConfService; |
|||
private ExlColumnConfService exlColumnConfService; |
|||
|
|||
/** |
|||
* 列表 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
//@GetMapping("/list")
|
|||
public R<List<ExlTableConf>> getList(ExlTableConf param){ |
|||
LambdaQueryWrapper<ExlTableConf> lqw = new LambdaQueryWrapper<>(param); |
|||
List<ExlTableConf> list = exlTableConfService.list(lqw); |
|||
return R.ok(list); |
|||
} |
|||
/** |
|||
* 翻页 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@GetMapping("/page") |
|||
public R<PageVo<ExlTableConf>> getPage(ExlTableConf param){ |
|||
LambdaQueryWrapper<ExlTableConf> lqw = new LambdaQueryWrapper<>(param); |
|||
PageUtil.startPage(); |
|||
List<ExlTableConf> list = exlTableConfService.list(lqw); |
|||
return R.byPageHelperList(list); |
|||
} |
|||
|
|||
/** |
|||
* ID查询 |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
@GetMapping("/getById/{id}") |
|||
@SysLog(module = SystemModule.Excel, title = "表配置", biz = BizType.QUERY) |
|||
public R<ExlTableConf> getById(@PathVariable("id") String id){ |
|||
ExlTableConf exlTableConf = exlTableConfService.getById(id); |
|||
LambdaQueryWrapper<ExlColumnConf> columnLqw = new LambdaQueryWrapper<>(); |
|||
columnLqw.eq(ExlColumnConf::getTableConfId,id); |
|||
List<ExlColumnConf> columnConfList = exlColumnConfService.list(columnLqw); |
|||
exlTableConf.setColumnList(columnConfList); |
|||
//组装查询参数列表
|
|||
List<ExlColumnConf> queryColumn = columnConfList.stream() |
|||
.filter(a->a.getConditionFlag().equals(1)).collect(Collectors.toList()); |
|||
List<ExlQueryFieldDto> queryFieldList = new ArrayList<>(); |
|||
for (ExlColumnConf columnConf : queryColumn) { |
|||
if(columnConf.getColumnType().contains(ExlConst.DATE_TYPE)){ |
|||
ExlQueryFieldDto startDto = new ExlQueryFieldDto(); |
|||
startDto.setField(ExlConst.PRE_COLUMN_START + columnConf.getColumnName()); |
|||
startDto.setType(columnConf.getColumnType()); |
|||
startDto.setLabel(columnConf.getColumnHeader()); |
|||
queryFieldList.add(startDto); |
|||
ExlQueryFieldDto fieldDto = new ExlQueryFieldDto(); |
|||
fieldDto.setField(ExlConst.PRE_COLUMN_END + columnConf.getColumnName()); |
|||
fieldDto.setType(columnConf.getColumnType()); |
|||
fieldDto.setLabel(columnConf.getColumnHeader()); |
|||
queryFieldList.add(fieldDto); |
|||
}else { |
|||
ExlQueryFieldDto fieldDto = new ExlQueryFieldDto(); |
|||
fieldDto.setField(columnConf.getColumnName()); |
|||
fieldDto.setType(columnConf.getColumnType()); |
|||
fieldDto.setLabel(columnConf.getColumnHeader()); |
|||
queryFieldList.add(fieldDto); |
|||
} |
|||
} |
|||
exlTableConf.setQueryList(queryFieldList); |
|||
return R.ok(exlTableConf); |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 更新 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@PostMapping("/updateById") |
|||
@SysLog(module = SystemModule.Excel, title = "表配置", biz = BizType.UPDATE) |
|||
public R<?> updateById(@RequestBody @Valid ExlTableBo param){ |
|||
if(param.getId()==null){ |
|||
return R.error("id is null"); |
|||
} |
|||
ExlTableConf tableConf = exlTableConfService.modify(param); |
|||
return R.ok(tableConf); |
|||
} |
|||
|
|||
/** |
|||
* 新增 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@PostMapping("/save") |
|||
@SysLog(module = SystemModule.Excel, title = "表配置", biz = BizType.INSERT) |
|||
public R<?> save(@RequestBody @Valid ExlTableBo param){ |
|||
if(param.getId()!=null){ |
|||
return R.error("id should be null"); |
|||
} |
|||
ExlTableConf tableConf = exlTableConfService.modify(param); |
|||
return R.ok(tableConf); |
|||
} |
|||
|
|||
/** |
|||
* 启用配置 |
|||
* @param tableId |
|||
* @return |
|||
*/ |
|||
@PostMapping("/enable/{tableId}") |
|||
@SysLog(module = SystemModule.Excel, title = "表配置", biz = BizType.INSERT) |
|||
public R<?> enable(@PathVariable("tableId") String tableId){ |
|||
ExlTableConf tableConf = exlTableConfService.getById(tableId); |
|||
LambdaQueryWrapper<ExlColumnConf> columnLqw = new LambdaQueryWrapper<>(); |
|||
columnLqw.eq(ExlColumnConf::getTableConfId,tableId); |
|||
List<ExlColumnConf> columnConfList = exlColumnConfService.list(columnLqw); |
|||
if(tableConf.getEnableFlag().equals(0)){ |
|||
String sql = TableCreateSqlUtil.createMysqlTableSql( |
|||
ExlConst.TABLE_NAME_PRE + tableConf.getTableName(), |
|||
ExlConst.TABLE_COMMENT_PRE + tableConf.getExcelTitle(), |
|||
columnConfList); |
|||
log.debug(sql); |
|||
boolean result = QsSqlSessionUtil.executeSql(sql,sqlSessionTemplate); |
|||
if(result){ |
|||
tableConf.setEnableFlag(1); |
|||
tableConf.setEnableTime(LocalDateTime.now()); |
|||
exlTableConfService.updateById(tableConf); |
|||
}else { |
|||
log.error("[ID:{}]创建表格失败,建表语句:{}",tableId,sql); |
|||
return R.error("创建失败"); |
|||
} |
|||
} |
|||
return R.ok(); |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 删除 |
|||
* @param ids |
|||
* @return |
|||
*/ |
|||
@DeleteMapping("/deleteById/{ids}") |
|||
@SysLog(module = SystemModule.Excel, title = "表配置", biz = BizType.DELETE) |
|||
public R<?> deleteById(@PathVariable("ids") String ids){ |
|||
List<Long> idsLong = StringUtils.splitIdLong(ids); |
|||
LambdaQueryWrapper<ExlTableConf> lqw = new LambdaQueryWrapper<>(); |
|||
lqw.in(ExlTableConf::getId,ids); |
|||
lqw.eq(ExlTableConf::getEnableFlag,1); |
|||
Long count = exlTableConfService.count(lqw); |
|||
if(count>0){ |
|||
return R.error("已启用的配置不可删除"); |
|||
} |
|||
boolean result = exlTableConfService.removeByIds(idsLong); |
|||
return R.isTrue(result); |
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,121 @@ |
|||
package com.qs.serve.modules.exl.controller; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.qs.serve.common.model.annotation.SysLog; |
|||
import com.qs.serve.common.model.dto.PageVo; |
|||
import com.qs.serve.common.model.dto.R; |
|||
import com.qs.serve.common.model.enums.BizType; |
|||
import com.qs.serve.common.model.enums.SystemModule; |
|||
import com.qs.serve.common.util.PageUtil; |
|||
import com.qs.serve.common.util.StringUtils; |
|||
import com.qs.serve.modules.exl.common.ExlConst; |
|||
import com.qs.serve.modules.exl.entity.ExlColumnConf; |
|||
import com.qs.serve.modules.exl.entity.ExlTableConf; |
|||
import com.qs.serve.modules.exl.entity.dto.ExlConditionDto; |
|||
import com.qs.serve.modules.exl.entity.dto.ExlQueryFieldDto; |
|||
import com.qs.serve.modules.exl.entity.dto.ExlTableBo; |
|||
import com.qs.serve.modules.exl.mapper.ExlTableConfMapper; |
|||
import com.qs.serve.modules.exl.service.ExlColumnConfService; |
|||
import com.qs.serve.modules.exl.service.ExlTableConfService; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.validation.Valid; |
|||
import java.time.LocalDateTime; |
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* 动态Excel表 表配置 |
|||
* @author YenHex |
|||
* @since 2023-08-11 |
|||
*/ |
|||
@Slf4j |
|||
@AllArgsConstructor |
|||
@RestController |
|||
@RequestMapping("exl/tableData") |
|||
public class ExlTableDataController { |
|||
|
|||
private ExlTableConfService exlTableConfService; |
|||
private ExlColumnConfService exlColumnConfService; |
|||
|
|||
private ExlTableConfMapper exlTableConfMapper; |
|||
|
|||
/** |
|||
* test |
|||
* @return |
|||
*/ |
|||
@GetMapping("/page/{tableConfigId}") |
|||
public R<?> test(@PathVariable("tableConfigId") Long tableConfigId,@RequestParam Map<String,String> map){ |
|||
// table
|
|||
ExlTableConf tableConf = exlTableConfService.getById(tableConfigId); |
|||
// columns
|
|||
LambdaQueryWrapper<ExlColumnConf> columnLqw = new LambdaQueryWrapper<>(); |
|||
columnLqw.eq(ExlColumnConf::getTableConfId,tableConfigId); |
|||
List<ExlColumnConf> columnList = exlColumnConfService.list(columnLqw); |
|||
// condition
|
|||
List<ExlConditionDto> ge_conditions = new ArrayList<>(); |
|||
List<ExlConditionDto> le_conditions = new ArrayList<>(); |
|||
List<ExlConditionDto> eq_conditions = new ArrayList<>(); |
|||
List<ExlConditionDto> like_conditions = new ArrayList<>(); |
|||
if(!map.isEmpty()){ |
|||
for (String columnName : map.keySet()) { |
|||
String searchValue = map.get(columnName); |
|||
if(columnName.contains(ExlConst.PRE_COLUMN_START)){ |
|||
String orgColumn = columnName.replace(ExlConst.PRE_COLUMN_START,"").trim(); |
|||
ExlConditionDto conditionDto = new ExlConditionDto(orgColumn,searchValue); |
|||
ge_conditions.add(conditionDto); |
|||
}else if (columnName.contains(ExlConst.PRE_COLUMN_END)){ |
|||
String orgColumn = columnName.replace(ExlConst.PRE_COLUMN_END,"").trim(); |
|||
ExlConditionDto conditionDto = new ExlConditionDto(orgColumn,searchValue); |
|||
le_conditions.add(conditionDto); |
|||
}else { |
|||
for (ExlColumnConf columnConf : columnList) { |
|||
if(columnConf.getColumnName().equals(columnName)){ |
|||
ExlConditionDto conditionDto = new ExlConditionDto(columnName,searchValue); |
|||
if (columnConf.getColumnType().equals(ExlConst.TYPE_INT)){ |
|||
eq_conditions.add(conditionDto); |
|||
}else if (columnConf.getColumnType().equals(ExlConst.TYPE_STRING)){ |
|||
like_conditions.add(conditionDto); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
// page
|
|||
Integer pageSize = PageUtil.getPageSize(); |
|||
Integer startRow = PageUtil.getStartRow(); |
|||
// query
|
|||
Map<String,Object> queryMap = new HashMap<>(10); |
|||
queryMap.put("startRow",startRow); |
|||
queryMap.put("pageSize",pageSize); |
|||
queryMap.put("leList",le_conditions); |
|||
queryMap.put("geList",ge_conditions); |
|||
queryMap.put("eqList",eq_conditions); |
|||
queryMap.put("likeList",like_conditions); |
|||
String targetTableName = ExlConst.TABLE_NAME_PRE + tableConf.getTableName(); |
|||
return R.ok(exlTableConfMapper.listData(targetTableName,queryMap)); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 新增 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@PostMapping("/batchSave/{tableConfigId}") |
|||
public R<?> batchSave(@RequestBody List<Object> param){ |
|||
for (Object obj : param) { |
|||
|
|||
} |
|||
return R.ok(param); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
@ -0,0 +1,111 @@ |
|||
package com.qs.serve.modules.exl.entity; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
import java.time.LocalDateTime; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
|
|||
import javax.validation.constraints.NotNull; |
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 行配置 实体类 |
|||
* @author YenHex |
|||
* @since 2023-08-14 |
|||
*/ |
|||
@Data |
|||
@TableName("exl_column_conf") |
|||
public class ExlColumnConf implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** id */ |
|||
@JsonIgnore |
|||
@TableId(type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
/** 非必传 */ |
|||
@JsonIgnore |
|||
private Long tableConfId; |
|||
|
|||
/** 列名 */ |
|||
@NotBlank(message = "列名不能为空") |
|||
@Length(max = 255,message = "列名长度不能超过255字") |
|||
private String columnName; |
|||
|
|||
/** excel头部 */ |
|||
@NotBlank(message = "excel头部不能为空") |
|||
@Length(max = 255,message = "excel头部长度不能超过255字") |
|||
private String columnHeader; |
|||
|
|||
/** 数据类型:string;int;money;date;datetime; */ |
|||
@Length(max = 20,message = "数据类型:string;int;money;date;datetime;长度不能超过255字") |
|||
private String columnType; |
|||
|
|||
//string-like;int-eq;date-between;datetime-between
|
|||
/** 作为查询条件标识 */ |
|||
private Integer conditionFlag; |
|||
|
|||
/** 空值标识 */ |
|||
private Integer notNullFlag; |
|||
|
|||
/** 空值标识 */ |
|||
private Integer keyFlag; |
|||
|
|||
/** 创建时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private LocalDateTime createTime; |
|||
|
|||
/** 最后更新时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
@TableField(fill = FieldFill.UPDATE) |
|||
private LocalDateTime updateTime; |
|||
|
|||
/** 所属租户 */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private String tenantId; |
|||
|
|||
/** 创建人 */ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private String createBy; |
|||
|
|||
/** 更新人 */ |
|||
@TableField(fill = FieldFill.UPDATE) |
|||
private String updateBy; |
|||
|
|||
/** 逻辑删除标记(0:显示;1:隐藏) */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private String delFlag; |
|||
|
|||
|
|||
public static ExlColumnConf toNewObject(ExlColumnConf source){ |
|||
ExlColumnConf columnConf = new ExlColumnConf(); |
|||
columnConf.setId(source.getId()); |
|||
columnConf.setColumnName(source.getColumnName()); |
|||
columnConf.setColumnHeader(source.getColumnHeader()); |
|||
columnConf.setColumnType(source.getColumnType()); |
|||
columnConf.setConditionFlag(source.getConditionFlag()); |
|||
columnConf.setCreateTime(source.getCreateTime()); |
|||
columnConf.setUpdateTime(source.getUpdateTime()); |
|||
columnConf.setTenantId(source.getTenantId()); |
|||
columnConf.setCreateBy(source.getCreateBy()); |
|||
columnConf.setUpdateBy(source.getUpdateBy()); |
|||
columnConf.setDelFlag(source.getDelFlag()); |
|||
return columnConf; |
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,105 @@ |
|||
package com.qs.serve.modules.exl.entity; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
import java.time.LocalDateTime; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
|
|||
import javax.validation.constraints.NotNull; |
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 数据源配置 实体类 |
|||
* @author YenHex |
|||
* @since 2023-08-11 |
|||
*/ |
|||
@Data |
|||
@TableName("exl_ds_conf") |
|||
public class ExlDsConf implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** id */ |
|||
@TableId(type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
/** 启用 */ |
|||
@NotNull(message = "启用不能为空") |
|||
private Integer enable; |
|||
|
|||
/** 用户名 */ |
|||
@NotBlank(message = "用户名不能为空") |
|||
@Length(max = 255,message = "用户名长度不能超过255字") |
|||
private String username; |
|||
|
|||
/** 密码 */ |
|||
@NotBlank(message = "密码不能为空") |
|||
@Length(max = 255,message = "密码长度不能超过255字") |
|||
private String password; |
|||
|
|||
/** url */ |
|||
@Length(max = 255,message = "url长度不能超过255字") |
|||
private String url; |
|||
|
|||
/** 备注 */ |
|||
@Length(max = 255,message = "备注长度不能超过255字") |
|||
private String remark; |
|||
|
|||
/** 创建时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private LocalDateTime createTime; |
|||
|
|||
/** 最后更新时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
@TableField(fill = FieldFill.UPDATE) |
|||
private LocalDateTime updateTime; |
|||
|
|||
/** 所属租户 */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private String tenantId; |
|||
|
|||
/** 创建人 */ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private String createBy; |
|||
|
|||
/** 更新人 */ |
|||
@TableField(fill = FieldFill.UPDATE) |
|||
private String updateBy; |
|||
|
|||
/** 逻辑删除标记(0:显示;1:隐藏) */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private String delFlag; |
|||
|
|||
|
|||
public static ExlDsConf toNewObject(ExlDsConf source){ |
|||
ExlDsConf dsConf = new ExlDsConf(); |
|||
dsConf.setId(source.getId()); |
|||
dsConf.setEnable(source.getEnable()); |
|||
dsConf.setUsername(source.getUsername()); |
|||
dsConf.setPassword(source.getPassword()); |
|||
dsConf.setUrl(source.getUrl()); |
|||
dsConf.setRemark(source.getRemark()); |
|||
dsConf.setCreateTime(source.getCreateTime()); |
|||
dsConf.setUpdateTime(source.getUpdateTime()); |
|||
dsConf.setTenantId(source.getTenantId()); |
|||
dsConf.setCreateBy(source.getCreateBy()); |
|||
dsConf.setUpdateBy(source.getUpdateBy()); |
|||
dsConf.setDelFlag(source.getDelFlag()); |
|||
return dsConf; |
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,115 @@ |
|||
package com.qs.serve.modules.exl.entity; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
import java.time.LocalDateTime; |
|||
import java.util.List; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
|
|||
import javax.validation.constraints.NotNull; |
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 表配置 实体类 |
|||
* @author YenHex |
|||
* @since 2023-08-11 |
|||
*/ |
|||
@Data |
|||
@TableName("exl_table_conf") |
|||
public class ExlTableConf implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** id */ |
|||
@TableId(type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
/** 表名 */ |
|||
@NotBlank(message = "表名不能为空") |
|||
@Length(max = 255,message = "表名长度不能超过255字") |
|||
private String tableName; |
|||
|
|||
/** excel标题 */ |
|||
@NotBlank(message = "excel标题不能为空") |
|||
@Length(max = 255,message = "excel标题长度不能超过255字") |
|||
private String excelTitle; |
|||
|
|||
/** 备注 */ |
|||
@Length(max = 255,message = "备注长度不能超过255字") |
|||
private String remark; |
|||
|
|||
/** 启用标识 (0/1) */ |
|||
private Integer enableFlag; |
|||
|
|||
/** 启用时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
private LocalDateTime enableTime; |
|||
|
|||
/** 创建时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private LocalDateTime createTime; |
|||
|
|||
/** 最后更新时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
@TableField(fill = FieldFill.UPDATE) |
|||
private LocalDateTime updateTime; |
|||
|
|||
/** 所属租户 */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private String tenantId; |
|||
|
|||
/** 创建人 */ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private String createBy; |
|||
|
|||
/** 更新人 */ |
|||
@TableField(fill = FieldFill.UPDATE) |
|||
private String updateBy; |
|||
|
|||
/** 逻辑删除标记(0:显示;1:隐藏) */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private String delFlag; |
|||
|
|||
/** |
|||
* 列配置的列表 |
|||
*/ |
|||
@TableField(exist = false) |
|||
private List<ExlColumnConf> columnList; |
|||
|
|||
/** |
|||
* 查询参数列表 |
|||
*/ |
|||
@TableField(exist = false) |
|||
private List<?> queryList; |
|||
|
|||
public static ExlTableConf toNewObject(ExlTableConf source){ |
|||
ExlTableConf tableConf = new ExlTableConf(); |
|||
tableConf.setId(source.getId()); |
|||
tableConf.setTableName(source.getTableName()); |
|||
tableConf.setExcelTitle(source.getExcelTitle()); |
|||
tableConf.setRemark(source.getRemark()); |
|||
tableConf.setCreateTime(source.getCreateTime()); |
|||
tableConf.setUpdateTime(source.getUpdateTime()); |
|||
tableConf.setTenantId(source.getTenantId()); |
|||
tableConf.setCreateBy(source.getCreateBy()); |
|||
tableConf.setUpdateBy(source.getUpdateBy()); |
|||
tableConf.setDelFlag(source.getDelFlag()); |
|||
return tableConf; |
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,18 @@ |
|||
package com.qs.serve.modules.exl.entity.dto; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2023/8/15 |
|||
*/ |
|||
@Data |
|||
@AllArgsConstructor |
|||
public class ExlConditionDto { |
|||
|
|||
String column; |
|||
|
|||
String value; |
|||
|
|||
} |
@ -0,0 +1,24 @@ |
|||
package com.qs.serve.modules.exl.entity.dto; |
|||
|
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2023/8/14 |
|||
*/ |
|||
@Data |
|||
public class ExlQueryFieldDto { |
|||
|
|||
/** 字段名 */ |
|||
private String field; |
|||
|
|||
/** 数据类型 */ |
|||
private String type; |
|||
|
|||
/** 显示标签 */ |
|||
private String label; |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package com.qs.serve.modules.exl.entity.dto; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.qs.serve.modules.exl.entity.ExlColumnConf; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2023/8/14 |
|||
*/ |
|||
@Data |
|||
public class ExlTableBo { |
|||
|
|||
/** id(修改时参数) */ |
|||
@TableId(type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
/** 表名 */ |
|||
@NotBlank(message = "表名不能为空") |
|||
@Length(max = 255,message = "表名长度不能超过255字") |
|||
private String tableName; |
|||
|
|||
/** excel标题 */ |
|||
@NotBlank(message = "excel标题不能为空") |
|||
@Length(max = 255,message = "excel标题长度不能超过255字") |
|||
private String excelTitle; |
|||
|
|||
/** 备注 */ |
|||
@Length(max = 255,message = "备注长度不能超过255字") |
|||
private String remark; |
|||
|
|||
private List<ExlColumnConf> columnList; |
|||
|
|||
} |
@ -0,0 +1,14 @@ |
|||
package com.qs.serve.modules.exl.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.qs.serve.modules.exl.entity.ExlColumnConf; |
|||
|
|||
/** |
|||
* 行配置 Mapper |
|||
* @author YenHex |
|||
* @date 2023-08-14 |
|||
*/ |
|||
public interface ExlColumnConfMapper extends BaseMapper<ExlColumnConf> { |
|||
|
|||
} |
|||
|
@ -0,0 +1,14 @@ |
|||
package com.qs.serve.modules.exl.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.qs.serve.modules.exl.entity.ExlDsConf; |
|||
|
|||
/** |
|||
* 数据源配置 Mapper |
|||
* @author YenHex |
|||
* @date 2023-08-11 |
|||
*/ |
|||
public interface ExlDsConfMapper extends BaseMapper<ExlDsConf> { |
|||
|
|||
} |
|||
|
@ -0,0 +1,23 @@ |
|||
package com.qs.serve.modules.exl.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.qs.serve.modules.exl.entity.ExlTableConf; |
|||
import org.apache.ibatis.annotations.Param; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 表配置 Mapper |
|||
* @author YenHex |
|||
* @date 2023-08-11 |
|||
*/ |
|||
public interface ExlTableConfMapper extends BaseMapper<ExlTableConf> { |
|||
|
|||
|
|||
@InterceptorIgnore(tenantLine = "1") |
|||
List<Map<String,Object>> listData(@Param("tableName") String tableName,@Param("query")Map<String,Object> query); |
|||
|
|||
} |
|||
|
@ -0,0 +1,14 @@ |
|||
package com.qs.serve.modules.exl.service; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.qs.serve.modules.exl.entity.ExlColumnConf; |
|||
|
|||
/** |
|||
* 行配置 服务接口 |
|||
* @author YenHex |
|||
* @date 2023-08-14 |
|||
*/ |
|||
public interface ExlColumnConfService extends IService<ExlColumnConf> { |
|||
|
|||
} |
|||
|
@ -0,0 +1,22 @@ |
|||
package com.qs.serve.modules.exl.service; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.qs.serve.modules.exl.entity.ExlTableConf; |
|||
import com.qs.serve.modules.exl.entity.dto.ExlTableBo; |
|||
|
|||
/** |
|||
* 表配置 服务接口 |
|||
* @author YenHex |
|||
* @date 2023-08-11 |
|||
*/ |
|||
public interface ExlTableConfService extends IService<ExlTableConf> { |
|||
|
|||
/** |
|||
* 编辑 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
ExlTableConf modify(ExlTableBo param); |
|||
|
|||
} |
|||
|
@ -0,0 +1,22 @@ |
|||
package com.qs.serve.modules.exl.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
import com.qs.serve.modules.exl.entity.ExlColumnConf; |
|||
import com.qs.serve.modules.exl.service.ExlColumnConfService; |
|||
import com.qs.serve.modules.exl.mapper.ExlColumnConfMapper; |
|||
|
|||
/** |
|||
* 行配置 服务实现类 |
|||
* @author YenHex |
|||
* @since 2023-08-14 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@AllArgsConstructor |
|||
public class ExlColumnConfServiceImpl extends ServiceImpl<ExlColumnConfMapper,ExlColumnConf> implements ExlColumnConfService { |
|||
|
|||
} |
|||
|
@ -0,0 +1,79 @@ |
|||
package com.qs.serve.modules.exl.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.qs.serve.common.util.Assert; |
|||
import com.qs.serve.modules.exl.common.ExlConst; |
|||
import com.qs.serve.modules.exl.entity.ExlColumnConf; |
|||
import com.qs.serve.modules.exl.entity.dto.ExlTableBo; |
|||
import com.qs.serve.modules.exl.service.ExlColumnConfService; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
import com.qs.serve.modules.exl.entity.ExlTableConf; |
|||
import com.qs.serve.modules.exl.service.ExlTableConfService; |
|||
import com.qs.serve.modules.exl.mapper.ExlTableConfMapper; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 表配置 服务实现类 |
|||
* @author YenHex |
|||
* @since 2023-08-11 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@AllArgsConstructor |
|||
public class ExlTableConfServiceImpl extends ServiceImpl<ExlTableConfMapper,ExlTableConf> implements ExlTableConfService { |
|||
|
|||
private final ExlColumnConfService columnConfService; |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public ExlTableConf modify(ExlTableBo param) { |
|||
ExlTableConf tableConf = new ExlTableConf(); |
|||
if(param.getId()==null){ |
|||
//save
|
|||
tableConf.setTableName(param.getTableName()); |
|||
tableConf.setExcelTitle(param.getExcelTitle()); |
|||
tableConf.setRemark(param.getRemark()); |
|||
this.save(tableConf); |
|||
final Long tableId = tableConf.getId(); |
|||
List<ExlColumnConf> columnList = param.getColumnList(); |
|||
columnList.forEach(a->{ |
|||
a.setTableConfId(tableId); |
|||
a.setId(null); |
|||
}); |
|||
columnConfService.saveBatch(columnList); |
|||
return tableConf; |
|||
}else { |
|||
//update
|
|||
final Long tableId = param.getId(); |
|||
ExlTableConf dbData = this.getById(tableId); |
|||
if(dbData.getEnableFlag().equals(1)){ |
|||
Assert.throwEx("已启用的配置不可修改"); |
|||
} |
|||
tableConf.setId(tableId); |
|||
tableConf.setTableName(param.getTableName()); |
|||
tableConf.setExcelTitle(param.getExcelTitle()); |
|||
tableConf.setRemark(param.getRemark()); |
|||
this.updateById(tableConf); |
|||
LambdaQueryWrapper<ExlColumnConf> columnLqw = new LambdaQueryWrapper<>(); |
|||
columnLqw.eq(ExlColumnConf::getTableConfId,param.getId()); |
|||
columnConfService.remove(columnLqw); |
|||
List<ExlColumnConf> columnList = param.getColumnList(); |
|||
columnList.forEach(a->{ |
|||
a.setTableConfId(tableId); |
|||
if(a.getColumnType().equals(ExlConst.TYPE_MONEY)){ |
|||
a.setConditionFlag(0); |
|||
} |
|||
a.setId(null); |
|||
}); |
|||
columnConfService.saveBatch(columnList); |
|||
} |
|||
return tableConf; |
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,62 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.qs.serve.modules.exl.mapper.ExlTableConfMapper"> |
|||
|
|||
<resultMap id="exlTableConfMap" type="com.qs.serve.modules.exl.entity.ExlTableConf" > |
|||
<result property="id" column="id"/> |
|||
<result property="tableName" column="table_name"/> |
|||
<result property="excelTitle" column="excel_title"/> |
|||
<result property="enableFlag" column="enable_flag"/> |
|||
<result property="enableTime" column="enable_time"/> |
|||
<result property="remark" column="remark"/> |
|||
<result property="createTime" column="create_time"/> |
|||
<result property="updateTime" column="update_time"/> |
|||
<result property="tenantId" column="tenant_id"/> |
|||
<result property="createBy" column="create_by"/> |
|||
<result property="updateBy" column="update_by"/> |
|||
<result property="delFlag" column="del_flag"/> |
|||
</resultMap> |
|||
|
|||
<sql id="exlTableConfSql"> |
|||
exl_table_conf.`id`, |
|||
exl_table_conf.`table_name`, |
|||
exl_table_conf.`excel_title`, |
|||
exl_table_conf.`enable_flag`, |
|||
exl_table_conf.`enable_time`, |
|||
exl_table_conf.`remark`, |
|||
exl_table_conf.`create_time`, |
|||
exl_table_conf.`update_time`, |
|||
exl_table_conf.`tenant_id`, |
|||
exl_table_conf.`create_by`, |
|||
exl_table_conf.`update_by`, |
|||
exl_table_conf.`del_flag` </sql> |
|||
<select id="listData" resultType="java.util.Map"> |
|||
select * from ${tableName} |
|||
<where> |
|||
<if test="query.leList!=null and query.leList.size > 0"> |
|||
<foreach collection="query.leList" item ="item" index="i" open="(" close=")" separator=","> |
|||
and ${item.column} <= #{item.value} |
|||
</foreach> |
|||
</if> |
|||
<if test="query.geList!=null and query.geList.size > 0"> |
|||
<foreach collection="query.geList" item ="item" index="i" open="(" close=")" separator=","> |
|||
and ${item.column} >= #{item.value} |
|||
</foreach> |
|||
</if> |
|||
<if test="query.eqList!=null and query.eqList.size > 0"> |
|||
<foreach collection="query.eqList" item ="item" index="i" open="(" close=")" separator=","> |
|||
and ${item.column} = #{item.value} |
|||
</foreach> |
|||
</if> |
|||
<if test="query.likeList!=null and query.likeList.size > 0"> |
|||
<foreach collection="query.likeList" item ="item" index="i" open="(" close=")" separator=","> |
|||
and ${item.column} like concat('%', #{item.value} ,'%') |
|||
</foreach> |
|||
</if> |
|||
</where> |
|||
limit #{query.startRow},#{query.pageSize} |
|||
</select> |
|||
|
|||
|
|||
</mapper> |
|||
|
Loading…
Reference in new issue