|
|
|
@ -23,10 +23,9 @@ import java.util.List; |
|
|
|
@Component |
|
|
|
public class ExcelDepositoryInfoConverter implements Converter<Integer> { |
|
|
|
|
|
|
|
private static ExcelDepositoryInfoConverter excelDepositoryInfoConverter; |
|
|
|
@Autowired |
|
|
|
private DepositoryService depositoryService; |
|
|
|
|
|
|
|
private static ExcelDepositoryInfoConverter excelDepositoryInfoConverter; |
|
|
|
private DepositoryService depositoryService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Class supportJavaTypeKey() { |
|
|
|
@ -40,14 +39,12 @@ public class ExcelDepositoryInfoConverter implements Converter<Integer> { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
|
|
|
List<Depository> depositoryAll = excelDepositoryInfoConverter.depositoryService.findDepositoryAll(); |
|
|
|
Integer data = 0; |
|
|
|
for (int i = 0; i < depositoryAll.size(); i++) { |
|
|
|
if(cellData.getStringValue().equals(depositoryAll.get(i).getCode())){ |
|
|
|
data = depositoryAll.get(i).getId(); |
|
|
|
} |
|
|
|
Depository depository = excelDepositoryInfoConverter.depositoryService.findDepositoryByCode(cellData.getStringValue()); |
|
|
|
if (depository != null) { |
|
|
|
data = depository.getId(); |
|
|
|
} |
|
|
|
if(data == 0){ |
|
|
|
if (data == 0) { |
|
|
|
throw new RuntimeException("没有该仓库"); |
|
|
|
} |
|
|
|
return data; |
|
|
|
@ -55,18 +52,17 @@ public class ExcelDepositoryInfoConverter implements Converter<Integer> { |
|
|
|
|
|
|
|
@Override |
|
|
|
public WriteCellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
|
|
|
List<Depository> depositoryAll = excelDepositoryInfoConverter.depositoryService.findDepositoryAll(); |
|
|
|
Depository depository = excelDepositoryInfoConverter.depositoryService.findDepositoryById(value); |
|
|
|
String data = ""; |
|
|
|
for (int i = 0; i < depositoryAll.size(); i++) { |
|
|
|
if(Integer.compare(value,depositoryAll.get(i).getId()) == 0){ |
|
|
|
data = depositoryAll.get(i).getCode(); |
|
|
|
} |
|
|
|
if(depository != null) { |
|
|
|
data = depository.getCode(); |
|
|
|
} |
|
|
|
|
|
|
|
return new WriteCellData<>(data); |
|
|
|
} |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void init(){ |
|
|
|
public void init() { |
|
|
|
excelDepositoryInfoConverter = this; |
|
|
|
excelDepositoryInfoConverter.depositoryService = this.depositoryService; |
|
|
|
} |
|
|
|
|