From d05efd40821d9b7e567fb688e4797835bc58abec Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Mon, 28 Jun 2021 16:16:02 +0800 Subject: [PATCH 1/6] pom --- report-core/pom.xml | 44 +- .../service/impl/ReportServiceImpl.java | 12 - .../controller/ReportExcelController.java | 97 -- .../controller/dto/ReportExcelDto.java | 43 - .../controller/param/ReportExcelParam.java | 18 - .../reportexcel/dao/ReportExcelMapper.java | 11 - .../reportexcel/dao/entity/ReportExcel.java | 33 - .../service/ReportExcelService.java | 39 - .../service/impl/ReportExcelServiceImpl.java | 146 --- .../modules/reportexcel/util/ReportUtil.java | 1109 ----------------- .../resources/mapper/ReportExcelMapper.xml | 22 - report-ui/config/dev.env.js | 4 +- 12 files changed, 8 insertions(+), 1570 deletions(-) delete mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/ReportExcelController.java delete mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/dto/ReportExcelDto.java delete mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/param/ReportExcelParam.java delete mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/dao/ReportExcelMapper.java delete mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/dao/entity/ReportExcel.java delete mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/ReportExcelService.java delete mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java delete mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/util/ReportUtil.java delete mode 100644 report-core/src/main/resources/mapper/ReportExcelMapper.xml diff --git a/report-core/pom.xml b/report-core/pom.xml index 0819f92b..9b6a30c0 100644 --- a/report-core/pom.xml +++ b/report-core/pom.xml @@ -38,23 +38,6 @@ spring-cloud-context - - - org.springframework.boot - spring-boot-starter-freemarker - - - - - - - - - - - - - com.baomidou mybatis-plus-boot-starter @@ -98,31 +81,16 @@ - - com.alibaba - druid - 1.1.22 + org.apache.httpcomponents + httpclient + 4.5.2 - - owinfo - impalajdbc41 - 1.0.0 - system - ${project.basedir}/src/main/resources/lib/ImpalaJDBC41.jar - - - org.apache.hive - hive-jdbc - 1.2.1 - - - org.eclipse.jetty.aggregate - jetty-all - - + org.apache.httpcomponents + httpcore + 4.4.5 diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/service/impl/ReportServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/service/impl/ReportServiceImpl.java index 838315c7..2efbc378 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/service/impl/ReportServiceImpl.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/service/impl/ReportServiceImpl.java @@ -5,11 +5,6 @@ import com.anjiplus.template.gaea.business.modules.report.controller.dto.ReportD import com.anjiplus.template.gaea.business.modules.report.dao.ReportMapper; import com.anjiplus.template.gaea.business.modules.report.dao.entity.Report; import com.anjiplus.template.gaea.business.modules.report.service.ReportService; -import com.anjiplus.template.gaea.business.modules.reportexcel.dao.ReportExcelMapper; -import com.anjiplus.template.gaea.business.modules.reportexcel.dao.entity.ReportExcel; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,13 +17,9 @@ import org.springframework.stereotype.Service; @Service public class ReportServiceImpl implements ReportService { - private Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private ReportMapper reportMapper; - @Autowired - private ReportExcelMapper reportExcelMapper; - @Override public GaeaBaseMapper getMapper() { return reportMapper; @@ -38,8 +29,5 @@ public class ReportServiceImpl implements ReportService { @Override public void delReport(ReportDto reportDto) { deleteById(reportDto.getId()); - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("report_code" , reportDto.getReportCode()); - reportExcelMapper.delete(queryWrapper); } } diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/ReportExcelController.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/ReportExcelController.java deleted file mode 100644 index 5ab7457d..00000000 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/ReportExcelController.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.anjiplus.template.gaea.business.modules.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.reportexcel.controller.dto.ReportExcelDto; -import com.anjiplus.template.gaea.business.modules.reportexcel.controller.param.ReportExcelParam; -import com.anjiplus.template.gaea.business.modules.reportexcel.dao.entity.ReportExcel; -import com.anjiplus.template.gaea.business.modules.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 { - - @Autowired - private ReportExcelService reportExcelService; - - @Override - public GaeaBaseService 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(); -// } -} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/dto/ReportExcelDto.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/dto/ReportExcelDto.java deleted file mode 100644 index 22c273e7..00000000 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/dto/ReportExcelDto.java +++ /dev/null @@ -1,43 +0,0 @@ - -package com.anjiplus.template.gaea.business.modules.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; - -} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/param/ReportExcelParam.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/param/ReportExcelParam.java deleted file mode 100644 index e4d85806..00000000 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/param/ReportExcelParam.java +++ /dev/null @@ -1,18 +0,0 @@ - -package com.anjiplus.template.gaea.business.modules.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{ - - -} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/dao/ReportExcelMapper.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/dao/ReportExcelMapper.java deleted file mode 100644 index 422b83f8..00000000 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/dao/ReportExcelMapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.anjiplus.template.gaea.business.modules.reportexcel.dao; - -import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper; -import com.anjiplus.template.gaea.business.modules.reportexcel.dao.entity.ReportExcel; - -/** - * @author chenkening - * @date 2021/4/13 15:11 - */ -public interface ReportExcelMapper extends GaeaBaseMapper { -} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/dao/entity/ReportExcel.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/dao/entity/ReportExcel.java deleted file mode 100644 index ea55d556..00000000 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/dao/entity/ReportExcel.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.anjiplus.template.gaea.business.modules.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; -} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/ReportExcelService.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/ReportExcelService.java deleted file mode 100644 index 883899b6..00000000 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/ReportExcelService.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.anjiplus.template.gaea.business.modules.reportexcel.service; - -import com.anji.plus.gaea.curd.service.GaeaBaseService; -import com.anjiplus.template.gaea.business.modules.reportexcel.controller.dto.ReportExcelDto; -import com.anjiplus.template.gaea.business.modules.reportexcel.controller.param.ReportExcelParam; -import com.anjiplus.template.gaea.business.modules.reportexcel.dao.entity.ReportExcel; - -/** - * TODO - * - * @author chenkening - * @date 2021/4/13 15:14 - */ -public interface ReportExcelService extends GaeaBaseService { - - /** - * 根据报表编码查询详情 - * @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); -} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java deleted file mode 100644 index 3295e64c..00000000 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.anjiplus.template.gaea.business.modules.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.report.dao.ReportMapper; -import com.anjiplus.template.gaea.business.modules.report.dao.entity.Report; -import com.anjiplus.template.gaea.business.modules.reportexcel.controller.dto.ReportExcelDto; -import com.anjiplus.template.gaea.business.modules.reportexcel.dao.ReportExcelMapper; -import com.anjiplus.template.gaea.business.modules.reportexcel.dao.entity.ReportExcel; -import com.anjiplus.template.gaea.business.modules.reportexcel.service.ReportExcelService; -import com.anjiplus.template.gaea.business.modules.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 getMapper() { - return reportExcelMapper; - } - - @Override - public ReportExcelDto detailByReportCode(String reportCode) { - QueryWrapper 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 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; - } - -} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/util/ReportUtil.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/util/ReportUtil.java deleted file mode 100644 index bcebc34a..00000000 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/util/ReportUtil.java +++ /dev/null @@ -1,1109 +0,0 @@ -package com.anjiplus.template.gaea.business.modules.reportexcel.util; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.parser.Feature; -import com.anji.plus.gaea.export.utils.QrCodeOrBarCodeUtil; -import com.anjiplus.template.gaea.business.modules.dataSet.controller.dto.DataSetDto; -import com.anjiplus.template.gaea.business.modules.dataSet.controller.dto.OriginalDataDto; -import com.anjiplus.template.gaea.business.modules.dataSet.service.DataSetService; -import com.anjiplus.template.gaea.business.modules.report.constant.ExpConstant; -import com.anjiplus.template.gaea.business.modules.reportexcel.controller.dto.ReportExcelDto; -import freemarker.template.Configuration; -import freemarker.template.Template; -import org.apache.commons.lang3.StringUtils; -import org.apache.poi.ddf.EscherClientAnchorRecord; -import org.apache.poi.hssf.usermodel.HSSFDataFormat; -import org.apache.poi.ss.usermodel.BorderStyle; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellType; -import org.apache.poi.ss.usermodel.ClientAnchor; -import org.apache.poi.ss.usermodel.CreationHelper; -import org.apache.poi.ss.usermodel.DataFormat; -import org.apache.poi.ss.usermodel.FillPatternType; -import org.apache.poi.ss.usermodel.HorizontalAlignment; -import org.apache.poi.ss.usermodel.Picture; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.VerticalAlignment; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.ss.util.RegionUtil; -import org.apache.poi.xssf.usermodel.XSSFCellStyle; -import org.apache.poi.xssf.usermodel.XSSFColor; -import org.apache.poi.xssf.usermodel.XSSFDataFormat; -import org.apache.poi.xssf.usermodel.XSSFDrawing; -import org.apache.poi.xssf.usermodel.XSSFFont; -import org.apache.poi.xssf.usermodel.XSSFRow; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; - -import java.io.ByteArrayOutputStream; -import java.io.FileOutputStream; -import java.io.StringReader; -import java.io.StringWriter; -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.OptionalDouble; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * TODO - * - * @author chenkening - * @date 2021/3/26 10:30 - */ -@Component -public class ReportUtil { - - /** - * 记录日志 - */ - protected static Logger logger = LoggerFactory.getLogger(ReportUtil.class); - - @Autowired - private DataSetService dataSetService; - - - public JSONObject reportParse(ReportExcelDto reportExcelDto) { - - // 取第一个sheet - JSONObject jsonObject = JSONObject.parseObject(reportExcelDto.getJsonStr(), Feature.OrderedField).getJSONArray("sheet").getJSONObject(0); -// JSONObject jsonObject = JSONObject.parseObject(reportExcelDto.getJsonStr()); - - logger.info("excelJSON信息:{}\n", jsonObject); - JSONObject rowsJsonObject = jsonObject.getJSONObject("rows"); - // 所有的样式数组。 - JSONArray styles = jsonObject.getJSONArray("styles"); -// System.out.println(styles); - logger.info("需要解析的JSON {}", rowsJsonObject); - - //用于存储语法解析后的json - JSONObject syntaxJsonObject = new JSONObject(true); - - Map dataSetMap = new HashMap<>(); - - Map> map = new HashMap<>(); - rowsJsonObject.remove("len"); - for (String s : rowsJsonObject.keySet()) { - List list = Collections.singletonList(rowsJsonObject.getJSONObject(s)); - map.put(Integer.parseInt(s), list); - } - - // 解决rows 行乱序 - syntaxParse(map, syntaxJsonObject, reportExcelDto.getSetCodes(), reportExcelDto.getSetParam(), dataSetMap); - JSONObject jsonMap = new JSONObject(true); - - JSONObject jsonObject1 = JSONObject.parseObject(JSON.toJSONString(syntaxJsonObject), Feature.OrderedField); - jsonObject1.put("len", jsonObject1.size() + 30); - jsonObject.put("rows", jsonObject1); - jsonObject.put("name", reportExcelDto.getReportName()); - return jsonObject; - } - - /** - * 包含动态表达式的行解析 - * - * @param mapss rows - * @param syntaxJsonObject 存储解析后的json - * @param dbCode 编码 - * @param setParam 查询条件数据集 - * @param dataSetMap 数据集 - */ - public void syntaxParse(Map> mapss, JSONObject syntaxJsonObject, String dbCode, String setParam, Map dataSetMap) { - - String[] split = dbCode.split("\\|"); - // 解析过几次表达式列。 - int count = 1; - for (Map.Entry> integerListEntry : mapss.entrySet()) { - List listobj = Stream.of(integerListEntry.getValue()).collect(Collectors.toList()); - JSONArray jsonObject1 = JSONArray.parseArray(listobj.toString()); - JSONArray jsonArray = (JSONArray) jsonObject1.get(0); - // cells json - JSONObject jsonObject2 = JSONObject.parseObject(jsonArray.get(0).toString()); - for (Map.Entry stringObjectEntry2 : jsonObject2.entrySet()) { - if (stringObjectEntry2.getKey() == "cells") { - JSONObject cell = (JSONObject) stringObjectEntry2.getValue(); - if (jsonObject2.toString().contains("#{")) { - - for (int i = 0; i < split.length; i++) { - JSONObject setParamJson = JSONObject.parseObject(setParam); - - String code = split[i]; - - String newCode = String.format("#{%s", code); - // 如果表达式包含具体code编码,进。否则不做处理 - if (jsonObject2.toString().contains(newCode) && StringUtils.isNotBlank(code)) { - DataSetDto dto = new DataSetDto(); - dto.setSetCode(code); - Map map = new HashMap<>(); - // 查询条件 - if (setParamJson.containsKey(code)) { - JSONObject paramCondition = setParamJson.getJSONObject(code); - paramCondition.entrySet().forEach(item -> map.put(item.getKey(), item.getValue())); - } - - dto.setContextData(map); - OriginalDataDto originalDataDto = dataSetService.getData(dto); - dataSetMap.clear(); - List list = (List) JSONObject.toJSON(originalDataDto.getData()); - dataSetMap.put("list", list); - boolean flag = true; - //仅拿到为cells的json ,目前推拽有问题,会存在 列为-1 ,排除掉不解析 - for (Map.Entry objectEntry : cell.entrySet()) { - JSONObject object = (JSONObject) objectEntry.getValue(); - for (Map.Entry stringObjectEntry : object.entrySet()) { - if (stringObjectEntry.getKey().equals("-1")) { - flag = false; - } - } - } - if (flag) { - if (syntaxJsonObject.size() == 0) { - StringBuffer sb = new StringBuffer(); - String str = jsonObject2.toString().replaceAll("#\\{", "\\${"); - sb.append(String.format("{<#list list as %s> ", code)); - sb.append(String.format("\"${%s_index+%s}\":%s,", code, integerListEntry.getKey(), str)); - sb.append(""); - sb.append("}"); - logger.info("替换后的str: {}", sb); - String parseJsonStr = parseTemplate(sb.toString(), dataSetMap); - if (parseJsonStr.equals("{}")) { - syntaxJsonObject.putAll(isNullParseJson(jsonObject2, newCode, syntaxJsonObject.size(), integerListEntry.getKey(), 0)); - } else { - syntaxJsonObject.putAll(JSONObject.parseObject(parseJsonStr, Feature.OrderedField)); - } - } else { - StringBuffer sb = new StringBuffer(); - String str = jsonObject2.toString().replaceAll("#\\{", "\\${").replaceAll("\\\\n", ""); - sb.append(String.format("{<#list list as %s> ", code)); - sb.append(String.format("\"${%s_index+%s}\":%s,", code, syntaxJsonObject.size() + integerListEntry.getKey() - count, str)); - sb.append(""); - sb.append("}"); - logger.info("替换后的str: {}", sb); - String parseJsonStr = parseTemplate(sb.toString(), dataSetMap); - syntaxJsonObject.putAll(JSONObject.parseObject(parseJsonStr, Feature.OrderedField)); - // 如果查出来没有数据,会被替换为 {} ,不能put到 syntaxJsonObject,就会少一行,不操作count - if (parseJsonStr.equals("{}")) { - syntaxJsonObject.putAll(isNullParseJson(jsonObject2, newCode, syntaxJsonObject.size(), integerListEntry.getKey(), count)); - } else { - syntaxJsonObject.putAll(JSONObject.parseObject(parseJsonStr, Feature.OrderedField)); - } - count++; - } - } - } - } - // 存在 函数表达式 - } else if (!CollectionUtils.isEmpty(ExpConstant.getExpFunction(jsonObject2.toString()))) { - // 函数下标集合 - List indexs = ExpConstant.getExpFunction(jsonObject2.toString()); - for (Integer index : indexs) { - // 函数值 - String exp = ExpConstant.FUNCTION[index]; - - List bigDecimalList = new ArrayList<>(); - for (Map.Entry entryHanShu : jsonObject2.entrySet()) { - JSONObject jb3 = (JSONObject) entryHanShu.getValue(); - for (Map.Entry entry4 : jb3.entrySet()) { - // 得到最下面的 {"style":1,"text":"=SUM(A3)"} - JSONObject cellJson = (JSONObject) entry4.getValue(); - if (cellJson.containsKey("text")) { - if (StringUtils.isNotBlank(cellJson.get("text").toString()) && cellJson.get("text").toString().contains(exp)) { - for (Map.Entry rowsJson : syntaxJsonObject.entrySet()) { - // 拿到一行 中的cells - JSONObject rowsJsonToCells = (JSONObject) JSONObject.parseObject(rowsJson.getValue().toString()).get("cells"); - if (rowsJsonToCells.containsKey(entry4.getKey())) { - JSONObject textJson = (JSONObject) rowsJsonToCells.get(entry4.getKey()); - if (textJson.containsKey("text")) { - // 列值。 - String value = textJson.get("text").toString(); - try { - bigDecimalList.add(new BigDecimal(value)); - } catch (Exception exception) { - logger.info("函数计算错误,错误列{}、值{}", entry4, value); - } - } - } - } - if (!CollectionUtils.isEmpty(bigDecimalList)) { - switch (exp) { - case "=MIN(": - Optional min = bigDecimalList.stream().min((o1, o2) -> o1.compareTo(o2)); - cellJson.replace("text", cellJson.get("text"), min.get() + ""); - break; - case "=MAX(": - Optional max = bigDecimalList.stream().max((o1, o2) -> o1.compareTo(o2)); - cellJson.replace("text", cellJson.get("text"), max.get() + ""); - break; - case "=SUM(": - BigDecimal sums = bigDecimalList.stream().reduce(BigDecimal.ZERO, BigDecimal::add); - cellJson.replace("text", cellJson.get("text"), sums + ""); - break; - case "=AVERAGE(": - OptionalDouble average = bigDecimalList.stream().mapToDouble(BigDecimal::doubleValue).average(); - cellJson.replace("text", cellJson.get("text"), average.getAsDouble() + ""); - break; - default: - break; - } - } else { - cellJson.replace("text", cellJson.get("text"), ""); - } - } - } - } - } - - } - if (syntaxJsonObject.size() == 0) { - syntaxJsonObject.put(integerListEntry.getKey() + "", jsonObject2); - } else { - syntaxJsonObject.put(syntaxJsonObject.size() + integerListEntry.getKey() - count + "", jsonObject2); - count++; - } - } else { - - if (count == 1 && syntaxJsonObject.size() == 0) { - syntaxJsonObject.put(integerListEntry.getKey() + "", jsonObject2); - } else { - syntaxJsonObject.put(syntaxJsonObject.size() + integerListEntry.getKey() - count + "", jsonObject2); - count++; - } - } - } - } - } - - } - - /** - * 解析的表达式未null 即 {} - * - * @param jsonObject 本行json - * @param newCode 表达式编码 - * @param syntax 存储解析后的json大小 - * @param entryNum 本次循环的num - * @param count - * @return - */ - public static JSONObject isNullParseJson(JSONObject jsonObject, String newCode, Integer syntax, Integer entryNum, int count) { - JSONObject cellsJson = jsonObject.getJSONObject("cells"); - for (Map.Entry entry : cellsJson.entrySet()) { - JSONObject elementJson = JSONObject.parseObject(entry.getValue().toString()); - if (elementJson.containsKey("text")) { - String text = (String) elementJson.get("text"); - if (text.contains(newCode)) { - elementJson.put("text", ""); - } - } - cellsJson.put(entry.getKey(), elementJson); - } - jsonObject.put("cells", cellsJson); - JSONObject newJson = new JSONObject(); - newJson.put(String.valueOf((syntax + entryNum - count)), jsonObject); - return newJson; - } - - /** - * 报表格式化解析 - * - * @param templateValue - * @param maps - * @return - */ - private static String parseTemplate(String templateValue, Map maps) { - try { - Configuration configuration = new Configuration(); - configuration.setNumberFormat("#.#########"); - configuration.setClassicCompatible(true); - StringWriter writer = new StringWriter(); - Template template = new Template("template", new StringReader(templateValue), configuration); - template.process(maps, writer); - return writer.toString(); - - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public static void main(String[] args) { - String str = "{\"sheet\":[{\"name\":\"sheet2\",\"freeze\":\"A1\",\"styles\":[{\"valign\":\"top\"}],\"merges\":[],\"rows\":{\"0\":{\"cells\":{\"0\":{\"text\":{\"type\":\"QRCode\",\"content\":\"http://gaea.anji-plus.com\",\"width\":125,\"height\":125,\"ri\":0,\"ci\":0},\"style\":0}},\"height\":163},\"len\":100},\"cols\":{\"len\":20},\"validations\":[],\"autofilter\":{}}]}"; - - // 取第一个sheet - JSONObject jsonObject = JSONObject.parseObject(str); -// XSSFWorkbook workbook = new XSSFWorkbook(); -// XSSFSheet sheet = workbook.createSheet(); - try { - exportExcel(jsonObject); -// makePhoto(jsonArray , workbook , sheet); -// workbook.write(new FileOutputStream("E:\\excel\\e\\dsad.xlsx")); - } catch (Exception e) { - e.printStackTrace(); - } - - - } - - public static Map exportExcel(JSONObject a) { -// JSONObject jsonObject = JSONObject.parseObject(result.getJsonStr()); - JSONObject jsonObject = a.getJSONArray("sheet").getJSONObject(0); - JSONObject rows = jsonObject.getJSONObject("rows"); - JSONObject cols = jsonObject.getJSONObject("cols"); - if (cols.containsKey("len")) { - cols.remove("len"); - } - EscherClientAnchorRecord escherClientAnchorRecord; - - if (rows.containsKey("-1")) { - rows.remove("-1"); - } -// JSONArray photos = jsonObject.getJSONArray("QRCodeOrBarCode"); - // 所有的样式数组。 - JSONArray styles = jsonObject.getJSONArray("styles"); - -// 1.创建一个工作簿 - XSSFWorkbook workbook = new XSSFWorkbook(); - - -// 2.创建一个工作表 - XSSFSheet sheet = workbook.createSheet("news"); - try { - sheet.autoSizeColumn(1, true); - // 设置默认列宽 - sheet.setDefaultColumnWidth(12); - sheet.setDefaultRowHeight((short) 360); - Iterator colsIte = cols.keySet().iterator(); - while (colsIte.hasNext()) { - String next = colsIte.next(); //列 - JSONObject colStyle = cols.getJSONObject(next); - if (colStyle.containsKey("width")) { - // 自定义 width * 32 - sheet.setColumnWidth(Integer.parseInt(next), colStyle.getInteger("width") * 30); - } - } - -// if (photos != null) { -// // make photo -// makePhoto(photos, workbook, sheet); -// } - for (Map.Entry entry : rows.entrySet()) { - if (!entry.getKey().contains("len")) { - - // 创建一行 - Row row = sheet.createRow(Integer.parseInt(entry.getKey())); - JSONObject jsonObject1 = (JSONObject) entry.getValue(); - - //设置行高 - if (jsonObject1.containsKey("height")) { - int height = (int) jsonObject1.get("height"); - row.setHeight((short) (height * 14.7)); - } - // cells 获取到一行 - JSONObject cells = (JSONObject) jsonObject1.get("cells"); - if (cells.containsKey("-1")) { - cells.remove("-1"); - } - - setCellStyle(cells, workbook , sheet , styles, row); - - } - } - - Iterator iterator = rows.keySet().iterator(); - while (iterator.hasNext()) { - String rownum = iterator.next(); //行 - if (rownum.equals("len")) { - continue; - } - JSONObject cells = rows.getJSONObject(rownum).getJSONObject("cells"); - if (cells == null) { - continue; - } else { - Iterator cellsIte = cells.keySet().iterator(); - while (cellsIte.hasNext()) { - String cellnum = cellsIte.next(); //列 - JSONObject cellJSON = cells.getJSONObject(cellnum); - if (cellJSON != null) { - if (cellJSON.containsKey("merge")) { - List list = (List) cellJSON.get("merge"); -// // 起始行, 终止行, 起始列, 终止列 - CellRangeAddress cra = new CellRangeAddress(Integer.parseInt(rownum), Integer.parseInt(rownum) + list.get(0), Integer.parseInt(cellnum), Integer.parseInt(cellnum) + list.get(1)); - sheet.addMergedRegion(cra); - - - if (cellJSON.containsKey("style")) { - int style = (int) cellJSON.get("style"); - JSONObject jsonObject4 = (JSONObject) styles.get(style); - if (jsonObject4.containsKey("border")) { - JSONObject borders = (JSONObject) jsonObject4.get("border"); - - Iterator borderIterator = borders.keySet().iterator(); - while (borderIterator.hasNext()) { - String borderSide = borderIterator.next(); - // 设置单元格的边框 - switch (borderSide) { - case "top": - JSONArray top = borders.getJSONArray("top"); - // 上边框 - RegionUtil.setBorderTop(BorderStyle.valueOf(top.get(0).toString().toUpperCase()).getCode(), cra, sheet); - case "left": - JSONArray left = borders.getJSONArray("left"); - // 左边框 - RegionUtil.setBorderLeft(BorderStyle.valueOf(left.get(0).toString().toUpperCase()).getCode(), cra, sheet); - case "bottom": - JSONArray bottom = borders.getJSONArray("bottom"); - // 下边框 - RegionUtil.setBorderBottom(BorderStyle.valueOf(bottom.get(0).toString().toUpperCase()).getCode(), cra, sheet); - case "right": - JSONArray right = borders.getJSONArray("right"); - // 右边框 - RegionUtil.setBorderRight(BorderStyle.valueOf(right.get(0).toString().toUpperCase()).getCode(), cra, sheet); - default: - break; - } - } - } - } - - } - } - - } - } - } - - - - - String fileName = (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date()); - - FileOutputStream fos = new FileOutputStream("E:\\excel\\e\\" + fileName + ".xlsx"); - workbook.write(fos); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public static Map exportExcel(ReportExcelDto result) { - // 取第一个sheet -// JSONObject jsonObject = JSONObject.parseObject(result.getJsonStr(), Feature.OrderedField).getJSONArray("sheet").getJSONObject(0); - JSONObject jsonObject = JSONObject.parseObject(result.getJsonStr()); -// jsonObject.put("QRCodeOrBarCode", "[\n" + -// " {\n" + -// " \"type\": \"QRCode\",\n" + -// " \"content\": \"https://gaea.anji-plus.com\",\n" + -// " \"height\": \"128\",\n" + -// " \"width\": \"128\",\n" + -// " \"backgroundColor\": \"#FFFFFF\",\n" + -// " \"foregroundColor\": \"#000000\",\n" + -// " \"ri\": 1,\n" + -// " \"ci\": \"1\"\n" + -// " },\n" + -// " {\n" + -// " \"type\": \"BarCode\",\n" + -// " \"content\": \"6926557300360\",\n" + -// " \"height\": \"50\",\n" + -// " \"width\": \"450\",\n" + -// " \"backgroundColor\": \"#FFFFFF\",\n" + -// " \"foregroundColor\": \"#000000\",\n" + -// " \"ri\": 1,\n" + -// " \"ci\": \"1\"\n" + -// " }\n" + -// " ]"); - JSONObject rows = (JSONObject) jsonObject.get("rows"); - JSONObject cols = (JSONObject) jsonObject.get("cols"); - if (cols.containsKey("len")) { - cols.remove("len"); - } - if (rows.containsKey("-1")) { - rows.remove("-1"); - } - JSONArray photos = jsonObject.getJSONArray("QRCodeOrBarCode"); - // 所有的样式数组。 - JSONArray styles = jsonObject.getJSONArray("styles"); - -// 1.创建一个工作簿 - XSSFWorkbook workbook = new XSSFWorkbook(); - - -// 2.创建一个工作表 - XSSFSheet sheet = workbook.createSheet(result.getReportName()); - try { - sheet.autoSizeColumn(1, true); - // 设置默认列宽 - sheet.setDefaultColumnWidth(12); - Iterator colsIte = cols.keySet().iterator(); - while (colsIte.hasNext()) { - String next = colsIte.next(); //列 - JSONObject colStyle = cols.getJSONObject(next); - if (colStyle.containsKey("width")) { - // 自定义 width * 32 - sheet.setColumnWidth(Integer.parseInt(next), colStyle.getInteger("width") * 32); - } - } - for (Map.Entry entry : rows.entrySet()) { - if (!entry.getKey().contains("len")) { - - // 创建一行 - Row row = sheet.createRow(Integer.parseInt(entry.getKey())); - JSONObject jsonObject1 = (JSONObject) entry.getValue(); - - //设置行高 - if (jsonObject1.containsKey("height")) { - int height = (int) jsonObject1.get("height"); - row.setHeight((short) (height * 14.7)); - } else { - row.setHeight((short) 360); - } - // cells 获取到一行 - JSONObject cells = (JSONObject) jsonObject1.get("cells"); - if (cells.containsKey("-1")) { - cells.remove("-1"); - } - - setCellStyle(cells, workbook, sheet , styles, row); - - } - } - - Iterator iterator = rows.keySet().iterator(); - while (iterator.hasNext()) { - String rownum = iterator.next(); //行 - if (rownum.equals("len")) { - continue; - } - JSONObject cells = rows.getJSONObject(rownum).getJSONObject("cells"); - if (cells == null) { - continue; - } else { - Iterator cellsIte = cells.keySet().iterator(); - while (cellsIte.hasNext()) { - String cellnum = cellsIte.next(); //列 - JSONObject cellJSON = cells.getJSONObject(cellnum); - if (cellJSON != null) { - if (cellJSON.containsKey("merge")) { - List list = (List) cellJSON.get("merge"); -// // 起始行, 终止行, 起始列, 终止列 - CellRangeAddress cra = new CellRangeAddress(Integer.parseInt(rownum), Integer.parseInt(rownum) + list.get(0), Integer.parseInt(cellnum), Integer.parseInt(cellnum) + list.get(1)); - sheet.addMergedRegion(cra); - - - if (cellJSON.containsKey("style")) { - int style = (int) cellJSON.get("style"); - JSONObject jsonObject4 = (JSONObject) styles.get(style); - if (jsonObject4.containsKey("border")) { - JSONObject borders = (JSONObject) jsonObject4.get("border"); - - Iterator borderIterator = borders.keySet().iterator(); - while (borderIterator.hasNext()) { - String borderSide = borderIterator.next(); - // 设置单元格的边框 - switch (borderSide) { - case "top": - JSONArray top = borders.getJSONArray("top"); - // 上边框 - RegionUtil.setBorderTop(BorderStyle.valueOf(top.get(0).toString().toUpperCase()).getCode(), cra, sheet); - case "left": - JSONArray left = borders.getJSONArray("left"); - // 左边框 - RegionUtil.setBorderLeft(BorderStyle.valueOf(left.get(0).toString().toUpperCase()).getCode(), cra, sheet); - case "bottom": - JSONArray bottom = borders.getJSONArray("bottom"); - // 下边框 - RegionUtil.setBorderBottom(BorderStyle.valueOf(bottom.get(0).toString().toUpperCase()).getCode(), cra, sheet); - case "right": - JSONArray right = borders.getJSONArray("right"); - // 右边框 - RegionUtil.setBorderRight(BorderStyle.valueOf(right.get(0).toString().toUpperCase()).getCode(), cra, sheet); - default: - break; - } - } - } - } - - } - } - - } - } - } - Map map = new HashMap<>(); - if (photos != null) { - // make photo - makePhoto(photos, workbook, sheet); - } - String fileName = result.getReportName() + (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date()); - - FileOutputStream fos = new FileOutputStream("E:\\excel\\e\\" + fileName + ".xlsx"); - workbook.write(fos); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - /** - * @param cells 当前行每一列 - * @param workbook - * @param styles 样式 - * @param row 当前行 - */ - private static void setCellStyle(JSONObject cells, XSSFWorkbook workbook, XSSFSheet sheet ,JSONArray styles, Row row) { - - for (Map.Entry entry2 : cells.entrySet()) { - - XSSFCellStyle cellStyle = workbook.createCellStyle(); - DataFormat df = workbook.createDataFormat(); - - JSONObject jsonObject3 = (JSONObject) entry2.getValue(); - // 创建一列 - Cell cell = row.createCell(Integer.parseInt(entry2.getKey())); - Object text = jsonObject3.get("text"); - String cellValue = null; - if(text instanceof JSONObject){ - JSONObject jsonObject = (JSONObject) text; - JSONArray jsonArray = new JSONArray(); - jsonArray.add(jsonObject); - try { - makePhoto(jsonArray , workbook , sheet ); - } catch (Exception e) { - logger.info("makePhoto error" , e); - } - } else if(text instanceof String){ - cell = (Cell) text; - // 创建第 某行 第几个单元格 - if (StringUtils.isNotBlank(cellValue)) { - cell.setCellValue(cellValue); - if (!CollectionUtils.isEmpty(ExpConstant.getExpFunction(cellValue))) { - cell.setCellFormula(cellValue.substring(1)); - cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00")); - cell.setCellType(CellType.FORMULA); - } - } - } - - - if (StringUtils.isNotBlank(jsonObject3.getString("style"))) { - // 样式 id - int style = (int) jsonObject3.get("style"); - JSONObject jsonObject4 = (JSONObject) styles.get(style); - - if (!jsonObject4.containsKey("valign")) { - cellStyle.setVerticalAlignment(VerticalAlignment.valueOf("CENTER")); - } else { - String str1 = jsonObject4.getString("valign").toUpperCase(); - if ("MIDDLE".equals(str1)) { - str1 = "CENTER"; - } - cellStyle.setVerticalAlignment(VerticalAlignment.valueOf(str1)); - } - // 设置局中 - if (jsonObject4.containsKey("align")) { - String align = (String) jsonObject4.get("align"); - cellStyle.setAlignment(HorizontalAlignment.valueOf(align.toUpperCase())); - - } - - //------------------------bgColor - if (jsonObject4.containsKey("bgcolor")) { - - String str1 = jsonObject4.getString("bgcolor"); - XSSFColor xSSFColor = new XSSFColor(); - if (str1.indexOf("#") != -1) { - byte[] arrayOfByte = {(byte) Integer.parseInt(str1.substring(1, 3), 16), (byte) Integer.parseInt(str1.substring(3, 5), 16), (byte) Integer.parseInt(str1.substring(5, 7), 16)}; - xSSFColor.setRGB(arrayOfByte); - } - cellStyle.setFillForegroundColor(xSSFColor); - cellStyle.setFillBackgroundColor(xSSFColor); - cellStyle.setFillPattern(FillPatternType.BIG_SPOTS); - } - - - if (jsonObject4.containsKey("format")) { - String format = (String) jsonObject4.get("format"); - if(text instanceof String){ - switch (format) { - case "formula": - // 函数 - cell.setCellType(CellType.FORMULA); - break; - case "rmb": - //货币 - if (StringUtils.isNotBlank(cellValue)) { - try { - - cell.setCellValue(Integer.parseInt(cellValue)); - XSSFDataFormat xssfDataFormat = workbook.createDataFormat(); - cellStyle.setDataFormat(xssfDataFormat.getFormat("¥#,##0_);\\[Red](¥#,##0)")); - cell.setCellStyle(cellStyle); - } catch (Exception e) { - } - } - break; - case "number": - // 数值 - if (StringUtils.isNotBlank(cellValue)) { - - try { - cell.setCellValue(Integer.parseInt(cellValue)); - cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00")); - cell.setCellStyle(cellStyle); - - } catch (Exception e) { - } - } - break; - case "date": - - break; - case "date2": - - break; - case "time": - - break; - case "datetime": - - break; - case "percent": - //百分比 - if (StringUtils.isNotBlank(cellValue)) { - - try { - cell.setCellValue(Integer.parseInt(cellValue) / 100); - cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%")); - cell.setCellStyle(cellStyle); - - } catch (Exception e) { - } - } - break; - case "eur": - //欧元 - if (StringUtils.isNotBlank(cellValue)) { -// - try { - - cell.setCellValue(Integer.parseInt(cellValue)); - XSSFDataFormat xssfDataFormat = workbook.createDataFormat(); - cellStyle.setDataFormat(xssfDataFormat.getFormat("€#,##0_);\\[Red](¥#,##0)")); - cell.setCellStyle(cellStyle); - - } catch (Exception e) { - } - } - break; - case "usd": - //美元 - if (StringUtils.isNotBlank(cellValue)) { -// - try { - cell.setCellValue(Integer.parseInt(cellValue)); - XSSFDataFormat xssfDataFormat = workbook.createDataFormat(); - cellStyle.setDataFormat(xssfDataFormat.getFormat("$#,##0_);\\[Red](¥#,##0)")); - cell.setCellStyle(cellStyle); - - } catch (Exception e) { - } - } - break; - default: - cell.setCellType(CellType.STRING); - - } - } - } -// ------------------------------border-------------------------- - if (jsonObject4.containsKey("border")) { - JSONObject borders = (JSONObject) jsonObject4.get("border"); - - Iterator borderIterator = borders.keySet().iterator(); - while (borderIterator.hasNext()) { - String borderSide = borderIterator.next(); - // 设置单元格的边框 - switch (borderSide) { - case "top": - JSONArray top = borders.getJSONArray("top"); - tracingBorder(BorderStyle.valueOf(top.get(0).toString().toUpperCase()).getCode(), "top", cellStyle); - case "left": - JSONArray left = borders.getJSONArray("left"); - tracingBorder(BorderStyle.valueOf(left.get(0).toString().toUpperCase()).getCode(), "left", cellStyle); - case "bottom": - JSONArray bottom = borders.getJSONArray("bottom"); - tracingBorder(BorderStyle.valueOf(bottom.get(0).toString().toUpperCase()).getCode(), "bottom", cellStyle); - case "right": - JSONArray right = borders.getJSONArray("right"); - tracingBorder(BorderStyle.valueOf(right.get(0).toString().toUpperCase()).getCode(), "right", cellStyle); - } - } - } - - if (jsonObject4.containsKey("font") || jsonObject4.containsKey("underline") || jsonObject4.containsKey("strike") || jsonObject4.containsKey("color")) { - XSSFFont xSSFFont = workbook.createFont(); - - //------------------------------font-------------------------- - JSONObject fontObj = (JSONObject) jsonObject4.get("font"); - Object object1 = jsonObject4.get("underline"); - Object object2 = jsonObject4.get("strike"); - if (null != fontObj) { - if (fontObj.containsKey("name")) { - xSSFFont.setFontName(fontObj.getString("name")); - } - if (fontObj.containsKey("italic")) { - xSSFFont.setItalic(true); - } - if (fontObj.containsKey("size")) { - xSSFFont.setFontHeightInPoints(fontObj.getShort("size").shortValue()); - } - if (fontObj.containsKey("bold")) { - boolean bool = fontObj.getBoolean("bold").booleanValue(); - xSSFFont.setBold(bool); - } - } - - if (null != object1) { - xSSFFont.setUnderline((byte) 1); - } - if (null != object2) { - xSSFFont.setStrikeout(true); - } - - //------------------------------color-------------------------- - if (jsonObject4.containsKey("color")) { - String colorStr = jsonObject4.getString("color"); - XSSFColor xssfColor = new XSSFColor(); - - if (colorStr.length() > 6) { - if (colorStr.contains("rgb")) { - colorStr = colorStr.replace("rgb", "").replace("(", "").replace(")", ""); - String[] arrayOfString = colorStr.split(","); - if (arrayOfString.length == 3) { - byte[] arrayOfByte = {(byte) Integer.parseInt(arrayOfString[0]), (byte) Integer.parseInt(arrayOfString[1]), (byte) Integer.parseInt(arrayOfString[2])}; - xssfColor.setRGB(arrayOfByte); - } - } else if (colorStr.contains("#")) { - byte[] arrayOfByte = {(byte) Integer.parseInt(colorStr.substring(1, 3), 16), (byte) Integer.parseInt(colorStr.substring(3, 5), 16), (byte) Integer.parseInt(colorStr.substring(5, 7), 16)}; - xssfColor.setRGB(arrayOfByte); - } - } - xSSFFont.setColor(xssfColor); - } - cellStyle.setFont(xSSFFont); - - } - cellStyle.setWrapText(true); - cell.setCellStyle((cellStyle)); - - } - - - } - } - - - /** - * @param borderCode BordetStyle 枚举值 - * @param border top、right、bottom 、left - * @param cellStyle - */ - public static void tracingBorder(int borderCode, String border, XSSFCellStyle cellStyle) { - - switch (borderCode) { - case 0: - switch (border) { - case "top": - cellStyle.setBorderTop(BorderStyle.NONE); - break; - case "left": - cellStyle.setBorderLeft(BorderStyle.NONE); - break; - case "bottom": - cellStyle.setBorderBottom(BorderStyle.NONE); - break; - case "right": - cellStyle.setBorderRight(BorderStyle.NONE); - break; - default: - break; - } - break; - case 1: - switch (border) { - case "top": - cellStyle.setBorderTop(BorderStyle.THIN); - break; - case "left": - cellStyle.setBorderLeft(BorderStyle.THIN); - break; - case "bottom": - cellStyle.setBorderBottom(BorderStyle.THIN); - break; - case "right": - cellStyle.setBorderRight(BorderStyle.THIN); - break; - default: - break; - } - break; - case 2: - switch (border) { - case "top": - cellStyle.setBorderTop(BorderStyle.MEDIUM); - break; - case "left": - cellStyle.setBorderLeft(BorderStyle.MEDIUM); - break; - case "bottom": - cellStyle.setBorderBottom(BorderStyle.MEDIUM); - break; - case "right": - cellStyle.setBorderRight(BorderStyle.MEDIUM); - break; - default: - break; - } - break; - case 3: - switch (border) { - case "top": - cellStyle.setBorderTop(BorderStyle.DASHED); - break; - case "left": - cellStyle.setBorderLeft(BorderStyle.DASHED); - break; - case "bottom": - cellStyle.setBorderBottom(BorderStyle.DASHED); - break; - case "right": - cellStyle.setBorderRight(BorderStyle.DASHED); - break; - default: - break; - } - break; - case 4: - cellStyle.setBorderBottom(BorderStyle.DOTTED); - break; - case 5: - cellStyle.setBorderBottom(BorderStyle.THICK); - break; - case 6: - cellStyle.setBorderBottom(BorderStyle.DOUBLE); - break; - case 7: - cellStyle.setBorderBottom(BorderStyle.HAIR); - break; - case 8: - cellStyle.setBorderBottom(BorderStyle.MEDIUM_DASHED); - break; - case 9: - cellStyle.setBorderBottom(BorderStyle.DASH_DOT); - break; - case 10: - cellStyle.setBorderBottom(BorderStyle.MEDIUM_DASH_DOT); - break; - case 11: - cellStyle.setBorderBottom(BorderStyle.DASH_DOT_DOT); - break; - case 12: - cellStyle.setBorderBottom(BorderStyle.MEDIUM_DASH_DOT_DOT); - break; - case 13: - cellStyle.setBorderBottom(BorderStyle.SLANTED_DASH_DOT); - break; - default: - break; - } - } - - /** - * 导出excel生成图片 - * @param photos 图片数组 - * @param workbook - * @param sheet - * @throws Exception - */ - public static void makePhoto(JSONArray photos, Workbook workbook, XSSFSheet sheet) throws Exception { - ByteArrayOutputStream byteArrayOut = null; - for (int i = 0; i < photos.size(); i++) { - JSONObject qrCodeJson = (JSONObject) photos.get(i); - - if(qrCodeJson.get("type").toString().equals("QRCode")){ - // 二维码 - byteArrayOut = QrCodeOrBarCodeUtil.encodeQRCode - (qrCodeJson.getString("content"), "", qrCodeJson.getInteger("width"), qrCodeJson.getInteger("height")); - - }else if(qrCodeJson.get("type").toString().equals("BarCode")){ - // 条形码 - byteArrayOut = QrCodeOrBarCodeUtil.encodeBarCode - (qrCodeJson.getString("content"), qrCodeJson.getInteger("width"), qrCodeJson.getInteger("height")); - - } - - XSSFRow row = null; - if(sheet.getRow(qrCodeJson.getInteger("ri")) == null){ - row = sheet.createRow(qrCodeJson.getInteger("ri")); - row.setHeight((short) 360); - } else { - row = sheet.getRow(qrCodeJson.getInteger("ri")); - } - - // 原图片宽高。 - double imageWidth = qrCodeJson.getInteger("width"); - double imageHeight = qrCodeJson.getInteger("height"); - - // 列宽像素 - double cellWidth = sheet.getColumnWidthInPixels(qrCodeJson.getInteger("ci")); - // getHeightInPoints()方法获取的是点(磅),就是excel设置的行高,1英寸有72磅,一般显示屏一英寸是96个像素: 行高像素 - double cellHeight = row.getHeightInPoints() / 72 * 96; - - // 图片宽 / 列宽 - double cellWidthD = imageWidth / cellWidth; - int cellWidthI= (int) cellWidthD; - - // 图片高 / 列高 - double rowHeightD = imageHeight / cellHeight; - int rowHeightDI = (int) rowHeightD; - // 1023、255 为宽高 此从第r行、c列开始 、、、 扩充到 r+rowHeightDI行、c+cellWidthI列 -// XSSFClientAnchor anchor = new XSSFClientAnchor -// (0,0,1025,255, -// qrCodeJson.getInteger("ci"), -// row.getRowNum(), -// qrCodeJson.getInteger("ci")+ (cellWidthI == 0 ? 1 : cellWidthI), -// row.getRowNum() + (rowHeightDI == 0 ? 1 : rowHeightDI)); -// anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE); -// //画图器 一个sheet只能一个 - XSSFDrawing drawing = sheet.createDrawingPatriarch(); -// drawing.createPicture(anchor , workbook.addPicture(byteArrayOut.toByteArray() , XSSFWorkbook.PICTURE_TYPE_PNG)); - - - CreationHelper helper = workbook.getCreationHelper(); - int jdpictureIdx = workbook.addPicture(byteArrayOut.toByteArray(), Workbook.PICTURE_TYPE_JPEG);// 根据需要调整参数,如果是PNG,就改为 Workbook.PICTURE_TYPE_PNG - // 插入图片,如果原图宽度大于最终要求的图片宽度,就按比例缩小,否则展示原图 - ClientAnchor jdanchor = helper.createClientAnchor(); - // 起始画图的行列。 - jdanchor.setCol1(qrCodeJson.getInteger("ci")); - jdanchor.setRow1(row.getRowNum()); - Picture pict = drawing.createPicture(jdanchor, jdpictureIdx); - pict.resize(); - } - } -} diff --git a/report-core/src/main/resources/mapper/ReportExcelMapper.xml b/report-core/src/main/resources/mapper/ReportExcelMapper.xml deleted file mode 100644 index 41a7bcf8..00000000 --- a/report-core/src/main/resources/mapper/ReportExcelMapper.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/report-ui/config/dev.env.js b/report-ui/config/dev.env.js index f50fc84e..ee3d90dc 100644 --- a/report-ui/config/dev.env.js +++ b/report-ui/config/dev.env.js @@ -4,6 +4,6 @@ const prodEnv = require('./prod.env') module.exports = merge(prodEnv, { NODE_ENV: '"development"', - // BASE_API: '"http://127.0.0.1:9095"' - BASE_API: '"http://10.108.26.197:9095"' + BASE_API: '"http://127.0.0.1:9095"' + // BASE_API: '"http://10.108.26.197:9095"' }) From 276ab15b7a08d1385e112db5167fe824bf4292f0 Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Mon, 28 Jun 2021 16:21:03 +0800 Subject: [PATCH 2/6] createBy updateBy --- report-ui/src/views/report/datasource/index.vue | 4 ++-- report-ui/src/views/report/report/index.vue | 8 ++++---- report-ui/src/views/report/resultset/index.vue | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/report-ui/src/views/report/datasource/index.vue b/report-ui/src/views/report/datasource/index.vue index aff95123..7ccfd658 100644 --- a/report-ui/src/views/report/datasource/index.vue +++ b/report-ui/src/views/report/datasource/index.vue @@ -88,13 +88,13 @@ label="数据源名称[编码]" /> - - - --> - - @@ -408,4 +408,4 @@ export default { }, }, } - \ No newline at end of file + diff --git a/report-ui/src/views/report/resultset/index.vue b/report-ui/src/views/report/resultset/index.vue index 9e1a79e1..37ee4ca7 100644 --- a/report-ui/src/views/report/resultset/index.vue +++ b/report-ui/src/views/report/resultset/index.vue @@ -78,13 +78,13 @@ 查看 - - - + + diff --git a/report-ui/src/views/report/bigscreen/designer/widget/widget.vue b/report-ui/src/views/report/bigscreen/designer/widget/widget.vue index 29c747b2..a0d37ee2 100644 --- a/report-ui/src/views/report/bigscreen/designer/widget/widget.vue +++ b/report-ui/src/views/report/bigscreen/designer/widget/widget.vue @@ -36,6 +36,7 @@ import WidgetPiechart from "./widgetPiechart.vue"; import WidgetHollowPiechart from "./widgetHollowPiechart.vue"; import WidgetFunnel from "./widgetFunnel.vue"; import WidgetGauge from "./widgetGauge.vue"; +import WidgetPieNightingaleRoseArea from "./pie/widgetPieNightingaleRoseArea"; export default { name: "Widget", components: { @@ -54,7 +55,8 @@ export default { WidgetPiechart, WidgetHollowPiechart, WidgetFunnel, - WidgetGauge + WidgetGauge, + WidgetPieNightingaleRoseArea }, model: { prop: "value", From bec50fadaaa84f7b5abdedf0923595ecd11b5537 Mon Sep 17 00:00:00 2001 From: yanzili <978387851@qq.com> Date: Mon, 28 Jun 2021 16:55:10 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E7=99=BB=E5=BD=95=20token=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- report-ui/src/api/axios.js | 7 ++---- report-ui/src/router/index.js | 2 +- report-ui/src/utils/request.js | 41 +++++++++++++++++----------------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/report-ui/src/api/axios.js b/report-ui/src/api/axios.js index 46bae2f4..fd56f807 100644 --- a/report-ui/src/api/axios.js +++ b/report-ui/src/api/axios.js @@ -17,13 +17,10 @@ service.interceptors.request.use( config => { // 在发送请求之前做些什么 var token = getItem('token'); - // config = signUtil.sign(token, deepClone(config)); - console.log(config, 'config') return config }, error => { - // Do something with request error - console.log(error) // for debug + // Do something with request error Promise.reject(error) } ) @@ -35,6 +32,7 @@ service.interceptors.response.use( if (res.code == 200) { return res } + else if (res.code == '50014') { //登录超时或被登出,弹确认框,用户确认后,跳转到登录页面 MessageBox({ @@ -45,7 +43,6 @@ service.interceptors.response.use( sessionStorage.clear(); localStorage.clear(); delItem('token') - // location.reload(); window.location.href = "/"; }).catch(err => { }) diff --git a/report-ui/src/router/index.js b/report-ui/src/router/index.js index d2c62820..1e4977fc 100644 --- a/report-ui/src/router/index.js +++ b/report-ui/src/router/index.js @@ -98,7 +98,7 @@ export const constantRouterMap = [ // ] // }, { path: '/404', component: () => import('@/views/404'), hidden: true }, - { path: '*', redirect: '/index', hidden: true }, + { path: '*', redirect: '/login', hidden: true }, ] export default new Router({ diff --git a/report-ui/src/utils/request.js b/report-ui/src/utils/request.js index 5c263a8b..81b3eae8 100644 --- a/report-ui/src/utils/request.js +++ b/report-ui/src/utils/request.js @@ -2,7 +2,6 @@ import axios from 'axios' import { Message, MessageBox } from 'element-ui' import store from '../store' import { getToken } from '@/utils/auth' - // 创建axios实例 const service = axios.create({ baseURL: process.env.BASE_API, // api 的 base_url @@ -17,7 +16,6 @@ service.interceptors.request.use( }, error => { // Do something with request error - console.log(error) // for debug Promise.reject(error) } ) @@ -29,36 +27,37 @@ service.interceptors.response.use( * code为非20000是抛错 可结合自己业务进行修改 */ const res = response.data - if (res.code !== '200') { + // 50008:非法的token; 50012:其他客户端登录了; 50014:Token 过期了; + if (res.code == '50008' || res.code == '50012' || res.code == '50014') { + MessageBox.confirm( + '你已被登出,可以取消继续留在该页面,或者重新登录', + '重新登录', + { + confirmButtonText: '重新登录', + cancelButtonText: '取消', + type: 'warning' + } + ).then(() => { + // store.dispatch('FedLogOut').then(() => { + // // location.reload() // 为了重新实例化vue-router对象 避免bug + // window.location.href = "/"; + // }) + location.reload(); + window.location.href = "/"; + }) + } + else if (res.code !== '200') { Message({ message: res.message, type: 'error', duration: 5 * 1000 }) - - // 50008:非法的token; 50012:其他客户端登录了; 50014:Token 过期了; - if (res.code === 50008 || res.code === 50012 || res.code === 50014) { - MessageBox.confirm( - '你已被登出,可以取消继续留在该页面,或者重新登录', - '确定登出', - { - confirmButtonText: '重新登录', - cancelButtonText: '取消', - type: 'warning' - } - ).then(() => { - store.dispatch('FedLogOut').then(() => { - location.reload() // 为了重新实例化vue-router对象 避免bug - }) - }) - } return Promise.reject('error') } else { return response.data } }, error => { - console.log('err' + error) // for debug Message({ message: error.message, type: 'error', From fee68de5515d8e3130ab89398f76f99de9870911 Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Mon, 28 Jun 2021 17:56:14 +0800 Subject: [PATCH 6/6] WidgetGradientColorBarchart --- .../views/report/bigscreen/designer/tools.js | 550 ++++++------------ .../bar/widgetGradientColorBarchart.vue | 42 +- 2 files changed, 208 insertions(+), 384 deletions(-) diff --git a/report-ui/src/views/report/bigscreen/designer/tools.js b/report-ui/src/views/report/bigscreen/designer/tools.js index 9442d7c8..2febb36f 100644 --- a/report-ui/src/views/report/bigscreen/designer/tools.js +++ b/report-ui/src/views/report/bigscreen/designer/tools.js @@ -1506,14 +1506,6 @@ const widgetTools = [ placeholder: '', value: '柱状图', }, - { - type: 'el-switch', - label: '竖展示', - name: 'verticalShow', - required: false, - placeholder: '', - value: false, - }, { type: 'vue-color', label: '背景颜色', @@ -1523,35 +1515,6 @@ const widgetTools = [ value: '' }, [ - // { - // name: '柱体设置', - // list: [ - // { - // type: 'el-slider', - // label: '最大宽度', - // name: 'maxWidth', - // required: false, - // placeholder: '', - // value: 10, - // }, - // { - // type: 'el-slider', - // label: '圆角', - // name: 'radius', - // require: false, - // placeholder: '', - // value: 5, - // }, - // { - // type: 'el-slider', - // label: '最小高度', - // name: 'minHeight', - // require: false, - // placeholder: '', - // value: 0, - // }, - // ], - // }, { name: '标题设置', list: [ @@ -1654,325 +1617,200 @@ const widgetTools = [ }, ], }, - // { - // name: 'X轴设置', - // list: [ - // { - // type: 'el-input-text', - // label: '名称', - // name: 'xName', - // required: false, - // placeholder: '', - // value: '' - // }, - // { - // type: 'el-switch', - // label: '显示', - // name: 'hideX', - // required: false, - // placeholder: '', - // value: true, - // }, - // { - // type: 'vue-color', - // label: '坐标名颜色', - // name: 'xNameColor', - // required: false, - // placeholder: '', - // value: '#fff' - // }, - // { - // type: 'el-input-number', - // label: '字体大小', - // name: 'xNameFontSize', - // required: false, - // placeholder: '', - // value: 12 - // }, - // { - // type: 'el-slider', - // label: '文字角度', - // name: 'textAngle', - // required: false, - // placeholder: '', - // value: 0 - // }, - // { - // type: 'el-input-number', - // label: '文字间隔', - // name: 'textInterval', - // required: false, - // placeholder: '', - // value: '' - // }, - // { - // type: 'el-switch', - // label: '轴反转', - // name: 'reversalX', - // required: false, - // placeholder: '', - // value: '' - // }, - // { - // type: 'vue-color', - // label: '颜色', - // name: 'Xcolor', - // required: false, - // placeholder: '', - // value: '#fff', - // }, - // { - // type: 'el-input-number', - // label: '字号', - // name: 'fontSizeX', - // required: false, - // placeholder: '', - // value: 12, - // }, - // ], - // }, - // { - // name: 'Y轴设置', - // list: [ - // { - // type: 'el-input-text', - // label: '名称', - // name: 'textNameY', - // require: false, - // placeholder: '', - // value: '' - // }, - // { - // type: 'el-switch', - // label: '显示', - // name: 'isShowY', - // require: false, - // placeholder: '', - // value: true, - // }, - // { - // type: 'vue-color', - // label: '坐标名颜色', - // name: 'NameColorY', - // required: false, - // placeholder: '', - // value: '#fff', - // }, - // { - // type: 'el-input-number', - // label: '字体大小', - // name: 'NameFontSizeY', - // required: false, - // placeholder: '', - // value: 12, - // }, - // { - // type: 'el-switch', - // label: '轴反转', - // name: 'reversalY', - // required: false, - // placeholder: '', - // value: false - // }, - // { - // type: 'vue-color', - // label: '颜色', - // name: 'colorY', - // required: false, - // placeholder: '', - // value: '#fff', - // }, - // { - // type: 'el-input-number', - // label: '字号', - // name: 'fontSizeY', - // required: false, - // placeholder: '', - // value: 12, - // }, - // ], - // }, - // { - // name: '数值设定', - // list: [ - // { - // type: 'el-switch', - // label: '显示', - // name: 'isShow', - // required: false, - // placeholder: '', - // value: false - // }, - // { - // type: 'el-input-number', - // label: '字体大小', - // name: 'fontSize', - // required: false, - // placeholder: '', - // value: 14 - // }, - // { - // type: 'vue-color', - // label: '字体颜色', - // name: 'subTextColor', - // required: false, - // placeholder: '', - // value: '#fff' - // }, - // { - // type: 'el-select', - // label: '字体粗细', - // name: 'fontWeight', - // required: false, - // placeholder: '', - // selectOptions: [ - // { code: 'normal', name: '正常' }, - // { code: 'bold', name: '粗体' }, - // { code: 'bolder', name: '特粗体' }, - // { code: 'lighter', name: '细体' } - // ], - // value: 'normal' - // }, - // ], - // }, - // { - // name: '提示语设置', - // list: [ - // { - // type: 'el-input-number', - // label: '字体大小', - // name: 'fontSize', - // required: false, - // placeholder: '', - // }, - // { - // type: 'vue-color', - // label: '字体颜色', - // name: 'lineColor', - // required: false, - // placeholder: '', - // }, - // ], - // }, - // { - // name: '坐标轴边距设置', - // list: [ - // { - // type: 'el-slider', - // label: '左边距(像素)', - // name: 'marginLeft', - // required: false, - // placeholder: '', - // value: 10, - // }, { - // type: 'el-slider', - // label: '顶边距(像素)', - // name: 'marginTop', - // required: false, - // placeholder: '', - // value: 50, - // }, { - // type: 'el-slider', - // label: '右边距(像素)', - // name: 'marginRight', - // required: false, - // placeholder: '', - // value: 40, - // }, { - // type: 'el-slider', - // label: '底边距(像素)', - // name: 'marginBottom', - // required: false, - // placeholder: '', - // value: 10, - // }, - // ], - // }, - // { - // name: '图例操作', - // list: [ - // { - // type: 'el-switch', - // label: '图例', - // name: 'isShowLegend', - // required: false, - // placeholder: '', - // value: true, - // }, - // { - // type: 'vue-color', - // label: '字体颜色', - // name: 'lengedColor', - // required: false, - // placeholder: '', - // value: '#fff', - // }, - // { - // type: 'el-input-number', - // label: '字体大小', - // name: 'lengedFontSize', - // required: false, - // placeholder: '', - // value: 16, - // }, - // { - // type: 'el-input-number', - // label: '图例宽度', - // name: 'lengedWidth', - // required: false, - // placeholder: '', - // value: 15, - // }, - // { - // type: 'el-select', - // label: '横向位置', - // name: 'lateralPosition', - // required: false, - // placeholder: '', - // selectOptions: [ - // { code: 'left', name: '左对齐' }, - // { code: 'right', name: '右对齐' }, - // ], - // value: '' - // }, - // { - // type: 'el-select', - // label: '纵向位置', - // name: 'longitudinalPosition', - // required: false, - // placeholder: '', - // selectOptions: [ - // { code: 'top', name: '顶部' }, - // { code: 'bottom', name: '底部' }, - // ], - // value: '' - // }, - // { - // type: 'el-select', - // label: '布局前置', - // name: 'layoutFront', - // required: false, - // placeholder: '', - // selectOptions: [ - // { code: 'vertical', name: '竖排' }, - // { code: 'horizontal', name: '横排' }, - // ], - // value: '' - // }, - // ], - // }, - // { - // name: '自定义配色', - // list: [ - // { - // type: 'customColor', - // label: '', - // name: 'customColor', - // required: false, - // value: [{ color: '#ff7f50' }, { color: '#87cefa' }, { color: '#da70d6' }, { color: '#32cd32' }, { color: '#6495ed' }], - // }, - // ], - // }, + { + name: 'X轴设置', + list: [ + { + type: 'el-input-text', + label: '名称', + name: 'xName', + required: false, + placeholder: '', + value: '' + }, + { + type: 'el-switch', + label: '显示', + name: 'hideX', + required: false, + placeholder: '', + value: true, + }, + { + type: 'vue-color', + label: '坐标名颜色', + name: 'xNameColor', + required: false, + placeholder: '', + value: '#fff' + }, + { + type: 'el-input-number', + label: '字体大小', + name: 'xNameFontSize', + required: false, + placeholder: '', + value: 12 + }, + { + type: 'el-slider', + label: '文字角度', + name: 'textAngle', + required: false, + placeholder: '', + value: 0 + }, + { + type: 'el-input-number', + label: '文字间隔', + name: 'textInterval', + required: false, + placeholder: '', + value: '' + }, + { + type: 'el-switch', + label: '轴反转', + name: 'reversalX', + required: false, + placeholder: '', + value: '' + }, + { + type: 'vue-color', + label: '颜色', + name: 'Xcolor', + required: false, + placeholder: '', + value: '#fff', + }, + { + type: 'el-input-number', + label: '字号', + name: 'fontSizeX', + required: false, + placeholder: '', + value: 12, + }, + ], + }, + { + name: 'Y轴设置', + list: [ + { + type: 'el-input-text', + label: '名称', + name: 'textNameY', + require: false, + placeholder: '', + value: '' + }, + { + type: 'el-switch', + label: '显示', + name: 'isShowY', + require: false, + placeholder: '', + value: true, + }, + { + type: 'vue-color', + label: '坐标名颜色', + name: 'NameColorY', + required: false, + placeholder: '', + value: '#fff', + }, + { + type: 'el-input-number', + label: '字体大小', + name: 'NameFontSizeY', + required: false, + placeholder: '', + value: 12, + }, + { + type: 'el-switch', + label: '轴反转', + name: 'reversalY', + required: false, + placeholder: '', + value: false + }, + { + type: 'vue-color', + label: '颜色', + name: 'colorY', + required: false, + placeholder: '', + value: '#fff', + }, + { + type: 'el-input-number', + label: '字号', + name: 'fontSizeY', + required: false, + placeholder: '', + value: 12, + }, + ], + }, + { + name: '坐标轴边距设置', + list: [ + { + type: 'el-slider', + label: '左边距(像素)', + name: 'marginLeft', + required: false, + placeholder: '', + value: 10, + }, { + type: 'el-slider', + label: '顶边距(像素)', + name: 'marginTop', + required: false, + placeholder: '', + value: 50, + }, { + type: 'el-slider', + label: '右边距(像素)', + name: 'marginRight', + required: false, + placeholder: '', + value: 40, + }, { + type: 'el-slider', + label: '底边距(像素)', + name: 'marginBottom', + required: false, + placeholder: '', + value: 10, + }, + ], + }, + { + name: '渐变色', + list: [ + { + type: 'vue-color', + label: '0%处', + name: 'barStart', + required: false, + placeholder: '', + value: '#00F4FFFF' + }, + { + type: 'vue-color', + label: '100%处', + name: 'barEnd', + required: false, + placeholder: '', + value: '#004DA7FF' + }, + + ], + }, ], ], // 数据 diff --git a/report-ui/src/views/report/bigscreen/designer/widget/bar/widgetGradientColorBarchart.vue b/report-ui/src/views/report/bigscreen/designer/widget/bar/widgetGradientColorBarchart.vue index 195c5181..e88f76a2 100644 --- a/report-ui/src/views/report/bigscreen/designer/widget/bar/widgetGradientColorBarchart.vue +++ b/report-ui/src/views/report/bigscreen/designer/widget/bar/widgetGradientColorBarchart.vue @@ -16,7 +16,7 @@ data() { return { options: { - backgroundColor: '#00265f', + // backgroundColor: '#00265f', "title": { "text": "政策补贴额度", x: "center", @@ -176,13 +176,13 @@ // 修改图标options属性 editorOptions() { this.setOptionsTitle() - // this.setOptionsX() - // this.setOptionsY() + this.setOptionsX() + this.setOptionsY() // this.setOptionsTop() // this.setOptionsTooltip() - // this.setOptionsMargin() + this.setOptionsMargin() // this.setOptionsLegend() - // this.setOptionsColor() + this.setOptionsColor() this.setOptionsData() }, // 标题修改 @@ -331,29 +331,17 @@ } legend.itemWidth = optionsCollapse.lengedWidth }, - // 图例颜色修改 + // 渐变色 setOptionsColor() { const optionsCollapse = this.optionsSetup - const customColor = optionsCollapse.customColor - if (!customColor) return - const arrColor = [] - for (let i = 0; i < customColor.length; i++) { - arrColor.push(customColor[i].color) - } - const itemStyle = { - normal: { - color: (params) => { - return arrColor[params.dataIndex] - }, - barBorderRadius: optionsCollapse.radius, - }, - } - for (const key in this.options.series) { - if (this.options.series[key].type == 'bar') { - this.options.series[key].itemStyle = itemStyle - } - } - this.options = Object.assign({}, this.options) + const barStart = {} + barStart['offset'] = 0 + barStart['color'] = optionsCollapse.barStart + const barEnd = {} + barStart['offset'] = 1 + barStart['color'] = optionsCollapse.barEnd + // this.options.series[0].itemStyle.normal.color = new echarts.graphic.LinearGradient(0, 0, 0, 1,[ barStart, barEnd], false) + }, // 数据解析 setOptionsData() { @@ -419,8 +407,6 @@ .echarts { width: 100%; height: 100%; - min-width: 200px; - min-height: 200px; overflow: hidden; }