查询对比下载;角色权限为空返回空数组
This commit is contained in:
parent
43247d411a
commit
7a1a3e2549
@ -140,12 +140,16 @@ public class PermissionController {
|
|||||||
List<ParametersView> list = parameterService.getAllParameters(subsystem);
|
List<ParametersView> list = parameterService.getAllParameters(subsystem);
|
||||||
return Response.ok().data(list);
|
return Response.ok().data(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查看角色绑定的人员或部门列表
|
// 查看角色绑定的人员或部门列表
|
||||||
@GetMapping("/selectUserOrDeptByRole")
|
@GetMapping("/selectUserOrDeptByRole")
|
||||||
public Response selectUserOrDeptByRole(
|
public Response selectUserOrDeptByRole(
|
||||||
@NotBlank String roleID
|
@NotBlank String roleID
|
||||||
) {
|
) {
|
||||||
HashMap<String, List<String>> map = modelRoleService.selectUserOrDeptByRole(roleID);
|
HashMap<String, List<String>> map = modelRoleService.selectUserOrDeptByRole(roleID);
|
||||||
|
if (ObjectUtils.isEmpty(map)) {
|
||||||
|
return Response.ok().data(new HashMap<>());
|
||||||
|
}
|
||||||
return Response.ok().data(map);
|
return Response.ok().data(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package com.xdap.self_development.controller;
|
|||||||
|
|
||||||
import com.definesys.mpaas.common.http.Response;
|
import com.definesys.mpaas.common.http.Response;
|
||||||
import com.xdap.self_development.controller.request.AnalysisRequest;
|
import com.xdap.self_development.controller.request.AnalysisRequest;
|
||||||
|
import com.xdap.self_development.controller.request.ModelComparisonExportRequest;
|
||||||
import com.xdap.self_development.pojo.ClassificationAttribute;
|
import com.xdap.self_development.pojo.ClassificationAttribute;
|
||||||
import com.xdap.self_development.pojo.EngineParamDetailPojo;
|
import com.xdap.self_development.pojo.EngineParamDetailPojo;
|
||||||
import com.xdap.self_development.service.TcDataQueryService;
|
import com.xdap.self_development.service.TcDataQueryService;
|
||||||
@ -34,6 +35,12 @@ public class TcDataQueryController {
|
|||||||
Map<String, List<EngineParamDetailPojo>> stringListHashMap = tcDataQueryService.tcDataSelectAllByPartsNameBack(analysisRequest);
|
Map<String, List<EngineParamDetailPojo>> stringListHashMap = tcDataQueryService.tcDataSelectAllByPartsNameBack(analysisRequest);
|
||||||
return Response.ok().data(stringListHashMap);
|
return Response.ok().data(stringListHashMap);
|
||||||
}
|
}
|
||||||
|
//根据机型ID和子系统-零部件+userID下载为excel
|
||||||
|
@PostMapping("/modelComparisonExport")
|
||||||
|
public Response modelComparisonExport(@RequestBody ModelComparisonExportRequest request,HttpServletResponse response) {
|
||||||
|
tcDataQueryService.modelComparisonExport(request,response);
|
||||||
|
return Response.ok().data("导出成功");
|
||||||
|
}
|
||||||
//下载TC数据ads_prd_f_yfsjglpt_fdjlbjcjb
|
//下载TC数据ads_prd_f_yfsjglpt_fdjlbjcjb
|
||||||
@PostMapping("/syncA")
|
@PostMapping("/syncA")
|
||||||
public Response excelExportA(HttpServletResponse response) {
|
public Response excelExportA(HttpServletResponse response) {
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class AnalysisRequest{
|
public class AnalysisRequest{
|
||||||
|
private String userID;
|
||||||
private String engineModelID;
|
private String engineModelID;
|
||||||
/**
|
/**
|
||||||
* 子系统+零部件名称路径
|
* 子系统+零部件名称路径
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
package com.xdap.self_development.controller.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ModelComparisonExportRequest {
|
||||||
|
String userID;
|
||||||
|
List<String> modelIds;
|
||||||
|
List<String> subsystemParts;
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.xdap.self_development.service;
|
package com.xdap.self_development.service;
|
||||||
|
|
||||||
import com.xdap.self_development.controller.request.AnalysisRequest;
|
import com.xdap.self_development.controller.request.AnalysisRequest;
|
||||||
|
import com.xdap.self_development.controller.request.ModelComparisonExportRequest;
|
||||||
import com.xdap.self_development.pojo.ClassificationAttribute;
|
import com.xdap.self_development.pojo.ClassificationAttribute;
|
||||||
import com.xdap.self_development.pojo.DataEntryEngineModelPojo;
|
import com.xdap.self_development.pojo.DataEntryEngineModelPojo;
|
||||||
import com.xdap.self_development.pojo.EngineParamDetailPojo;
|
import com.xdap.self_development.pojo.EngineParamDetailPojo;
|
||||||
@ -25,4 +26,6 @@ public interface TcDataQueryService {
|
|||||||
void excelExportA(HttpServletResponse response);
|
void excelExportA(HttpServletResponse response);
|
||||||
|
|
||||||
void excelExportB(HttpServletResponse response);
|
void excelExportB(HttpServletResponse response);
|
||||||
|
|
||||||
|
void modelComparisonExport(ModelComparisonExportRequest request, HttpServletResponse response);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -276,14 +276,22 @@ public class ModelRoleServiceImpl implements ModelRoleService {
|
|||||||
for (ModelDepUserRolePojo userRolePojo : deptList) {
|
for (ModelDepUserRolePojo userRolePojo : deptList) {
|
||||||
String depId = userRolePojo.getUserOrDep();
|
String depId = userRolePojo.getUserOrDep();
|
||||||
XdapDepartments xdapDepartments = xdapDeptUsersService.selectDeptByID(depId);
|
XdapDepartments xdapDepartments = xdapDeptUsersService.selectDeptByID(depId);
|
||||||
|
if (ObjectUtils.isEmpty(xdapDepartments)) {
|
||||||
|
stringsDept.add("未知部门:" + depId);
|
||||||
|
} else {
|
||||||
stringsDept.add(xdapDepartments.getName());
|
stringsDept.add(xdapDepartments.getName());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
map.put("部门", stringsDept);
|
map.put("部门", stringsDept);
|
||||||
for (ModelDepUserRolePojo userRolePojo : userList) {
|
for (ModelDepUserRolePojo userRolePojo : userList) {
|
||||||
String userId = userRolePojo.getUserOrDep();
|
String userId = userRolePojo.getUserOrDep();
|
||||||
XdapUsers xdapUsers = xdapDeptUsersService.selectUserByID(userId);
|
XdapUsers xdapUsers = xdapDeptUsersService.selectUserByID(userId);
|
||||||
|
if (ObjectUtils.isEmpty(xdapUsers)) {
|
||||||
|
stringsUser.add("未知人员:" + userId);
|
||||||
|
} else {
|
||||||
stringsUser.add(xdapUsers.getUsername() + "-" + xdapUsers.getAccount());
|
stringsUser.add(xdapUsers.getUsername() + "-" + xdapUsers.getAccount());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
map.put("人员", stringsUser);
|
map.put("人员", stringsUser);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,10 +6,13 @@ import com.alibaba.excel.write.metadata.WriteSheet;
|
|||||||
import com.definesys.mpaas.query.MpaasQueryFactory;
|
import com.definesys.mpaas.query.MpaasQueryFactory;
|
||||||
import com.xdap.self_development.config.BusinessDatabase;
|
import com.xdap.self_development.config.BusinessDatabase;
|
||||||
import com.xdap.self_development.controller.request.AnalysisRequest;
|
import com.xdap.self_development.controller.request.AnalysisRequest;
|
||||||
|
import com.xdap.self_development.controller.request.ModelComparisonExportRequest;
|
||||||
import com.xdap.self_development.pojo.*;
|
import com.xdap.self_development.pojo.*;
|
||||||
import com.xdap.self_development.service.DataEntryEngineModelService;
|
import com.xdap.self_development.service.DataEntryEngineModelService;
|
||||||
import com.xdap.self_development.service.EngineParamDetailService;
|
import com.xdap.self_development.service.EngineParamDetailService;
|
||||||
import com.xdap.self_development.service.TcDataQueryService;
|
import com.xdap.self_development.service.TcDataQueryService;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -19,6 +22,8 @@ import org.springframework.stereotype.Service;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -34,6 +39,13 @@ public class TcDataQueryServiceImpl implements TcDataQueryService {
|
|||||||
private DataEntryEngineModelService engineModelService;
|
private DataEntryEngineModelService engineModelService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private MpaasQueryFactory sw;
|
private MpaasQueryFactory sw;
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
private ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
|
||||||
//产品编号(状态代号) = 状态机
|
//产品编号(状态代号) = 状态机
|
||||||
@Override
|
@Override
|
||||||
@ -215,17 +227,18 @@ public class TcDataQueryServiceImpl implements TcDataQueryService {
|
|||||||
public Map<String, List<EngineParamDetailPojo>> tcDataSelectAllByPartsNameFunctionOptimized(AnalysisRequest analysisRequest) {
|
public Map<String, List<EngineParamDetailPojo>> tcDataSelectAllByPartsNameFunctionOptimized(AnalysisRequest analysisRequest) {
|
||||||
String engineModelID = analysisRequest.getEngineModelID();
|
String engineModelID = analysisRequest.getEngineModelID();
|
||||||
List<String> subsystemTypes = analysisRequest.getSubsystemParts();
|
List<String> subsystemTypes = analysisRequest.getSubsystemParts();
|
||||||
|
String userID = analysisRequest.getUserID();
|
||||||
|
|
||||||
if (ObjectUtils.isEmpty(engineModelID) || ObjectUtils.isEmpty(subsystemTypes)) {
|
if (ObjectUtils.isEmpty(engineModelID) || ObjectUtils.isEmpty(subsystemTypes) || ObjectUtils.isEmpty(userID)) {
|
||||||
throw new RuntimeException("传入参数为空,请检查");
|
throw new RuntimeException("传入参数部分为空,请检查");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
List<EngineParamDetailPojo> allPojos = new ArrayList<>();
|
List<EngineParamDetailPojo> allPojos = new ArrayList<>();
|
||||||
List<Parameter> parameters = engineParamDetailService.selectAllAndTcByNewVersion();
|
List<Parameter> parameters = engineParamDetailService.selectAllAndTcByNewVersion();
|
||||||
DataEntryEngineModelPojo dataEntryEngineModelPojo = engineModelService.selectBymodelId(engineModelID);
|
DataEntryEngineModelPojo dataEntryEngineModelPojo = engineModelService.selectBymodelId(engineModelID);
|
||||||
|
|
||||||
// 预加载所有参数信息
|
// 预加载所有参数信息
|
||||||
|
|
||||||
Map<String, List<Parameter>> parameterMap = parameters.stream()
|
Map<String, List<Parameter>> parameterMap = parameters.stream()
|
||||||
.collect(Collectors.groupingBy(p -> p.getPartsName() + "&&" + p.getParameterName()));
|
.collect(Collectors.groupingBy(p -> p.getPartsName() + "&&" + p.getParameterName()));
|
||||||
|
|
||||||
@ -328,9 +341,20 @@ public class TcDataQueryServiceImpl implements TcDataQueryService {
|
|||||||
|
|
||||||
allPojos.addAll(tcDataPojos);
|
allPojos.addAll(tcDataPojos);
|
||||||
}
|
}
|
||||||
|
//将allPojos存到Redis,KEY为userID+engineModelID+预操作,过期时间24小时
|
||||||
|
try {
|
||||||
|
String redisKey = userID + ":" + engineModelID + ":" + "ComparisonExport";
|
||||||
|
String jsonValue = objectMapper.writeValueAsString(allPojos);
|
||||||
|
redisTemplate.opsForValue().set(redisKey, jsonValue, 24, java.util.concurrent.TimeUnit.HOURS);
|
||||||
|
log.info("成功将数据存储到Redis,KEY: {}", redisKey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("存储数据到Redis失败: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, List<EngineParamDetailPojo>> valueBySubSysName =
|
Map<String, List<EngineParamDetailPojo>> valueBySubSysName =
|
||||||
allPojos.stream().collect(Collectors.groupingBy(EngineParamDetailPojo::getSubsystemName));
|
allPojos.stream().collect(Collectors.groupingBy(EngineParamDetailPojo::getSubsystemName));
|
||||||
|
|
||||||
|
|
||||||
return valueBySubSysName;
|
return valueBySubSysName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,6 +408,138 @@ public class TcDataQueryServiceImpl implements TcDataQueryService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void modelComparisonExport(ModelComparisonExportRequest request, HttpServletResponse response) {
|
||||||
|
List<String> modelIds = request.getModelIds();
|
||||||
|
String userID = request.getUserID();
|
||||||
|
List<String> subsystemParts = request.getSubsystemParts();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 设置响应头
|
||||||
|
setupResponse(response, "机型参数对比表" + (formatter.format(LocalDateTime.now())) + ".xlsx");
|
||||||
|
|
||||||
|
// 获取机型名称映射
|
||||||
|
Map<String, String> modelNames = new HashMap<>();
|
||||||
|
for (String modelId : modelIds) {
|
||||||
|
DataEntryEngineModelPojo model = engineModelService.selectBymodelId(modelId);
|
||||||
|
if (model != null) {
|
||||||
|
modelNames.put(modelId, model.getModelName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存储所有参数信息,key为参数名,value为各机型的参数值
|
||||||
|
Map<String, Map<String, String>> parameterValues = new HashMap<>();
|
||||||
|
// 存储参数的子系统和零部件信息
|
||||||
|
Map<String, String[]> parameterSubsystemParts = new HashMap<>();
|
||||||
|
|
||||||
|
// 从Redis获取每个机型的数据
|
||||||
|
for (String modelId : modelIds) {
|
||||||
|
try {
|
||||||
|
String redisKey = userID + ":" + modelId + ":" + "ComparisonExport";
|
||||||
|
String cachedData = redisTemplate.opsForValue().get(redisKey);
|
||||||
|
|
||||||
|
if (ObjectUtils.isNotEmpty(cachedData)) {
|
||||||
|
// 反序列化数据
|
||||||
|
List<EngineParamDetailPojo> allPojos = objectMapper.readValue(cachedData,
|
||||||
|
objectMapper.getTypeFactory().constructCollectionType(List.class, EngineParamDetailPojo.class));
|
||||||
|
|
||||||
|
// 根据子系统部件筛选数据
|
||||||
|
List<EngineParamDetailPojo> filteredPojos = allPojos.stream()
|
||||||
|
.filter(pojo -> subsystemParts.stream().anyMatch(part -> {
|
||||||
|
String[] parts = part.split("-");
|
||||||
|
if (parts.length != 2) return false;
|
||||||
|
String subsystem = parts[0];
|
||||||
|
String partsName = parts[1];
|
||||||
|
|
||||||
|
// 如果部件名为"/",表示只匹配子系统
|
||||||
|
if ("/".equals(partsName)) {
|
||||||
|
return subsystem.equals(pojo.getSubsystemName());
|
||||||
|
} else {
|
||||||
|
return subsystem.equals(pojo.getSubsystemName()) && partsName.equals(pojo.getPartsName());
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 处理筛选后的数据,按参数名分组
|
||||||
|
for (EngineParamDetailPojo pojo : filteredPojos) {
|
||||||
|
String paramName = pojo.getParameterName();
|
||||||
|
String paramValue = pojo.getParameterValue();
|
||||||
|
|
||||||
|
// 如果参数名不存在,创建新条目
|
||||||
|
if (!parameterValues.containsKey(paramName)) {
|
||||||
|
parameterValues.put(paramName, new HashMap<>());
|
||||||
|
// 存储子系统和零部件信息
|
||||||
|
parameterSubsystemParts.put(paramName, new String[]{pojo.getSubsystemName(), pojo.getPartsName()});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置该机型的参数值
|
||||||
|
parameterValues.get(paramName).put(modelId, paramValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("从Redis读取机型{}数据失败: {}", modelId, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 准备Excel数据
|
||||||
|
List<List<String>> excelData = new ArrayList<>();
|
||||||
|
|
||||||
|
// 表头行:子系统,零部件,参数名,机型1,机型2,机型3...
|
||||||
|
List<String> header = new ArrayList<>();
|
||||||
|
header.add("子系统");
|
||||||
|
header.add("零部件");
|
||||||
|
header.add("参数");
|
||||||
|
for (String modelId : modelIds) {
|
||||||
|
header.add(modelNames.getOrDefault(modelId, "未知机型"));
|
||||||
|
}
|
||||||
|
excelData.add(header);
|
||||||
|
|
||||||
|
// 数据行:每个参数一行
|
||||||
|
for (Map.Entry<String, Map<String, String>> entry : parameterValues.entrySet()) {
|
||||||
|
List<String> row = new ArrayList<>();
|
||||||
|
String paramName = entry.getKey();
|
||||||
|
|
||||||
|
// 添加子系统和零部件信息
|
||||||
|
String[] getSubsystemParts = parameterSubsystemParts.get(paramName);
|
||||||
|
if (getSubsystemParts != null) {
|
||||||
|
row.add(getSubsystemParts[0]); // 子系统
|
||||||
|
row.add(getSubsystemParts[1]); // 零部件
|
||||||
|
} else {
|
||||||
|
row.add(""); // 子系统
|
||||||
|
row.add(""); // 零部件
|
||||||
|
}
|
||||||
|
|
||||||
|
row.add(paramName); // 参数名
|
||||||
|
|
||||||
|
// 每个机型的参数值
|
||||||
|
Map<String, String> values = entry.getValue();
|
||||||
|
for (String modelId : modelIds) {
|
||||||
|
row.add(values.getOrDefault(modelId, ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
excelData.add(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 写入Excel
|
||||||
|
EasyExcel.write(response.getOutputStream())
|
||||||
|
.sheet("机型参数对比")
|
||||||
|
.doWrite(excelData);
|
||||||
|
|
||||||
|
log.info("机型参数对比表导出成功");
|
||||||
|
|
||||||
|
// 导出成功后删除Redis中的数据
|
||||||
|
// for (String modelId : modelIds) {
|
||||||
|
// String redisKey = userID + ":" + modelId + ":" + "ComparisonExport";
|
||||||
|
// redisTemplate.delete(redisKey);
|
||||||
|
// log.info("已删除Redis中的数据,KEY: {}", redisKey);
|
||||||
|
// }
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("导出机型参数对比表失败: {}", e.getMessage());
|
||||||
|
throw new RuntimeException("导出失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setupResponse(HttpServletResponse response, String fileName) throws IOException {
|
private void setupResponse(HttpServletResponse response, String fileName) throws IOException {
|
||||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user