mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-11 05:19:00 +08:00
⚡ 优化. 公共参数引入导入导出案例
This commit is contained in:
1 parent
bb4a6285d5
commit
6eaa933fde
3 files changed
+120
-13
No files matched your search
@@ -44,5 +44,9 @@
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pigx-common-autopoi</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+28
-8
@@ -20,12 +20,15 @@ package com.pig4cloud.pigx.admin.api.entity;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.pig4cloud.pigx.common.poi.excel.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 公共参数配置
|
||||
@@ -49,18 +52,21 @@ public class SysPublicParam extends Model<SysPublicParam> {
|
||||
* 公共参数名称
|
||||
*/
|
||||
@ApiModelProperty(value = "公共参数名称", required = true, example = "公共参数名称")
|
||||
@Excel(name = "名称", width = 15)
|
||||
private String publicName;
|
||||
|
||||
/**
|
||||
* 公共参数地址值,英文大写+下划线
|
||||
*/
|
||||
@ApiModelProperty(value = "键[英文大写+下划线]", required = true, example = "PIGX_PUBLIC_KEY")
|
||||
@Excel(name = "键", width = 15)
|
||||
private String publicKey;
|
||||
|
||||
/**
|
||||
* 值
|
||||
*/
|
||||
@ApiModelProperty(value = "值", required = true, example = "999")
|
||||
@Excel(name = "值", width = 15)
|
||||
private String publicValue;
|
||||
|
||||
/**
|
||||
@@ -80,29 +86,43 @@ public class SysPublicParam extends Model<SysPublicParam> {
|
||||
* 公共参数编码
|
||||
*/
|
||||
@ApiModelProperty(value = "编码", example = "^(PIG|PIGX)$")
|
||||
@Excel(name = "编码", width = 15)
|
||||
private String validateCode;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@ApiModelProperty(value = "创建时间", example = "2019-03-21 12:28:48")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 是否是系统内置
|
||||
*/
|
||||
private String system;
|
||||
@Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@ApiModelProperty(value = "修改时间", example = "2019-03-21 12:28:48")
|
||||
private LocalDateTime updateTime;
|
||||
//TODO 待处理 时间导入导出 java.util.Date类型,java.time.LocalDateTime报错
|
||||
//时间格式三要素:Excel JsonFormat DateTimeFormat
|
||||
@Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否是系统内置
|
||||
*/
|
||||
@ApiModelProperty(value = "是否是系统内置")
|
||||
@Excel(name = "备注", width = 15)
|
||||
private String system;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 配置类型:0-默认;1-检索;2-原文;3-报表;4-安全;5-文档;6-消息;9-其他
|
||||
*/
|
||||
@ApiModelProperty(value = "类型[1-检索;2-原文...]", example = "1")
|
||||
@Excel(name = "配置类型", width = 15)
|
||||
private String publicType;
|
||||
|
||||
|
||||
|
||||
+88
-5
@@ -17,22 +17,29 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysPublicParam;
|
||||
import com.pig4cloud.pigx.admin.service.SysPublicParamService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import com.pig4cloud.pigx.common.poi.excel.ExcelImportUtil;
|
||||
import com.pig4cloud.pigx.common.poi.excel.def.NormalExcelConstants;
|
||||
import com.pig4cloud.pigx.common.poi.excel.entity.ExportParams;
|
||||
import com.pig4cloud.pigx.common.poi.excel.entity.ImportParams;
|
||||
import com.pig4cloud.pigx.common.poi.excel.view.PigxEntityExcelView;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,7 +64,6 @@ public class SysPublicParamController {
|
||||
*/
|
||||
@Inner(value = false)
|
||||
@ApiOperation(value = "查询公共参数值", notes = "根据key查询公共参数值")
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "publicKey", value = "键值,譬如:VERSION_INSTRUCTIONS", required = true)})
|
||||
@GetMapping("/publicValue/{publicKey}")
|
||||
public R publicKey(@PathVariable("publicKey") String publicKey) {
|
||||
return R.ok(sysPublicParamService.getSysPublicParamKeyToValue(publicKey));
|
||||
@@ -70,6 +76,7 @@ public class SysPublicParamController {
|
||||
* @param sysPublicParam 公共参数
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "分页查询")
|
||||
@GetMapping("/page")
|
||||
public R getSysPublicParamPage(Page page, SysPublicParam sysPublicParam) {
|
||||
return R.ok(sysPublicParamService.page(page, Wrappers.query(sysPublicParam)));
|
||||
@@ -82,6 +89,7 @@ public class SysPublicParamController {
|
||||
* @param publicId id
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "通过id查询公共参数", notes = "通过id查询公共参数")
|
||||
@GetMapping("/{publicId}")
|
||||
public R getById(@PathVariable("publicId") Long publicId) {
|
||||
return R.ok(sysPublicParamService.getById(publicId));
|
||||
@@ -93,6 +101,7 @@ public class SysPublicParamController {
|
||||
* @param sysPublicParam 公共参数
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "新增公共参数", notes = "新增公共参数")
|
||||
@SysLog("新增公共参数")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('admin_syspublicparam_add')")
|
||||
@@ -106,6 +115,7 @@ public class SysPublicParamController {
|
||||
* @param sysPublicParam 公共参数
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "修改公共参数", notes = "修改公共参数")
|
||||
@SysLog("修改公共参数")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('admin_syspublicparam_edit')")
|
||||
@@ -119,6 +129,7 @@ public class SysPublicParamController {
|
||||
* @param publicId id
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "删除公共参数", notes = "删除公共参数")
|
||||
@SysLog("删除公共参数")
|
||||
@DeleteMapping("/{publicId}")
|
||||
@PreAuthorize("@pms.hasPermission('admin_syspublicparam_del')")
|
||||
@@ -126,4 +137,76 @@ public class SysPublicParamController {
|
||||
return sysPublicParamService.removeParam(publicId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
*/
|
||||
//临时接口调试开启Inner
|
||||
@Inner(value = false)
|
||||
@SysLog("导出excel数据")
|
||||
@ApiOperation(value = "导出excel数据", notes = "导出excel数据")
|
||||
@GetMapping(value = "/exportXls")
|
||||
// @PostMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls() {
|
||||
// Step.1 组装查询条件
|
||||
// TODO 后续封装完成 通用查询条件 包含权限、排序、普通检索、高级检索 QueryGenerator.initQueryWrapper(...);
|
||||
QueryWrapper<SysPublicParam> queryWrapper = null;
|
||||
queryWrapper = Wrappers.query();
|
||||
|
||||
// Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new PigxEntityExcelView());
|
||||
List<SysPublicParam> pageList = sysPublicParamService.list(Wrappers.query());
|
||||
|
||||
//Step.3 导出文件名称
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "参数配置列表");
|
||||
mv.addObject(NormalExcelConstants.CLASS, SysPublicParam.class);
|
||||
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("参数配置列表数据", "导出人:pigx", "导出信息"));
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
//临时接口调试开启Inner
|
||||
@Inner(value = false)
|
||||
@SysLog("导入excel数据")
|
||||
@ApiOperation(value = "导入excel数据", notes = "导入excel数据")
|
||||
@PostMapping(value = "/importExcel")
|
||||
public R<?> importExcel(@RequestParam("file") MultipartFile file) {
|
||||
// HttpServletRequest request
|
||||
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
// Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
//for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
// 获取上传文件对象
|
||||
//MultipartFile file = entity.getValue();
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<SysPublicParam> listSysPublicParams = null;
|
||||
if(file.getInputStream() != null){
|
||||
listSysPublicParams = ExcelImportUtil.importExcel(file.getInputStream(), SysPublicParam.class, params);
|
||||
for (SysPublicParam sysPublicParamExcel : listSysPublicParams) {
|
||||
sysPublicParamService.save(sysPublicParamExcel);
|
||||
}
|
||||
}
|
||||
|
||||
return R.ok("文件导入成功!数据行数:" + listSysPublicParams.size());
|
||||
} catch (Exception e) {
|
||||
return R.failed("文件导入失败!");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user