Commit a3e21667 authored by yuanshuo's avatar yuanshuo

Merge branch 'master' of...

Merge branch 'master' of http://gitlab.91isoft.com:90/car-database/car-database-api into songyuanshuo
parents 7fc21b5f dc63cd7d
package com.ruoyi.domain.vo;
import com.ruoyi.common.annotation.Excel;
import lombok.Data;
@Data
public class RecaordUseCasesReportVO {
@Excel(name = "标准章节号")
private String serialNumber;
@Excel(name = "标准要求")
private String requirements;
@Excel(name = "用例编号")
private String customizedID;
@Excel(name = "用例描述")
private String description;
}
package com.ruoyi.domain.vo;
import com.ruoyi.common.annotation.Excel;
import lombok.Data;
@Data
public class SystemReviewExportVO {
@Excel(name = "标准章节号")
private String chapter;
@Excel(name = "标准要求")
private String reviewStandard;
@Excel(name = "审查要点")
private String reviewKeyPoint;
@Excel(name = "审查细则")
private String reviewDetails;
@Excel(name = "审查场景")
private String reviewScene;
}
...@@ -2,8 +2,11 @@ package com.ruoyi.mapper; ...@@ -2,8 +2,11 @@ package com.ruoyi.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.TTestPlanRecord; import com.ruoyi.domain.TTestPlanRecord;
import com.ruoyi.domain.vo.SystemReviewExportVO;
import com.ruoyi.web.request.SystemReviewExportRequest;
import com.ruoyi.web.request.TestPlanRecordGetInfoRequest; import com.ruoyi.web.request.TestPlanRecordGetInfoRequest;
import com.ruoyi.web.request.TestPlanRecordPageRequest; import com.ruoyi.web.request.TestPlanRecordPageRequest;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
...@@ -25,6 +28,8 @@ public interface TTestPlanRecordMapper extends BaseMapper<TTestPlanRecord> { ...@@ -25,6 +28,8 @@ public interface TTestPlanRecordMapper extends BaseMapper<TTestPlanRecord> {
public int updateTestPlanRecord(TestPlanRecordGetInfoRequest testPlanRecordGetInfoRequest); public int updateTestPlanRecord(TestPlanRecordGetInfoRequest testPlanRecordGetInfoRequest);
public List<SystemReviewExportVO> systemReviewExport(@Param("standardId") Long standardId, @Param("type") String type);
} }
......
package com.ruoyi.web; package com.ruoyi.web;
import com.alibaba.fastjson2.JSONObject; import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelMultipleSheetsUtil;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.ReviewStandard; import com.ruoyi.domain.ReviewStandard;
import com.ruoyi.domain.TTestPlanRecord; import com.ruoyi.domain.TTestPlanRecord;
import com.ruoyi.domain.vo.ItemsByUseCaseVO; import com.ruoyi.domain.vo.ItemsByUseCaseVO;
import com.ruoyi.domain.vo.RecaordUseCasesReportVO;
import com.ruoyi.domain.vo.RecaordUseCasesVO; import com.ruoyi.domain.vo.RecaordUseCasesVO;
import com.ruoyi.mapper.TTestPlanRecordMapper; import com.ruoyi.mapper.TTestPlanRecordMapper;
import com.ruoyi.service.TTestPlanRecordService; import com.ruoyi.service.TTestPlanRecordService;
import com.ruoyi.service.impl.ReviewStandardServiceImpl; import com.ruoyi.service.impl.ReviewStandardServiceImpl;
import com.ruoyi.web.request.PlanDetailStandardRequest; import com.ruoyi.web.request.PlanDetailStandardRequest;
import com.ruoyi.web.request.SystemReviewExportRequest;
import com.ruoyi.web.request.TestPlanRecordGetInfoRequest; import com.ruoyi.web.request.TestPlanRecordGetInfoRequest;
import com.ruoyi.web.request.TestPlanRecordPageRequest; import com.ruoyi.web.request.TestPlanRecordPageRequest;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import okhttp3.*;
import org.apache.skywalking.apm.toolkit.trace.Tag; import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags; import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace; import org.apache.skywalking.apm.toolkit.trace.Trace;
...@@ -31,14 +34,14 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -31,14 +34,14 @@ import org.springframework.web.bind.annotation.RequestBody;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.List;
@Api(tags = "检测方案记录") @Api(tags = "检测方案记录")
@RestController @RestController
@RequestMapping("/Plan/Record") @RequestMapping("/Plan/Record")
public class TestPlanRecordController extends BaseController{ public class TestPlanRecordController extends BaseController{
private static final String XLSX_SUFFIX = ".xlsx";
@Autowired @Autowired
private TTestPlanRecordService tTestPlanRecordService; private TTestPlanRecordService tTestPlanRecordService;
...@@ -72,7 +75,6 @@ public class TestPlanRecordController extends BaseController{ ...@@ -72,7 +75,6 @@ public class TestPlanRecordController extends BaseController{
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")}) @Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@RequestMapping(method = RequestMethod.POST, value = "/standard") @RequestMapping(method = RequestMethod.POST, value = "/standard")
public R<List<ReviewStandard>> selectStandarDetails(@Validated @RequestBody PlanDetailStandardRequest planDetailStandardRequest){ public R<List<ReviewStandard>> selectStandarDetails(@Validated @RequestBody PlanDetailStandardRequest planDetailStandardRequest){
System.out.println("planDetailStandardRequest = " + planDetailStandardRequest);
List<ReviewStandard> tree = reviewStandardService.findTree(planDetailStandardRequest.getInspectionStandardId(), planDetailStandardRequest.getType()); List<ReviewStandard> tree = reviewStandardService.findTree(planDetailStandardRequest.getInspectionStandardId(), planDetailStandardRequest.getType());
return R.ok(tree); return R.ok(tree);
} }
...@@ -91,7 +93,7 @@ public class TestPlanRecordController extends BaseController{ ...@@ -91,7 +93,7 @@ public class TestPlanRecordController extends BaseController{
@Trace @Trace
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")}) @Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@RequestMapping(method = RequestMethod.POST, value = "/update") @RequestMapping(method = RequestMethod.POST, value = "/update")
public R<Integer> updateTestPlanRecord(TestPlanRecordGetInfoRequest testPlanRecordGetInfoRequest){ public R<Integer> updateTestPlanRecord(@Validated @RequestBody TestPlanRecordGetInfoRequest testPlanRecordGetInfoRequest){
return R.ok(tTestPlanRecordService.updateTestPlanRecord(testPlanRecordGetInfoRequest)); return R.ok(tTestPlanRecordService.updateTestPlanRecord(testPlanRecordGetInfoRequest));
} }
...@@ -129,4 +131,44 @@ public class TestPlanRecordController extends BaseController{ ...@@ -129,4 +131,44 @@ public class TestPlanRecordController extends BaseController{
util.exportExcel( respon, list, "用例编号"); util.exportExcel( respon, list, "用例编号");
// return R.ok(); // return R.ok();
} }
@RequestMapping(method = RequestMethod.POST, value = "/exportTo")
public void exportPlanRecordTo(HttpServletResponse respon, @Validated @RequestBody SystemReviewExportRequest systemReviewExportRequest) throws IOException{
List inspectionTtem = systemReviewExportRequest.getInspectionTtem();
Map<String, Object> result = new HashMap<>();
Boolean isPage = true;
inspectionTtem.forEach(item->{
if("sraif".equals(item)){
result.put(isPage ? "体系审查" : "sheet1名字", tTestPlanRecordMapper.systemReviewExport(systemReviewExportRequest.getInspectionStandardId(), "system") );
}
if ("grfis".equals(item)){
result.put(isPage ? "车型审查" : "sheet1名字", tTestPlanRecordMapper.systemReviewExport(systemReviewExportRequest.getInspectionStandardId(), "car") );
}
if ("trfis".equals(item)){
String params = JSON.toJSONString(systemReviewExportRequest.getCarExperimentRequest());
List<ItemsByUseCaseVO> listUseCase = new ArrayList<>();
try {
listUseCase = tTestPlanRecordService.getCarTestDetail(params);
} catch (IOException e) {
throw new RuntimeException(e);
}
List<RecaordUseCasesReportVO> list = new ArrayList<>();
listUseCase.forEach(itemS->{
itemS.getUseCases().forEach(data->{
RecaordUseCasesReportVO recaordUseCasesReportVO = new RecaordUseCasesReportVO();
recaordUseCasesReportVO.setDescription(itemS.getSerialNumber());
recaordUseCasesReportVO.setRequirements(itemS.getRequirements());
recaordUseCasesReportVO.setCustomizedID(data.getCustomizedID());
recaordUseCasesReportVO.setDescription(data.getDescription());
list.add(recaordUseCasesReportVO);
});
});
result.put(isPage ? "车型实验" : "sheet1名字", list );
}
});
ExcelMultipleSheetsUtil.excelMultipleSheets(result, "Excel数据" + DateUtil.format(new Date(), "yyyyMMddHHmmss"), XLSX_SUFFIX, respon);
}
} }
package com.ruoyi.web.request;
import lombok.Data;
import java.util.List;
@Data
public class CarExperimentRequest {
private String regulationName;
private List<String> matchUseCases;
}
package com.ruoyi.web.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author GaoYing
*/
@Data
@ApiModel("导出参数")
public class SystemReviewExportRequest {
@ApiModelProperty("检验项目")
private List<String> inspectionTtem;
// @ApiModelProperty("用例编号")
// private List<String> useCaseNo;
//
// @ApiModelProperty("标准")
// private String inspectionStandardName;
@ApiModelProperty("标准ID")
private Long inspectionStandardId;
@ApiModelProperty("车型实验json")
private CarExperimentRequest carExperimentRequest;
}
package com.ruoyi.web.request; package com.ruoyi.web.request;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
/**
* @author gaoying
*/
@Data @Data
@ApiModel @ApiModel
public class TestPlanRecordGetInfoRequest { public class TestPlanRecordGetInfoRequest {
@ApiModelProperty("ID") @ApiModelProperty("ID")
@TableId(type = IdType.ASSIGN_ID)
private Long id; private Long id;
/** /**
...@@ -15,4 +21,10 @@ public class TestPlanRecordGetInfoRequest { ...@@ -15,4 +21,10 @@ public class TestPlanRecordGetInfoRequest {
*/ */
@ApiModelProperty("文件路径") @ApiModelProperty("文件路径")
private String fileUrl; private String fileUrl;
/**
* 文件路径
*/
@ApiModelProperty("实验结果")
private String testResult;
} }
...@@ -74,7 +74,17 @@ ...@@ -74,7 +74,17 @@
update t_test_plan_record update t_test_plan_record
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="fileUrl != null">file_url = #{fileUrl},</if> <if test="fileUrl != null">file_url = #{fileUrl},</if>
<if test="testResult != null">test_result = #{testResult},</if>
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>
<select id="systemReviewExport" resultType="com.ruoyi.domain.vo.SystemReviewExportVO">
select trs.chapter,trs.text as reviewStandard,trk.text as reviewKeyPoint,trd.text as reviewDetails, trsc.text as reviewScene from t_standard ts
LEFT JOIN t_review_standard trs on trs.standard_id = ts.id
LEFT JOIN t_review_keypoint trk on trk.review_standard_id = trs.id
LEFT JOIN t_review_details trd on trd.review_keypoint_id = trk.id
LEFT JOIN t_review_scene trsc on trsc.review_details_id = trd.id
WHERE standard_id = #{standardId} AND type = #{type}
</select>
</mapper> </mapper>
...@@ -18,7 +18,7 @@ ruoyi: ...@@ -18,7 +18,7 @@ ruoyi:
# 开发环境配置 # 开发环境配置
server: server:
# 服务器的HTTP端口,默认为8080 # 服务器的HTTP端口,默认为8080
port: 22032 port: 22033
servlet: servlet:
# 应用的访问路径 # 应用的访问路径
context-path: / context-path: /
...@@ -72,7 +72,7 @@ spring: ...@@ -72,7 +72,7 @@ spring:
# 端口,默认为6379 # 端口,默认为6379
port: ${REDIS_PORT} port: ${REDIS_PORT}
# 数据库索引 # 数据库索引
database: 0 database: 1
# 密码 # 密码
password: ${REDIS_PWD} password: ${REDIS_PWD}
# 连接超时时间 # 连接超时时间
......
...@@ -18,7 +18,7 @@ ruoyi: ...@@ -18,7 +18,7 @@ ruoyi:
# 开发环境配置 # 开发环境配置
server: server:
# 服务器的HTTP端口,默认为8080 # 服务器的HTTP端口,默认为8080
port: 22008 port: 22033
servlet: servlet:
# 应用的访问路径 # 应用的访问路径
context-path: / context-path: /
...@@ -74,7 +74,7 @@ spring: ...@@ -74,7 +74,7 @@ spring:
# 端口,默认为6379 # 端口,默认为6379
port: 22012 port: 22012
# 数据库索引 # 数据库索引
database: 0 database: 1
# 密码 # 密码
password: password:
# 连接超时时间 # 连接超时时间
......
package com.ruoyi.common.utils.poi;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.utils.DictUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
import java.util.Map;
import static com.ruoyi.common.core.text.CharsetKit.UTF_8;
public class ExcelMultipleSheetsUtil {
/**
* 导出excel:可多个sheet页
*
* @param data 数据:Map 集合【key == 每一个sheet页的名称,value == sheet页数据】
* @param excelFileName excel文件名
* @param suffixName 后缀名
* @param response 响应
* @throws IOException 异常
*/
public static void excelMultipleSheets(Map<String, Object> data, String excelFileName, String suffixName, HttpServletResponse response) throws IOException {
// 创建工作簿
try (Workbook workbook = new XSSFWorkbook()) {
for (Map.Entry<String, Object> entry : data.entrySet()) {
String sheetName = entry.getKey();
Object sheetData = entry.getValue();
Sheet sheet = workbook.createSheet(sheetName);
if (ObjectUtil.isNotEmpty(sheetData)) {
createSheetWithData(sheet, sheetData);
}
}
setResponseHeader(response, excelFileName, suffixName);
// 写出文件
workbook.write(response.getOutputStream());
}
}
/**
* 创建表单并填充数据
*
* @param sheet 表单
* @param data 数据
*/
private static void createSheetWithData(Sheet sheet, Object data) {
if (data instanceof List) {
createSheetWithListData(sheet, (List<?>) data);
} else {
createSheetWithObjectData(sheet, data);
}
}
/**
* 创建列表类型数据对应的Excel表单
*
* @param sheet 表单
* @param dataList 数据列表
*/
private static void createSheetWithListData(Sheet sheet, List<?> dataList) {
if (CollUtil.isNotEmpty(dataList)) {
Object firstItem = dataList.get(0);
createHeaderRow(sheet, firstItem.getClass());
int rowIndex = 1;
for (Object item : dataList) {
createDataRow(sheet, item, rowIndex++);
}
}
}
/**
* 创建对象类型数据对应的Excel表单
*
* @param sheet 表单
* @param data 数据
*/
private static void createSheetWithObjectData(Sheet sheet, Object data) {
createHeaderRow(sheet, data.getClass());
createDataRow(sheet, data, 1);
}
/**
* 创建表头行
*
* @param sheet 表单
* @param clazz 数据类
*/
private static void createHeaderRow(Sheet sheet, Class<?> clazz) {
// 创建单元格样式
CellStyle headerCellStyle = createCellStyle(sheet.getWorkbook());
// 创建标题行
Row headerRow = sheet.createRow(0);
Field[] fields = clazz.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
createHeaderCell(sheet, headerCellStyle, fields, headerRow, i);
}
}
/**
* 创建数据行
*
* @param sheet 表单
* @param data 数据
* @param rowIndex 行号
*/
private static void createDataRow(Sheet sheet, Object data, int rowIndex) {
// 创建单元格样式
CellStyle dataCellStyle = createCellStyle(sheet.getWorkbook());
// 创建数据行
Row dataRow = sheet.createRow(rowIndex);
Field[] fields = data.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
createDataCell(dataCellStyle, fields, dataRow, i, data);
}
}
/**
* 创建单元格样式
*
* @param workbook 工作簿
* @return 单元格样式
*/
private static CellStyle createCellStyle(Workbook workbook) {
CellStyle cellStyle = workbook.createCellStyle();
// 设置 水平和垂直 居中对齐
cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// 设置 上 下 左 右 边框及颜色
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
cellStyle.setBorderRight(BorderStyle.THIN);
cellStyle.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
// 设置字体
Font dataFont = workbook.createFont();
dataFont.setFontName("Arial");
dataFont.setFontHeightInPoints((short) 10);
cellStyle.setFont(dataFont);
return cellStyle;
}
/**
* 创建Excel表头单元格
*
* @param sheet 表单
* @param headerCellStyle 单元格样式
* @param fields 字段
* @param headerRow 标题行
* @param i 序号
*/
private static void createHeaderCell(Sheet sheet, CellStyle headerCellStyle, Field[] fields, Row headerRow, int i) {
// 默认宽度
double width = 16;
Excel excelAnnotation = fields[i].getAnnotation(Excel.class);
if (excelAnnotation != null && !ObjectUtil.isEmpty(excelAnnotation.width())) {
width = excelAnnotation.width();
}
// 设置宽度
sheet.setColumnWidth(i, (int) ((width + 0.72) * 256));
if (excelAnnotation != null) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(excelAnnotation.name());
cell.setCellStyle(headerCellStyle);
}
}
/**
* 创建Excel数据单元格
*
* @param dataCellStyle 单元格样式
* @param fields 字段
* @param dataRow 数据行
* @param i 序号
* @param data 数据
*/
private static void createDataCell(CellStyle dataCellStyle, Field[] fields, Row dataRow, int i, Object data) {
Cell cell = dataRow.createCell(i);
cell.setCellStyle(dataCellStyle);
try {
fields[i].setAccessible(true);
Object value = fields[i].get(data);
handleAnnotationAndSetValue(cell, fields[i], value);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
/**
* 处理注解并设置单元格值
*
* @param cell 单元格
* @param field 字段
* @param value 值
*/
private static void handleAnnotationAndSetValue(Cell cell, Field field, Object value) {
if (field.isAnnotationPresent(Excel.class) && field.getAnnotation(Excel.class).dictType().length() > 0) {
value = DictUtils.getDictLabel(field.getAnnotation(Excel.class).dictType(), String.valueOf(value));
}
if (field.isAnnotationPresent(Excel.class) && StrUtil.isNotEmpty(field.getAnnotation(Excel.class).dateFormat())) {
value = DateUtil.format(Convert.convert(Date.class, value), field.getAnnotation(Excel.class).dateFormat());
}
cell.setCellValue(ObjectUtil.isEmpty(value) ? null : value.toString());
}
/**
* 设置响应头
*
* @param response 响应
* @param excelFileName 文件名
* @param suffixName 后缀名
* @throws UnsupportedEncodingException 编码异常
*/
private static void setResponseHeader(HttpServletResponse response, String excelFileName, String suffixName) throws UnsupportedEncodingException {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(excelFileName + suffixName, UTF_8));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment