Merge branch 'prod/20260203' into develop

This commit is contained in:
曹鹏飞 2026-02-03 14:38:55 +08:00
commit 98c4d21568
5 changed files with 227 additions and 4 deletions

View File

@ -134,6 +134,47 @@ public class DeviceController extends ControllerBase {
return ApiResult.success(resultData, query, result.getTotal());
}
/**
* 导出设备列表
* @param query
*/
@PostMapping("exportSearch")
public void exportSearch(HttpServletResponse response,@RequestBody DeviceQuery query) throws IOException {
Page<Device> result = deviceService.getList(new Page<>(1, Integer.MAX_VALUE), query);
List<DictionaryItem> states = dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DEVICE_STATE);
List<DeviceExportDTO> datas = result.getRecords().stream().map(d -> {
DeviceExportDTO dto = new DeviceExportDTO();
dto.setId(String.valueOf(d.getId()));
dto.setDeviceNo(d.getDeviceNo());
dto.setDeviceName(d.getCustomerName()+d.getDeviceNo());
dto.setDeviceType(d.getDeviceType());
dto.setDeviceTypeSub(d.getDeviceTypeSub());
dto.setModelNo(d.getModelNo());
dto.setDeviceStateDesc(states.stream().filter(s -> Objects.equals(s.getId(), d.getDeviceState())).findFirst().get().getName());
dto.setCustomerName(d.getCustomerName());
dto.setAgentName(d.getAgentName());
dto.setAreaName(d.getAreaName());
dto.setAddress(d.getAddress());
dto.setShipmentDate(d.getShipmentDate());
dto.setStartWarrantyDate(d.getStartWarrantyDate());
if (Objects.nonNull(d.getWarrantyMonth())) {
dto.setWarrantyMonth(String.valueOf(d.getWarrantyMonth()));
}
dto.setServiceAgentName(d.getServiceAgentName());
return dto;
}).collect(Collectors.toList());
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("设备导出.xlsx", StandardCharsets.UTF_8));
// ClassPathResource resource = new ClassPathResource("templates/deviceForUpdate.xlsx");
// new Workbook()
// .addSheet(new TemplateSheet(resource.getInputStream())
// .setData(datas)
// .setData("@list:deviceStateDesc", dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DEVICE_STATE)
// .stream().map(DictionaryItem::getName).collect(Collectors.toList())))
// .writeTo(response.getOutputStream());
new Workbook().addSheet(new ListSheet<>(datas)).writeTo(response.getOutputStream());
}
/**
* 获取设备详情
* @param id

View File

@ -41,6 +41,7 @@ public class SolutionMeasuresSaveRequest {
/**
* 问题部件id
*/
@NotNull
private Long componentId;
/**

View File

@ -137,6 +137,48 @@ public class DeviceController extends ControllerBase {
return ApiResult.success(resultData, query, result.getTotal());
}
/**
* 导出设备列表
* @param query
*/
@PostMapping("exportSearch")
public void exportSearch(HttpServletResponse response,@RequestBody DeviceQuery query) throws IOException {
Page<GongfuDevice> result = deviceService.getList(new Page<>(1, Integer.MAX_VALUE), query);
List<DictionaryItem> states = dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DEVICE_STATE);
List<DeviceExportDTO> datas = result.getRecords().stream().map(d -> {
DeviceExportDTO dto = new DeviceExportDTO();
dto.setId(String.valueOf(d.getId()));
dto.setDeviceNo(d.getDeviceNo());
dto.setDeviceName(d.getCustomerName()+d.getDeviceNo());
dto.setDeviceType(d.getDeviceType());
dto.setDeviceTypeSub(d.getDeviceTypeSub());
dto.setModelNo(d.getModelNo());
dto.setDeviceStateDesc(states.stream().filter(s -> Objects.equals(s.getId(), d.getDeviceState())).findFirst().get().getName());
dto.setCustomerName(d.getCustomerName());
dto.setAgentName(d.getAgentName());
dto.setAreaName(d.getAreaName());
dto.setAddress(d.getAddress());
dto.setShipmentDate(d.getShipmentDate());
dto.setStartWarrantyDate(d.getStartWarrantyDate());
if (Objects.nonNull(d.getWarrantyMonth())) {
dto.setWarrantyMonth(String.valueOf(d.getWarrantyMonth()));
}
dto.setProductLine(d.getProductLine());
dto.setServiceAgentName(d.getServiceAgentName());
return dto;
}).collect(Collectors.toList());
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("设备导出.xlsx", StandardCharsets.UTF_8));
// ClassPathResource resource = new ClassPathResource("templates/deviceForUpdate.xlsx");
// new Workbook()
// .addSheet(new TemplateSheet(resource.getInputStream())
// .setData(datas)
// .setData("@list:deviceStateDesc", dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DEVICE_STATE)
// .stream().map(DictionaryItem::getName).collect(Collectors.toList())))
// .writeTo(response.getOutputStream());
new Workbook().addSheet(new ListSheet<>(datas)).writeTo(response.getOutputStream());
}
/**
* 获取设备详情
* @param id

View File

@ -0,0 +1,139 @@
package com.nflg.mobilebroken.gongfu.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.nflg.mobilebroken.common.pojo.ApiResult;
import com.nflg.mobilebroken.common.util.AdminUserUtil;
import com.nflg.mobilebroken.repository.entity.GongfuDevice;
import com.nflg.mobilebroken.repository.entity.GongfuDeviceComponent;
import com.nflg.mobilebroken.repository.entity.GongfuDeviceComponentDetail;
import com.nflg.mobilebroken.repository.service.IGongfuDeviceComponentDetailService;
import com.nflg.mobilebroken.repository.service.IGongfuDeviceComponentService;
import com.nflg.mobilebroken.repository.service.IGongfuDeviceService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 测试
*/
@RestController
@RequestMapping("/test")
public class TestController extends ControllerBase {
@Resource
private IGongfuDeviceService gongfuDeviceService;
@Resource
private IGongfuDeviceComponentService gongfuDeviceComponentService;
@Resource
private IGongfuDeviceComponentDetailService gongfuDeviceComponentDetailService;
/**
* 初始化设备组件中的产品线数据
*/
@Transactional
@GetMapping("initDeviceComponentProductLine")
public ApiResult<Void> initDeviceComponentProductLine() {
List<GongfuDeviceComponent> deviceComponents = gongfuDeviceComponentService
.lambdaQuery()
.isNull(GongfuDeviceComponent::getProductLine)
.list();
if (CollectionUtil.isEmpty(deviceComponents)) {
return ApiResult.success();
}
List<GongfuDevice> devices = gongfuDeviceService.lambdaQuery()
.select(GongfuDevice::getModelNo, GongfuDevice::getProductLine)
.eq(GongfuDevice::getDataValidState, 1)
.list();
List<GongfuDeviceComponent> forUpdate = new ArrayList<>();
List<GongfuDeviceComponent> forAdd = new ArrayList<>();
List<GongfuDeviceComponentDetail> detailsForAdd = new ArrayList<>();
deviceComponents.forEach(deviceComponent -> {
List<GongfuDevice> ds = devices.stream()
.filter(d -> d.getModelNo().equals(deviceComponent.getModelNo()))
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(ds)) {
forUpdate.add(new GongfuDeviceComponent()
.setId(deviceComponent.getId())
.setProductLine(ds.get(0).getProductLine())
);
if (ds.size() > 1) {
List<GongfuDeviceComponentDetail> details = gongfuDeviceComponentDetailService.lambdaQuery()
.eq(GongfuDeviceComponentDetail::getDeviceComponentId, deviceComponent.getId())
.list();
for (int i = 1; i < ds.size(); i++) {
String prodoctLine = ds.get(i).getProductLine();
GongfuDeviceComponent component = deviceComponents.stream()
.filter(dc -> StrUtil.equals(dc.getProductLine(), prodoctLine))
.findFirst()
.orElse(null);
if (Objects.isNull(component)) {
component = forAdd.stream()
.filter(dc -> StrUtil.equals(dc.getProductLine(), prodoctLine))
.findFirst()
.orElse(null);
if (Objects.isNull(component)) {
component = new GongfuDeviceComponent()
.setId(IdUtil.getSnowflakeNextId())
.setProductLine(ds.get(i).getProductLine())
.setComponent(deviceComponent.getComponent())
.setEnable(deviceComponent.getEnable())
.setCreateBy(deviceComponent.getCreateBy())
.setCreateTime(deviceComponent.getCreateTime())
.setUpdateBy(deviceComponent.getUpdateBy())
.setUpdateTime(deviceComponent.getUpdateTime());
forAdd.add(component);
}
}
for (GongfuDeviceComponentDetail detail : details) {
detailsForAdd.add(new GongfuDeviceComponentDetail()
.setDeviceComponentId(component.getId())
.setModelPartId(detail.getModelPartId())
.setModelPartName(detail.getModelPartName())
.setCreateBy(AdminUserUtil.getUserName())
.setCreateTime(LocalDateTime.now())
);
}
}
}
}
});
if (CollectionUtil.isNotEmpty(forUpdate)) {
gongfuDeviceComponentService.updateBatchById(forUpdate);
}
if (CollectionUtil.isNotEmpty(forAdd)) {
gongfuDeviceComponentService.saveBatch(forAdd);
}
if (CollectionUtil.isNotEmpty(detailsForAdd)) {
gongfuDeviceComponentDetailService.saveBatch(detailsForAdd);
}
List<GongfuDeviceComponentDetail> allDetails = gongfuDeviceComponentDetailService
.lambdaQuery()
.select(GongfuDeviceComponentDetail::getDeviceComponentId, GongfuDeviceComponentDetail::getModelPartName)
.list();
List<GongfuDeviceComponent> allComponents = gongfuDeviceComponentService.lambdaQuery()
.select(GongfuDeviceComponent::getId)
.list();
allComponents.forEach(component -> {
component.setComponent(
allDetails.stream()
.filter(detail -> detail.getDeviceComponentId().equals(component.getId()))
.map(GongfuDeviceComponentDetail::getModelPartName)
.collect(Collectors.joining(","))
);
});
gongfuDeviceComponentService.updateBatchById(allComponents);
return ApiResult.success();
}
}

View File

@ -28,10 +28,10 @@ public class GongfuDeviceComponent implements Serializable {
@TableId(value = "id", type = IdType.ASSIGN_ID)
private Long id;
// /**
// * 设备机型
// */
// private String modelNo;
/**
* 设备机型
*/
private String modelNo;
/**
* 产品线