Foming 3 years ago
parent bf6f3d9254
commit 34f73211a3

@ -0,0 +1,97 @@
package com.anjiplus.template.gaea.business.modules.data.reportexcel.controller;
import com.anji.plus.gaea.annotation.Permission;
import com.anji.plus.gaea.annotation.log.GaeaAuditLog;
import com.anji.plus.gaea.bean.ResponseBean;
import com.anji.plus.gaea.code.ResponseCode;
import com.anji.plus.gaea.curd.controller.GaeaBaseController;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.controller.dto.ReportExcelDto;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.controller.param.ReportExcelParam;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.dao.entity.ReportExcel;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.service.ReportExcelService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author chenkening
* @date 2021/4/13 15:12
*/
@RestController
@Api(tags = "报表表格管理")
@RequestMapping("/reportExcel")
public class ReportExcelController extends GaeaBaseController<ReportExcelParam, ReportExcel, ReportExcelDto> {
@Autowired
private ReportExcelService reportExcelService;
@Override
public GaeaBaseService<ReportExcelParam, ReportExcel> getService() {
return reportExcelService;
}
@Override
public ReportExcel getEntity() {
return new ReportExcel();
}
@Override
public ReportExcelDto getDTO() {
return new ReportExcelDto();
}
@GetMapping("/detailByReportCode/{reportCode}")
@Permission(
code = "DETAIL",
name = "详情"
)
@GaeaAuditLog(
pageTitle = "详情"
)
public ResponseBean detailByReportCode(@PathVariable String reportCode) {
ReportExcelDto reportExcelDto = reportExcelService.detailByReportCode(reportCode);
return ResponseBean.builder().data(reportExcelDto).build();
}
@PostMapping("/preview")
@Permission(
code = "DETAIL",
name = "预览"
)
@GaeaAuditLog(
pageTitle = "预览"
)
public ResponseBean preview(@RequestBody ReportExcelDto reportExcelDto) {
ReportExcelDto result = reportExcelService.preview(reportExcelDto);
return ResponseBean.builder().data(result).build();
}
@PostMapping("/exportExcel")
@Permission(
code = "IMPORT",
name = "导出"
)
@GaeaAuditLog(
pageTitle = "报表导出"
)
public ResponseBean exportExcel(@RequestBody ReportExcelDto reportExcelDto) {
return ResponseBean.builder().code(ResponseCode.SUCCESS_CODE)
.data(reportExcelService.exportExcel(reportExcelDto))
.message("导出成功,请稍后在下载中心查看").build();
}
// @PostMapping("/exportPdf")
// public ResponseBean exportPdf(@RequestBody ReportExcelDto reportExcelDto) {
// reportExcelService.exportPdf(reportExcelDto);
// return ResponseBean.builder().code(ResponseCode.SUCCESS_CODE)
// .build();
// }
}

@ -0,0 +1,43 @@
package com.anjiplus.template.gaea.business.modules.data.reportexcel.controller.dto;
import com.anji.plus.gaea.curd.dto.GaeaBaseDTO;
import lombok.Data;
import java.io.Serializable;
/**
* @author chenkening
* @date 2021/4/13 15:12
*/
@Data
public class ReportExcelDto extends GaeaBaseDTO implements Serializable {
/** 报表名称 */
private String reportName;
/** 报表编码 */
private String reportCode;
/**数据集编码,以|分割*/
private String setCodes;
/** 分组 */
private String reportGroup;
/** 数据集查询参数 */
private String setParam;
/** 报表json字符串 */
private String jsonStr;
/** 报表类型 */
private String reportType;
/** 数据总计 */
private long total;
/**导出类型*/
private String exportType;
}

@ -0,0 +1,18 @@
package com.anjiplus.template.gaea.business.modules.data.reportexcel.controller.param;
import com.anji.plus.gaea.curd.params.PageParam;
import lombok.Data;
import java.io.Serializable;
/**
* @author chenkening
* @date 2021/4/13 15:12
*/
@Data
public class ReportExcelParam extends PageParam implements Serializable{
}

@ -0,0 +1,11 @@
package com.anjiplus.template.gaea.business.modules.data.reportexcel.dao;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.dao.entity.ReportExcel;
/**
* @author chenkening
* @date 2021/4/13 15:11
*/
public interface ReportExcelMapper extends GaeaBaseMapper<ReportExcel> {
}

@ -0,0 +1,33 @@
package com.anjiplus.template.gaea.business.modules.data.reportexcel.dao.entity;
import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author chenkening
* @date 2021/4/13 15:11
*/
@TableName(value="gaea_report_excel")
@Data
public class ReportExcel extends GaeaBaseEntity {
@ApiModelProperty(value = "报表编码")
private String reportCode;
@ApiModelProperty(value = "数据集编码,以|分割")
private String setCodes;
@ApiModelProperty(value = "数据集查询参数")
private String setParam;
@ApiModelProperty(value = "报表json字符串")
private String jsonStr;
@ApiModelProperty(value = "0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG")
private Integer enableFlag;
@ApiModelProperty(value = "0--未删除 1--已删除 DIC_NAME=DELETE_FLAG")
private Integer deleteFlag;
}

@ -0,0 +1,39 @@
package com.anjiplus.template.gaea.business.modules.data.reportexcel.service;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.controller.dto.ReportExcelDto;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.controller.param.ReportExcelParam;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.dao.entity.ReportExcel;
/**
* TODO
*
* @author chenkening
* @date 2021/4/13 15:14
*/
public interface ReportExcelService extends GaeaBaseService<ReportExcelParam, ReportExcel> {
/**
*
* @param reportCode
* @return
*/
ReportExcelDto detailByReportCode(String reportCode);
/**
*
* @param reportExcelDto
* @return
*/
ReportExcelDto preview(ReportExcelDto reportExcelDto);
/**
* excel
* @param reportExcelDto
* @return
*/
Boolean exportExcel(ReportExcelDto reportExcelDto);
// Boolean exportPdf(ReportExcelDto reportExcelDto);
}

@ -0,0 +1,146 @@
package com.anjiplus.template.gaea.business.modules.data.reportexcel.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.anji.plus.gaea.constant.BaseOperationEnum;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anji.plus.gaea.exception.BusinessException;
import com.anji.plus.gaea.export.enums.ExportTypeEnum;
import com.anji.plus.gaea.export.utils.ExportUtil;
import com.anji.plus.gaea.export.vo.ExportOperation;
import com.anji.plus.gaea.holder.UserContentHolder;
import com.anji.plus.gaea.utils.GaeaAssert;
import com.anji.plus.gaea.utils.GaeaBeanUtils;
import com.anjiplus.template.gaea.business.code.ResponseCode;
import com.anjiplus.template.gaea.business.modules.data.report.dao.ReportMapper;
import com.anjiplus.template.gaea.business.modules.data.report.dao.entity.Report;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.controller.dto.ReportExcelDto;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.dao.ReportExcelMapper;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.dao.entity.ReportExcel;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.service.ReportExcelService;
import com.anjiplus.template.gaea.business.modules.data.reportexcel.util.ReportUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
/**
* TODO
*
* @author chenkening
* @date 2021/4/13 15:14
*/
@Service
public class ReportExcelServiceImpl implements ReportExcelService {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private ReportExcelMapper reportExcelMapper;
@Autowired
private ThreadPoolTaskExecutor threadPoolExportExecutor;
@Autowired
private ReportMapper reportMapper;
@Value("${file.dist-path}")
private String dictPath;
@Autowired
private ReportUtil reportUtil;
@Override
public GaeaBaseMapper<ReportExcel> getMapper() {
return reportExcelMapper;
}
@Override
public ReportExcelDto detailByReportCode(String reportCode) {
QueryWrapper<ReportExcel> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("report_code" , reportCode);
ReportExcel reportExcel = reportExcelMapper.selectOne(queryWrapper);
if(reportExcel != null){
ReportExcelDto dto = new ReportExcelDto();
BeanUtils.copyProperties(reportExcel , dto);
return dto;
}
return null;
}
/**
*
*
* @param entity
* @param operationEnum
* @throws BusinessException
*/
@Override
public void processBeforeOperation(ReportExcel entity, BaseOperationEnum operationEnum) throws BusinessException {
if (operationEnum.equals(BaseOperationEnum.INSERT)) {
String reportCode = entity.getReportCode();
ReportExcel report = this.selectOne("report_code", reportCode);
if (null != report) {
this.deleteById(report.getId());
}
}
}
/**
*
*/
@Override
public ReportExcelDto preview(ReportExcelDto reportExcelDto) {
// 根据id查询 报表详情
ReportExcel reportExcel = selectOne("report_code", reportExcelDto.getReportCode());
QueryWrapper<Report> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("report_code" , reportExcelDto.getReportCode());
Report report = reportMapper.selectOne(queryWrapper);
GaeaAssert.notNull(reportExcel, ResponseCode.RULE_CONTENT_NOT_EXIST, "reportExcel");
String setParam = reportExcelDto.getSetParam();
GaeaBeanUtils.copyAndFormatter(reportExcel , reportExcelDto);
if(StringUtils.isNotBlank(setParam)){
reportExcelDto.setSetParam(setParam);
}
reportExcelDto.setReportName(report.getReportName());
JSONObject jsonObject = reportUtil.reportParse(reportExcelDto);
reportExcelDto.setJsonStr(JSONObject.toJSONString(jsonObject));
reportExcelDto.setTotal(jsonObject.getJSONObject("rows").size());
return reportExcelDto;
}
@Override
public Boolean exportExcel(ReportExcelDto reportExcelDto) {
ExportOperation exportOperation = new ExportOperation();
//指明导出数据查询到结果开始时间
exportOperation.setResultStartTime(LocalDateTime.now());
ReportExcelDto result = preview(reportExcelDto);
//指明导出数据查询到结果结束时间
exportOperation.setResultEndTime(LocalDateTime.now());
//指明导出数据查询到结果条数
exportOperation.setResultSize(result.getTotal());
//指明采用什么模式导出
exportOperation.setExportType(StringUtils.isBlank(reportExcelDto.getExportType())
? ExportTypeEnum.GAEA_TEMPLATE_EXCEL.getCodeValue() : reportExcelDto.getExportType());
//设置导出的文件名
exportOperation.setFileTitle(result.getReportName());
//设置导出的文件存放目录
exportOperation.setFilePath(dictPath);
//设置导出的数据jsonStr
exportOperation.setJsonStr(result.getJsonStr());
//保存当前操作人
exportOperation.setCreaterUsername(UserContentHolder.getContext().getUsername());
//调用盖亚组件实现导出文件
threadPoolExportExecutor.execute(() -> {
ExportUtil.getInstance().exportByFilePathSimple(exportOperation, null);
});
return true;
}
}
Loading…
Cancel
Save