Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
pipeline-network
Commits
9fb61cd3
Commit
9fb61cd3
authored
Jul 23, 2026
by
wujipeng
Browse files
导入修复数据
parent
e72ab383
Changes
7
Show whitespace changes
Inline
Side-by-side
src/main/java/com/example/pipelinenetwork/controller/RepairController.java
0 → 100644
View file @
9fb61cd3
package
com.example.pipelinenetwork.controller
;
import
com.example.pipelinenetwork.result.Result
;
import
com.example.pipelinenetwork.service.RepairService
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
/**
* @Author: wujipeng
* @Description: TODO
* @Date: 2026/7/23 14:35
* @Version: 1.0
*/
@RestController
@RequestMapping
(
"/repair"
)
public
class
RepairController
{
@Resource
private
RepairService
repairService
;
@PostMapping
(
"/import"
)
public
Result
<
Boolean
>
importDefectData
(
@RequestBody
MultipartFile
file
)
throws
IOException
{
return
Result
.
success
(
repairService
.
importDefectData
(
file
));
}
}
src/main/java/com/example/pipelinenetwork/mapper/RepairMapper.java
0 → 100644
View file @
9fb61cd3
package
com.example.pipelinenetwork.mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.example.pipelinenetwork.pojo.entity.RepairEntity
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* @Author: wujipeng
* @Description: TODO
* @Date: 2026/7/23 14:33
* @Version: 1.0
*/
@Mapper
public
interface
RepairMapper
extends
BaseMapper
<
RepairEntity
>
{
}
src/main/java/com/example/pipelinenetwork/pojo/entity/DefectEntity.java
View file @
9fb61cd3
...
@@ -14,22 +14,22 @@ public class DefectEntity {
...
@@ -14,22 +14,22 @@ public class DefectEntity {
private
Long
id
;
private
Long
id
;
/**
/**
*
缺陷
类型
* 类型
*/
*/
private
String
type
;
private
String
type
;
/**
/**
* 缺
陷名
称
* 缺称
*/
*/
private
String
name
;
private
String
name
;
/**
/**
*
缺陷
等级
* 等级
*/
*/
private
String
level
;
private
String
level
;
/**
/**
*
缺陷
数量
* 数量
*/
*/
private
Integer
num
;
private
Integer
num
;
...
...
src/main/java/com/example/pipelinenetwork/pojo/entity/RepairEntity.java
0 → 100644
View file @
9fb61cd3
package
com.example.pipelinenetwork.pojo.entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
lombok.Data
;
/**
* @Author: wujipeng
* @Description: TODO
* @Date: 2026/7/23 14:32
* @Version: 1.0
*/
@Data
@TableName
(
"repair"
)
public
class
RepairEntity
{
@TableId
(
type
=
IdType
.
AUTO
)
private
Long
id
;
/**
* 类型
*/
private
String
type
;
/**
* 缺称
*/
private
String
name
;
/**
* 等级
*/
private
String
level
;
/**
* 数量
*/
private
Integer
num
;
@TableField
(
value
=
"rel_id"
)
private
String
relId
;
}
src/main/java/com/example/pipelinenetwork/service/RepairService.java
0 → 100644
View file @
9fb61cd3
package
com.example.pipelinenetwork.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.example.pipelinenetwork.pojo.entity.RepairEntity
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
/**
* @Author: wujipeng
* @Description: TODO
* @Date: 2026/7/23 14:34
* @Version: 1.0
*/
public
interface
RepairService
extends
IService
<
RepairEntity
>
{
Boolean
importDefectData
(
MultipartFile
file
)
throws
IOException
;
}
src/main/java/com/example/pipelinenetwork/service/impl/DefectServiceImpl.java
View file @
9fb61cd3
...
@@ -92,20 +92,4 @@ public class DefectServiceImpl extends ServiceImpl<DefectMapper, DefectEntity> i
...
@@ -92,20 +92,4 @@ public class DefectServiceImpl extends ServiceImpl<DefectMapper, DefectEntity> i
return
null
;
return
null
;
}
}
}
}
/**
* 检查行是否为空
*/
private
boolean
isRowEmpty
(
Row
row
)
{
if
(
row
==
null
)
{
return
true
;
}
for
(
int
c
=
row
.
getFirstCellNum
();
c
<
row
.
getLastCellNum
();
c
++)
{
Cell
cell
=
row
.
getCell
(
c
);
if
(
cell
!=
null
&&
cell
.
getCellType
()
!=
CellType
.
BLANK
)
{
return
false
;
}
}
return
true
;
}
}
}
src/main/java/com/example/pipelinenetwork/service/impl/RepairServiceImpl.java
0 → 100644
View file @
9fb61cd3
package
com.example.pipelinenetwork.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.example.pipelinenetwork.mapper.RepairMapper
;
import
com.example.pipelinenetwork.pojo.entity.RepairEntity
;
import
com.example.pipelinenetwork.service.RepairService
;
import
org.apache.poi.ss.usermodel.*
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @Author: wujipeng
* @Description: TODO
* @Date: 2026/7/23 14:34
* @Version: 1.0
*/
@Service
public
class
RepairServiceImpl
extends
ServiceImpl
<
RepairMapper
,
RepairEntity
>
implements
RepairService
{
@Override
@Transactional
public
Boolean
importDefectData
(
MultipartFile
file
)
throws
IOException
{
List
<
RepairEntity
>
repairEntities
=
new
ArrayList
<>();
try
(
InputStream
inputStream
=
file
.
getInputStream
();
Workbook
workbook
=
WorkbookFactory
.
create
(
inputStream
))
{
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
for
(
int
i
=
0
;
i
<=
sheet
.
getLastRowNum
();
i
++)
{
RepairEntity
repair
=
new
RepairEntity
();
repair
.
setType
(
getCellStringValue
(
sheet
.
getRow
(
i
).
getCell
(
0
)));
repair
.
setName
(
getCellStringValue
(
sheet
.
getRow
(
i
).
getCell
(
1
)));
repair
.
setLevel
(
getCellStringValue
(
sheet
.
getRow
(
i
).
getCell
(
2
)));
repair
.
setNum
(
getCellIntValue
(
sheet
.
getRow
(
i
).
getCell
(
3
)));
repair
.
setRelId
(
getCellStringValue
(
sheet
.
getRow
(
i
).
getCell
(
4
)));
repairEntities
.
add
(
repair
);
}
return
saveBatch
(
repairEntities
);
}
}
/**
* 安全获取字符串单元格值
*/
private
String
getCellStringValue
(
Cell
cell
)
{
if
(
cell
==
null
)
{
return
null
;
}
switch
(
cell
.
getCellType
())
{
case
STRING:
return
cell
.
getStringCellValue
().
trim
();
case
NUMERIC:
// 处理数字转字符串的情况
double
value
=
cell
.
getNumericCellValue
();
if
(
value
==
Math
.
floor
(
value
)
&&
!
Double
.
isInfinite
(
value
))
{
return
String
.
valueOf
((
long
)
value
);
}
return
String
.
valueOf
(
value
);
case
BOOLEAN:
return
String
.
valueOf
(
cell
.
getBooleanCellValue
());
case
FORMULA:
try
{
return
cell
.
getStringCellValue
();
}
catch
(
IllegalStateException
e
)
{
return
String
.
valueOf
(
cell
.
getNumericCellValue
());
}
default
:
return
null
;
}
}
/**
* 安全获取整数单元格值
*/
private
Integer
getCellIntValue
(
Cell
cell
)
{
if
(
cell
==
null
)
{
return
null
;
}
switch
(
cell
.
getCellType
())
{
case
NUMERIC:
return
(
int
)
cell
.
getNumericCellValue
();
case
STRING:
try
{
return
Integer
.
parseInt
(
cell
.
getStringCellValue
().
trim
());
}
catch
(
NumberFormatException
e
)
{
return
null
;
}
default
:
return
null
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment