Merge branch 'feature/bug-1286' into develop
# Conflicts: # nflg-mobilebroken-gongfu/src/main/java/com/nflg/mobilebroken/gongfu/controller/DeviceController.java
This commit is contained in:
commit
2b74adc20c
|
|
@ -8,10 +8,7 @@ import cn.hutool.core.util.StrUtil;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.nflg.mobilebroken.admin.annotation.ApiMark;
|
||||
import com.nflg.mobilebroken.admin.pojo.dto.DeviceAddImportDTO;
|
||||
import com.nflg.mobilebroken.admin.pojo.dto.DeviceDTO;
|
||||
import com.nflg.mobilebroken.admin.pojo.dto.DeviceUpdateImportDTO;
|
||||
import com.nflg.mobilebroken.admin.pojo.dto.SyncFromCrmDTO;
|
||||
import com.nflg.mobilebroken.admin.pojo.dto.*;
|
||||
import com.nflg.mobilebroken.admin.pojo.query.ChangeServiceAgentCodeQuery;
|
||||
import com.nflg.mobilebroken.admin.pojo.query.DeviceQuery;
|
||||
import com.nflg.mobilebroken.admin.pojo.vo.DeviceDetailResultVO;
|
||||
|
|
@ -37,6 +34,7 @@ import org.springframework.http.ResponseEntity;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.ttzero.excel.entity.ListSheet;
|
||||
import org.ttzero.excel.entity.TemplateSheet;
|
||||
import org.ttzero.excel.entity.Workbook;
|
||||
|
||||
|
|
@ -49,6 +47,7 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDate;
|
||||
|
|
@ -380,20 +379,44 @@ public class DeviceController extends ControllerBase {
|
|||
} else {
|
||||
device.setAgentName(customer.getAgencyCompanyName());
|
||||
device.setAgentCode(customer.getAgencyCompanyCode());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(dto.getServiceAgentName())) {
|
||||
TBaseCustomer customer = customerService.lambdaQuery()
|
||||
.eq(TBaseCustomer::getDelIs, 0)
|
||||
.eq(TBaseCustomer::getAgencyCompanyName, dto.getServiceAgentName())
|
||||
.one();
|
||||
if (Objects.isNull(customer)) {
|
||||
sb.append("服务代理商不存在;");
|
||||
} else if (customer.getEnableState() == 0) {
|
||||
sb.append("服务代理商状态为禁用;");
|
||||
} else {
|
||||
device.setServiceAgentCode(customer.getAgencyCompanyCode());
|
||||
device.setServiceAgentName(customer.getAgencyCompanyName());
|
||||
}
|
||||
}else {
|
||||
device.setServiceAgentCode(device.getAgentCode());
|
||||
device.setServiceAgentName(device.getAgentName());
|
||||
}
|
||||
if (StrUtil.isNotBlank(dto.getAreaName())) {
|
||||
TBaseArea area = areaService.lambdaQuery().eq(TBaseArea::getDelIs, 0).eq(TBaseArea::getAreaName, dto.getAreaName()).one();
|
||||
if (Objects.isNull(area)) {
|
||||
sb.append("区域不存在;");
|
||||
} else if (area.getAreaState().intValue() == 0) {
|
||||
sb.append("区域为禁用;");
|
||||
} else {
|
||||
device.setAreaName(area.getAreaName());
|
||||
device.setAreaCode(area.getAreaCode());
|
||||
}
|
||||
List<String> areaNames = StrUtil.split(dto.getAreaName(), ",");
|
||||
List<TBaseArea> areas = areaService.lambdaQuery()
|
||||
.eq(TBaseArea::getDelIs, 0)
|
||||
.in(TBaseArea::getAreaName, areaNames)
|
||||
.list();
|
||||
areaNames.forEach(name -> {
|
||||
TBaseArea area = areas.stream().filter(a -> StrUtil.equals(a.getAreaName(), name)).findFirst().orElse(null);
|
||||
if (Objects.isNull(area)) {
|
||||
sb.append("区域").append(name).append("不存在;");
|
||||
} else if (area.getAreaState().intValue() == 0) {
|
||||
sb.append("区域").append(name).append("为禁用;");
|
||||
} else {
|
||||
device.setAreaName(area.getAreaName());
|
||||
device.setAreaCode(area.getAreaCode());
|
||||
}
|
||||
});
|
||||
device.setAreaName(dto.getAreaName());
|
||||
device.setAreaCode(StrUtil.join(",",areas.stream().map(TBaseArea::getAreaCode).collect(Collectors.toList())));
|
||||
}
|
||||
if (StrUtil.isNotBlank(dto.getShipmentDate())) {
|
||||
try {
|
||||
|
|
@ -481,11 +504,11 @@ public class DeviceController extends ControllerBase {
|
|||
public void exportSelect(HttpServletResponse response,@Valid @RequestBody @NotEmpty List<Integer> ids) throws Exception {
|
||||
List<Device> devices=deviceService.listByIds(ids);
|
||||
List<DictionaryItem> states = dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DEVICE_STATE);
|
||||
List<DeviceUpdateImportDTO> datas=devices.stream().map(d->{
|
||||
DeviceUpdateImportDTO dto= new DeviceUpdateImportDTO();
|
||||
dto.setId(Long.valueOf(d.getId()));
|
||||
List<DeviceExportDTO> datas=devices.stream().map(d->{
|
||||
DeviceExportDTO dto= new DeviceExportDTO();
|
||||
dto.setId(String.valueOf(d.getId()));
|
||||
dto.setDeviceNo(d.getDeviceNo());
|
||||
dto.setDeviceName(d.getDeviceName());
|
||||
dto.setDeviceName(d.getCustomerName()+d.getDeviceNo());
|
||||
dto.setDeviceType(d.getDeviceType());
|
||||
dto.setDeviceTypeSub(d.getDeviceTypeSub());
|
||||
dto.setModelNo(d.getModelNo());
|
||||
|
|
@ -499,17 +522,19 @@ public class DeviceController extends ControllerBase {
|
|||
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", "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());
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -549,14 +574,16 @@ public class DeviceController extends ControllerBase {
|
|||
List<Device> devices = new ArrayList<>();
|
||||
List<TBaseDeviceType> deviceTypes = new ArrayList<>();
|
||||
List<DeviceComponent> deviceComponents = new ArrayList<>();
|
||||
List<Device> dbDevices = deviceService.listByIds(data.stream().map(DeviceUpdateImportDTO::getId).collect(Collectors.toList()));
|
||||
List<DeviceAgentRecord> deviceAgentRecords = new ArrayList<>();
|
||||
for (DeviceUpdateImportDTO dto : data) {
|
||||
Device device = new Device();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (Objects.isNull(dto.getId())) {
|
||||
sb.append("id不能为空;");
|
||||
}else {
|
||||
device=deviceService.getById(dto.getId());
|
||||
if (Objects.isNull(device)){
|
||||
device = dbDevices.stream().filter(d -> d.getId().equals(dto.getId())).findFirst().orElse(null);
|
||||
if (Objects.isNull(device)) {
|
||||
sb.append("设备不存在;");
|
||||
device = new Device();
|
||||
}
|
||||
|
|
@ -611,16 +638,50 @@ public class DeviceController extends ControllerBase {
|
|||
device.setAgentName("");
|
||||
device.setAgentCode("");
|
||||
}
|
||||
if (StrUtil.isNotBlank(dto.getAreaName())) {
|
||||
TBaseArea area = areaService.lambdaQuery().eq(TBaseArea::getDelIs, 0).eq(TBaseArea::getAreaName, dto.getAreaName()).one();
|
||||
if (Objects.isNull(area)) {
|
||||
sb.append("区域不存在;");
|
||||
} else if (area.getAreaState().intValue() == 0) {
|
||||
sb.append("区域为禁用;");
|
||||
String oldServiceAgentName = device.getServiceAgentName();
|
||||
if (StrUtil.isNotBlank(dto.getServiceAgentName())) {
|
||||
TBaseCustomer customer = customerService.lambdaQuery()
|
||||
.eq(TBaseCustomer::getDelIs, 0)
|
||||
.eq(TBaseCustomer::getAgencyCompanyName, dto.getServiceAgentName())
|
||||
.one();
|
||||
if (Objects.isNull(customer)) {
|
||||
sb.append("服务代理商不存在;");
|
||||
} else if (customer.getEnableState() == 0) {
|
||||
sb.append("服务代理商状态为禁用;");
|
||||
} else {
|
||||
device.setAreaName(area.getAreaName());
|
||||
device.setAreaCode(area.getAreaCode());
|
||||
device.setServiceAgentCode(customer.getAgencyCompanyName());
|
||||
device.setServiceAgentName(customer.getAgencyCompanyCode());
|
||||
}
|
||||
}else {
|
||||
device.setServiceAgentCode("");
|
||||
device.setServiceAgentName("");
|
||||
}
|
||||
if (Objects.nonNull(device.getId()) && StrUtil.equals(device.getServiceAgentName(),oldServiceAgentName)){
|
||||
deviceAgentRecords.add(new DeviceAgentRecord()
|
||||
.setDeviceId(device.getId())
|
||||
.setAgentCode(device.getServiceAgentCode())
|
||||
.setAgentName(device.getServiceAgentName())
|
||||
.setCreateById(AdminUserUtil.getUserId())
|
||||
.setCreateBy(AdminUserUtil.getUserName())
|
||||
.setCreateTime(LocalDateTime.now())
|
||||
);
|
||||
}
|
||||
if (StrUtil.isNotBlank(dto.getAreaName())) {
|
||||
List<String> areaNames = StrUtil.split(dto.getAreaName(), ",");
|
||||
List<TBaseArea> areas = areaService.lambdaQuery()
|
||||
.eq(TBaseArea::getDelIs, 0)
|
||||
.in(TBaseArea::getAreaName, areaNames)
|
||||
.list();
|
||||
areaNames.forEach(name -> {
|
||||
TBaseArea area = areas.stream().filter(a -> StrUtil.equals(a.getAreaName(), name)).findFirst().orElse(null);
|
||||
if (Objects.isNull(area)) {
|
||||
sb.append("区域").append(name).append("不存在;");
|
||||
} else if (area.getAreaState().intValue() == 0) {
|
||||
sb.append("区域").append(name).append("为禁用;");
|
||||
}
|
||||
});
|
||||
device.setAreaName(dto.getAreaName());
|
||||
device.setAreaCode(StrUtil.join(",",areas.stream().map(TBaseArea::getAreaCode).collect(Collectors.toList())));
|
||||
}else {
|
||||
device.setAreaName("");
|
||||
device.setAreaCode("");
|
||||
|
|
@ -700,6 +761,9 @@ public class DeviceController extends ControllerBase {
|
|||
if (CollUtil.isNotEmpty(deviceComponents)){
|
||||
deviceComponentService.saveBatch(deviceComponents);
|
||||
}
|
||||
if (CollUtil.isNotEmpty(deviceAgentRecords)){
|
||||
deviceAgentRecordService.saveBatch(deviceAgentRecords);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -56,6 +56,12 @@ public class DeviceAddImportDTO {
|
|||
@ExcelColumn("代理商")
|
||||
private String agentName;
|
||||
|
||||
/**
|
||||
* 服务代理商名称
|
||||
*/
|
||||
@ExcelColumn("服务代理商")
|
||||
private String serviceAgentName;
|
||||
|
||||
/**
|
||||
* 区域名称
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,102 @@
|
|||
package com.nflg.mobilebroken.admin.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.ttzero.excel.annotation.ExcelColumn;
|
||||
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DeviceExportDTO {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@ExcelColumn("id*")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 设备编号
|
||||
*/
|
||||
@ExcelColumn("设备编号*")
|
||||
private String deviceNo;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
@ExcelColumn("设备名称")
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
@ExcelColumn("设备类型*")
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 设备类型细分
|
||||
*/
|
||||
@ExcelColumn("设备类型细分*")
|
||||
private String deviceTypeSub;
|
||||
|
||||
/**
|
||||
* 设备机型
|
||||
*/
|
||||
@ExcelColumn("设备机型*")
|
||||
private String modelNo;
|
||||
|
||||
/**
|
||||
* 设备状态-来自字典
|
||||
*/
|
||||
@ExcelColumn("设备状态*")
|
||||
private String deviceStateDesc;
|
||||
|
||||
/**
|
||||
* 客户名称
|
||||
*/
|
||||
@ExcelColumn("客户名称")
|
||||
private String customerName;
|
||||
|
||||
/**
|
||||
* 代理商名称
|
||||
*/
|
||||
@ExcelColumn("代理商")
|
||||
private String agentName;
|
||||
|
||||
/**
|
||||
* 服务代理商名称
|
||||
*/
|
||||
@ExcelColumn("服务代理商")
|
||||
private String serviceAgentName;
|
||||
|
||||
/**
|
||||
* 区域名称
|
||||
*/
|
||||
@ExcelColumn("区域")
|
||||
private String areaName;
|
||||
|
||||
/**
|
||||
* 发货日期
|
||||
*/
|
||||
@ExcelColumn("发货日期")
|
||||
private String shipmentDate;
|
||||
|
||||
/**
|
||||
* 开始质保日期
|
||||
*/
|
||||
@ExcelColumn("开始质保日期")
|
||||
private String startWarrantyDate;
|
||||
|
||||
/**
|
||||
* 质保期(月)
|
||||
*/
|
||||
@ExcelColumn("质保期(月)")
|
||||
private String warrantyMonth;
|
||||
|
||||
/**
|
||||
* 设备地址
|
||||
*/
|
||||
@ExcelColumn("设备地址")
|
||||
private String address;
|
||||
}
|
||||
|
|
@ -14,5 +14,5 @@ public class DeviceUpdateImportDTO extends DeviceAddImportDTO{
|
|||
* id
|
||||
*/
|
||||
@ExcelColumn("id*")
|
||||
private Long id;
|
||||
private Integer id;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,7 @@ import com.nflg.mobilebroken.common.pojo.vo.DeviceQRCodeVO;
|
|||
import com.nflg.mobilebroken.common.util.*;
|
||||
import com.nflg.mobilebroken.gongfu.annotation.ApiMark;
|
||||
import com.nflg.mobilebroken.gongfu.constant.Constant1;
|
||||
import com.nflg.mobilebroken.gongfu.pojo.dto.DeviceAddImportDTO;
|
||||
import com.nflg.mobilebroken.gongfu.pojo.dto.DeviceDTO;
|
||||
import com.nflg.mobilebroken.gongfu.pojo.dto.DeviceUpdateImportDTO;
|
||||
import com.nflg.mobilebroken.gongfu.pojo.dto.SyncFromCrmDTO;
|
||||
import com.nflg.mobilebroken.gongfu.pojo.dto.*;
|
||||
import com.nflg.mobilebroken.gongfu.pojo.query.ChangeServiceAgentCodeQuery;
|
||||
import com.nflg.mobilebroken.gongfu.pojo.query.DeviceQuery;
|
||||
import com.nflg.mobilebroken.gongfu.pojo.vo.DeviceDetailResultVO;
|
||||
|
|
@ -31,7 +28,6 @@ import com.nflg.mobilebroken.repository.service.*;
|
|||
import com.nflg.mobilebroken.starter.annotation.MethodInfoMark;
|
||||
import com.nflg.mobilebroken.starter.service.FileUploadService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
|
@ -39,16 +35,19 @@ import org.springframework.http.ResponseEntity;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.ttzero.excel.entity.ListSheet;
|
||||
import org.ttzero.excel.entity.TemplateSheet;
|
||||
import org.ttzero.excel.entity.Workbook;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDate;
|
||||
|
|
@ -386,6 +385,23 @@ public class DeviceController extends ControllerBase {
|
|||
device.setServiceAgentName(customer.getAgencyCompanyName());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(dto.getServiceAgentName())) {
|
||||
TBaseCustomer customer = customerService.lambdaQuery()
|
||||
.eq(TBaseCustomer::getDelIs, 0)
|
||||
.eq(TBaseCustomer::getAgencyCompanyName, dto.getServiceAgentName())
|
||||
.one();
|
||||
if (Objects.isNull(customer)) {
|
||||
sb.append("服务代理商不存在;");
|
||||
} else if (customer.getEnableState() == 0) {
|
||||
sb.append("服务代理商状态为禁用;");
|
||||
} else {
|
||||
device.setServiceAgentCode(customer.getAgencyCompanyCode());
|
||||
device.setServiceAgentName(customer.getAgencyCompanyName());
|
||||
}
|
||||
}else {
|
||||
device.setServiceAgentCode(device.getAgentCode());
|
||||
device.setServiceAgentName(device.getAgentName());
|
||||
}
|
||||
if (StrUtil.isNotBlank(dto.getAreaName())) {
|
||||
TBaseArea area = areaService.lambdaQuery().eq(TBaseArea::getDelIs, 0).eq(TBaseArea::getAreaName, dto.getAreaName()).one();
|
||||
if (Objects.isNull(area)) {
|
||||
|
|
@ -500,11 +516,11 @@ public class DeviceController extends ControllerBase {
|
|||
public void exportSelect(HttpServletResponse response, @RequestBody @NotEmpty List<Long> ids) throws Exception {
|
||||
List<GongfuDevice> devices = deviceService.listByIds(ids);
|
||||
List<DictionaryItem> states = dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DEVICE_STATE);
|
||||
List<DeviceUpdateImportDTO> datas = devices.stream().map(d -> {
|
||||
DeviceUpdateImportDTO dto = new DeviceUpdateImportDTO();
|
||||
dto.setId(d.getId());
|
||||
List<DeviceExportDTO> datas = devices.stream().map(d -> {
|
||||
DeviceExportDTO dto = new DeviceExportDTO();
|
||||
dto.setId(String.valueOf(d.getId()));
|
||||
dto.setDeviceNo(d.getDeviceNo());
|
||||
dto.setDeviceName(d.getDeviceName());
|
||||
dto.setDeviceName(d.getCustomerName()+d.getDeviceNo());
|
||||
dto.setDeviceType(d.getDeviceType());
|
||||
dto.setDeviceTypeSub(d.getDeviceTypeSub());
|
||||
dto.setModelNo(d.getModelNo());
|
||||
|
|
@ -512,22 +528,26 @@ public class DeviceController extends ControllerBase {
|
|||
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", "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());
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -567,13 +587,16 @@ public class DeviceController extends ControllerBase {
|
|||
List<GongfuDevice> devices = new ArrayList<>();
|
||||
List<GongfuDeviceType> deviceTypes = new ArrayList<>();
|
||||
List<GongfuDeviceComponent> deviceComponents = new ArrayList<>();
|
||||
List<GongfuDevice> dbDevices = deviceService.listByIds(data.stream().map(DeviceUpdateImportDTO::getId).collect(Collectors.toList()));
|
||||
List<GongfuDeviceAgentRecord> deviceAgentRecords = new ArrayList<>();
|
||||
List<TBaseCustomer> customers = customerService.list();
|
||||
for (DeviceUpdateImportDTO dto : data) {
|
||||
GongfuDevice device = new GongfuDevice();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (Objects.isNull(dto.getId())) {
|
||||
sb.append("id不能为空;");
|
||||
} else {
|
||||
device = deviceService.getById(dto.getId());
|
||||
device = dbDevices.stream().filter(d -> d.getId().equals(dto.getId())).findFirst().orElse(null);
|
||||
if (Objects.isNull(device)) {
|
||||
sb.append("设备不存在;");
|
||||
device = new GongfuDevice();
|
||||
|
|
@ -638,17 +661,51 @@ public class DeviceController extends ControllerBase {
|
|||
device.setAgentName("");
|
||||
device.setAgentCode("");
|
||||
}
|
||||
if (StrUtil.isNotBlank(dto.getAreaName())) {
|
||||
TBaseArea area = areaService.lambdaQuery().eq(TBaseArea::getDelIs, 0).eq(TBaseArea::getAreaName, dto.getAreaName()).one();
|
||||
if (Objects.isNull(area)) {
|
||||
sb.append("区域不存在;");
|
||||
} else if (area.getAreaState().intValue() == 0) {
|
||||
sb.append("区域为禁用;");
|
||||
String oldServiceAgentName = device.getServiceAgentName();
|
||||
if (StrUtil.isNotBlank(dto.getServiceAgentName())) {
|
||||
TBaseCustomer customer = customerService.lambdaQuery()
|
||||
.eq(TBaseCustomer::getDelIs, 0)
|
||||
.eq(TBaseCustomer::getAgencyCompanyName, dto.getServiceAgentName())
|
||||
.one();
|
||||
if (Objects.isNull(customer)) {
|
||||
sb.append("服务代理商不存在;");
|
||||
} else if (customer.getEnableState() == 0) {
|
||||
sb.append("服务代理商状态为禁用;");
|
||||
} else {
|
||||
device.setAreaName(area.getAreaName());
|
||||
device.setAreaCode(area.getAreaCode());
|
||||
device.setServiceAgentCode(customer.getAgencyCompanyName());
|
||||
device.setServiceAgentName(customer.getAgencyCompanyCode());
|
||||
}
|
||||
} else {
|
||||
}else {
|
||||
device.setServiceAgentCode("");
|
||||
device.setServiceAgentName("");
|
||||
}
|
||||
if (Objects.nonNull(device.getId()) && StrUtil.equals(device.getServiceAgentName(),oldServiceAgentName)){
|
||||
deviceAgentRecords.add(new GongfuDeviceAgentRecord()
|
||||
.setDeviceId(device.getId())
|
||||
.setAgentCode(device.getServiceAgentCode())
|
||||
.setAgentName(device.getServiceAgentName())
|
||||
.setCreateById(AdminUserUtil.getUserId())
|
||||
.setCreateBy(AdminUserUtil.getUserName())
|
||||
.setCreateTime(LocalDateTime.now())
|
||||
);
|
||||
}
|
||||
if (StrUtil.isNotBlank(dto.getAreaName())) {
|
||||
List<String> areaNames = StrUtil.split(dto.getAreaName(), ",");
|
||||
List<TBaseArea> areas = areaService.lambdaQuery()
|
||||
.eq(TBaseArea::getDelIs, 0)
|
||||
.in(TBaseArea::getAreaName, areaNames)
|
||||
.list();
|
||||
areaNames.forEach(name -> {
|
||||
TBaseArea area = areas.stream().filter(a -> StrUtil.equals(a.getAreaName(), name)).findFirst().orElse(null);
|
||||
if (Objects.isNull(area)) {
|
||||
sb.append("区域").append(name).append("不存在;");
|
||||
} else if (area.getAreaState().intValue() == 0) {
|
||||
sb.append("区域").append(name).append("为禁用;");
|
||||
}
|
||||
});
|
||||
device.setAreaName(dto.getAreaName());
|
||||
device.setAreaCode(StrUtil.join(",",areas.stream().map(TBaseArea::getAreaCode).collect(Collectors.toList())));
|
||||
}else {
|
||||
device.setAreaName("");
|
||||
device.setAreaCode("");
|
||||
}
|
||||
|
|
@ -739,6 +796,9 @@ public class DeviceController extends ControllerBase {
|
|||
if (CollUtil.isNotEmpty(deviceComponents)) {
|
||||
deviceComponentService.saveBatch(deviceComponents);
|
||||
}
|
||||
if (CollUtil.isNotEmpty(deviceAgentRecords)){
|
||||
gongfuDeviceAgentRecordService.saveBatch(deviceAgentRecords);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -62,6 +62,12 @@ public class DeviceAddImportDTO {
|
|||
@ExcelColumn("代理商")
|
||||
private String agentName;
|
||||
|
||||
/**
|
||||
* 服务代理商名称
|
||||
*/
|
||||
@ExcelColumn("服务代理商")
|
||||
private String serviceAgentName;
|
||||
|
||||
/**
|
||||
* 区域名称
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,108 @@
|
|||
package com.nflg.mobilebroken.gongfu.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.ttzero.excel.annotation.ExcelColumn;
|
||||
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DeviceExportDTO {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@ExcelColumn("id*")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 产品线
|
||||
*/
|
||||
@ExcelColumn("产品线*")
|
||||
private String productLine;
|
||||
|
||||
/**
|
||||
* 设备编号
|
||||
*/
|
||||
@ExcelColumn("设备编号*")
|
||||
private String deviceNo;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
@ExcelColumn("设备名称")
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
@ExcelColumn("设备类型*")
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 设备类型细分
|
||||
*/
|
||||
@ExcelColumn("设备类型细分*")
|
||||
private String deviceTypeSub;
|
||||
|
||||
/**
|
||||
* 设备机型
|
||||
*/
|
||||
@ExcelColumn("设备机型*")
|
||||
private String modelNo;
|
||||
|
||||
/**
|
||||
* 设备状态-来自字典
|
||||
*/
|
||||
@ExcelColumn("设备状态*")
|
||||
private String deviceStateDesc;
|
||||
|
||||
/**
|
||||
* 客户名称
|
||||
*/
|
||||
@ExcelColumn("客户名称")
|
||||
private String customerName;
|
||||
|
||||
/**
|
||||
* 代理商名称
|
||||
*/
|
||||
@ExcelColumn("代理商")
|
||||
private String agentName;
|
||||
|
||||
/**
|
||||
* 服务代理商名称
|
||||
*/
|
||||
@ExcelColumn("服务代理商")
|
||||
private String serviceAgentName;
|
||||
|
||||
/**
|
||||
* 区域名称
|
||||
*/
|
||||
@ExcelColumn("区域")
|
||||
private String areaName;
|
||||
|
||||
/**
|
||||
* 发货日期
|
||||
*/
|
||||
@ExcelColumn("发货日期")
|
||||
private String shipmentDate;
|
||||
|
||||
/**
|
||||
* 开始质保日期
|
||||
*/
|
||||
@ExcelColumn("开始质保日期")
|
||||
private String startWarrantyDate;
|
||||
|
||||
/**
|
||||
* 质保期(月)
|
||||
*/
|
||||
@ExcelColumn("质保期(月)")
|
||||
private String warrantyMonth;
|
||||
|
||||
/**
|
||||
* 设备地址
|
||||
*/
|
||||
@ExcelColumn("设备地址")
|
||||
private String address;
|
||||
}
|
||||
Loading…
Reference in New Issue