Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
warehouse
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
胡懿
warehouse
Commits
97caded9
Commit
97caded9
authored
Jun 06, 2023
by
胡懿
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加物资类型,
parent
22a350e9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
258 additions
and
6 deletions
+258
-6
MaterialType.java
...s/modules/warehouse/materialtype/entity/MaterialType.java
+10
-0
MaterialTypeMapper.xml
.../warehouse/materialtype/mapper/xml/MaterialTypeMapper.xml
+8
-4
MaterialTypeService.java
...s/warehouse/materialtype/service/MaterialTypeService.java
+22
-0
InitMaterialType.java
...odules/warehouse/materialtype/utils/InitMaterialType.java
+84
-0
POIUtil.java
...jeeplus/modules/warehouse/materialtype/utils/POIUtil.java
+83
-0
MaterialTypeController.java
...es/warehouse/materialtype/web/MaterialTypeController.java
+51
-2
No files found.
src/main/java/com/jeeplus/modules/warehouse/materialtype/entity/MaterialType.java
View file @
97caded9
...
...
@@ -17,6 +17,7 @@ public class MaterialType extends TreeEntity<MaterialType> {
private
static
final
long
serialVersionUID
=
1L
;
private
String
code
;
// 物资类型编码
private
int
last
;
public
MaterialType
()
{
...
...
@@ -48,4 +49,12 @@ public class MaterialType extends TreeEntity<MaterialType> {
public
String
getParentId
()
{
return
parent
!=
null
&&
parent
.
getId
()
!=
null
?
parent
.
getId
()
:
"0"
;
}
public
int
getLast
()
{
return
last
;
}
public
void
setLast
(
int
last
)
{
this
.
last
=
last
;
}
}
\ No newline at end of file
src/main/java/com/jeeplus/modules/warehouse/materialtype/mapper/xml/MaterialTypeMapper.xml
View file @
97caded9
...
...
@@ -23,7 +23,8 @@
a.parent_ids AS "parentIds",
a.name AS "name",
a.sort AS "sort",
a.code AS "code"
a.code AS "code",
a.last AS "last"
</sql>
...
...
@@ -117,7 +118,8 @@
parent_ids,
name,
sort,
code
code,
last
) VALUES (
#{id},
#{createBy.id},
...
...
@@ -130,7 +132,8 @@
#{parentIds},
#{name},
#{sort},
#{code}
#{code},
#{last}
)
</insert>
...
...
@@ -143,7 +146,8 @@
parent_ids = #{parentIds},
name = #{name},
sort = #{sort},
code = #{code}
code = #{code},
last = #{last}
WHERE id = #{id}
</update>
...
...
src/main/java/com/jeeplus/modules/warehouse/materialtype/service/MaterialTypeService.java
View file @
97caded9
...
...
@@ -35,8 +35,30 @@ public class MaterialTypeService extends TreeService<MaterialTypeMapper, Materia
@Transactional
(
readOnly
=
false
)
public
void
save
(
MaterialType
materialType
)
{
String
[]
parentIdsArr
=
materialType
.
getParentIds
().
split
(
","
);
if
(
parentIdsArr
.
length
>=
2
)
{
materialType
.
setLast
(
1
);
}
else
{
materialType
.
setLast
(
0
);
}
super
.
save
(
materialType
);
}
@Transactional
(
readOnly
=
false
)
public
void
insert
(
MaterialType
materialType
)
{
String
[]
parentIdsArr
=
materialType
.
getParentIds
().
split
(
","
);
if
(
parentIdsArr
.
length
>=
2
)
{
materialType
.
setLast
(
1
);
}
else
{
materialType
.
setLast
(
0
);
}
materialType
.
preInsert
();
mapper
.
insert
(
materialType
);
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
MaterialType
materialType
)
{
...
...
src/main/java/com/jeeplus/modules/warehouse/materialtype/utils/InitMaterialType.java
0 → 100644
View file @
97caded9
package
com
.
jeeplus
.
modules
.
warehouse
.
materialtype
.
utils
;
import
com.jeeplus.common.utils.StringUtils
;
import
com.jeeplus.modules.warehouse.materialtype.entity.MaterialType
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
public
class
InitMaterialType
{
public
static
List
<
MaterialType
>
initType
(
String
filePath
,
String
sheetName
,
String
parentId
,
String
parentIds
)
{
List
<
MaterialType
>
resultList
=
new
ArrayList
<>();
InputStream
fis
=
null
;
try
{
fis
=
new
FileInputStream
(
filePath
);
Workbook
workbook
=
null
;
if
(
filePath
.
endsWith
(
".xlsx"
))
{
workbook
=
new
XSSFWorkbook
(
fis
);
}
else
if
(
filePath
.
endsWith
(
".xls"
)
||
filePath
.
endsWith
(
".et"
))
{
workbook
=
new
HSSFWorkbook
(
fis
);
}
fis
.
close
();
/* 读EXCEL文字内容 */
// 获取第一个sheet表,也可使用sheet表名获取
Sheet
sheet
=
workbook
.
getSheet
(
sheetName
);
// 获取行
Iterator
<
Row
>
rows
=
sheet
.
rowIterator
();
Row
row
;
Cell
cell
;
int
sort
=
1
;
while
(
rows
.
hasNext
())
{
row
=
rows
.
next
();
cell
=
row
.
getCell
(
0
);
String
cellValue
=
POIUtil
.
getCellValue
(
cell
);
cell
=
row
.
getCell
(
1
);
String
cellValue1
=
POIUtil
.
getCellValue
(
cell
);
MaterialType
type
=
new
MaterialType
();
if
(
StringUtils
.
isBlank
(
cellValue
))
{
continue
;
}
if
(
"main"
.
equals
(
sheetName
))
{
type
.
setId
(
sort
+
""
);
}
type
.
setCode
(
cellValue
);
type
.
setName
(
cellValue1
);
type
.
setParent
(
new
MaterialType
(
parentId
));
type
.
setParentIds
(
parentIds
);
type
.
setSort
(
sort
);
resultList
.
add
(
type
);
sort
++;
}
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
null
!=
fis
)
{
try
{
fis
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
resultList
;
}
}
src/main/java/com/jeeplus/modules/warehouse/materialtype/utils/POIUtil.java
0 → 100644
View file @
97caded9
package
com
.
jeeplus
.
modules
.
warehouse
.
materialtype
.
utils
;
import
java.text.DateFormat
;
import
java.text.DecimalFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
org.apache.poi.hssf.usermodel.HSSFCell
;
import
org.apache.poi.hssf.usermodel.HSSFDateUtil
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.FormulaEvaluator
;
public
class
POIUtil
{
/**
* 获取cell中的值并返回String类型
*
* @param cell
* @return String类型的cell值
*/
public
static
String
getCellValue
(
Cell
cell
)
{
String
cellValue
=
""
;
if
(
null
!=
cell
)
{
// 以下是判断数据的类型
switch
(
cell
.
getCellType
())
{
case
HSSFCell
.
CELL_TYPE_NUMERIC
:
// 数字
if
(
0
==
cell
.
getCellType
())
{
// 判断单元格的类型是否则NUMERIC类型
if
(
HSSFDateUtil
.
isCellDateFormatted
(
cell
))
{
// 判断是否为日期类型
Date
date
=
cell
.
getDateCellValue
();
// DateFormat formater = new SimpleDateFormat("yyyy/MM/dd HH:mm");
DateFormat
formater
=
new
SimpleDateFormat
(
"yyyy/MM/dd"
);
cellValue
=
formater
.
format
(
date
);
}
else
{
// 有些数字过大,直接输出使用的是科学计数法: 2.67458622E8 要进行处理
DecimalFormat
df
=
new
DecimalFormat
(
"####.####"
);
cellValue
=
df
.
format
(
cell
.
getNumericCellValue
());
// cellValue = cell.getNumericCellValue() + "";
}
}
break
;
case
HSSFCell
.
CELL_TYPE_STRING
:
// 字符串
cellValue
=
cell
.
getStringCellValue
();
break
;
case
HSSFCell
.
CELL_TYPE_BOOLEAN
:
// Boolean
cellValue
=
cell
.
getBooleanCellValue
()
+
""
;
break
;
case
HSSFCell
.
CELL_TYPE_FORMULA
:
// 公式
try
{
// 如果公式结果为字符串
cellValue
=
String
.
valueOf
(
cell
.
getStringCellValue
());
}
catch
(
IllegalStateException
e
)
{
if
(
HSSFDateUtil
.
isCellDateFormatted
(
cell
))
{
// 判断是否为日期类型
Date
date
=
cell
.
getDateCellValue
();
// DateFormat formater = new SimpleDateFormat("yyyy/MM/dd HH:mm");
DateFormat
formater
=
new
SimpleDateFormat
(
"yyyy/MM/dd"
);
cellValue
=
formater
.
format
(
date
);
}
else
{
FormulaEvaluator
evaluator
=
cell
.
getSheet
().
getWorkbook
().
getCreationHelper
()
.
createFormulaEvaluator
();
evaluator
.
evaluateFormulaCell
(
cell
);
// 有些数字过大,直接输出使用的是科学计数法: 2.67458622E8 要进行处理
DecimalFormat
df
=
new
DecimalFormat
(
"####.####"
);
cellValue
=
df
.
format
(
cell
.
getNumericCellValue
());
// cellValue = cell.getNumericCellValue() + "";
}
}
// //直接获取公式
// cellValue = cell.getCellFormula() + "";
break
;
case
HSSFCell
.
CELL_TYPE_BLANK
:
// 空值
cellValue
=
""
;
break
;
case
HSSFCell
.
CELL_TYPE_ERROR
:
// 故障
cellValue
=
"非法字符"
;
break
;
default
:
cellValue
=
"未知类型"
;
break
;
}
}
return
cellValue
;
}
}
src/main/java/com/jeeplus/modules/warehouse/materialtype/web/MaterialTypeController.java
View file @
97caded9
...
...
@@ -3,12 +3,14 @@
*/
package
com
.
jeeplus
.
modules
.
warehouse
.
materialtype
.
web
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
com.jeeplus.modules.warehouse.materialtype.utils.InitMaterialType
;
import
org.apache.shiro.authz.annotation.Logical
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -23,7 +25,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.jeeplus.common.json.AjaxJson
;
import
com.jeeplus.common.config.Global
;
import
com.jeeplus.core.web.BaseController
;
import
com.jeeplus.common.utils.StringUtils
;
import
com.jeeplus.modules.warehouse.materialtype.entity.MaterialType
;
...
...
@@ -172,5 +173,52 @@ public class MaterialTypeController extends BaseController {
}
return
mapList
;
}
@ResponseBody
@RequestMapping
(
value
=
"initType"
)
public
AjaxJson
initType
()
throws
Exception
{
String
filePath
=
"D:\\yqd\\2023\\cangchuguanli\\warehouse\\doc\\PMDM.xlsx"
;
Map
<
String
,
String
>
codeIdMap
=
new
HashMap
<>();
List
<
MaterialType
>
materialTypeList
=
InitMaterialType
.
initType
(
filePath
,
"main"
,
"0"
,
"0,"
);
for
(
MaterialType
materialType
:
materialTypeList
)
{
materialTypeService
.
insert
(
materialType
);
codeIdMap
.
put
(
materialType
.
getCode
(),
materialType
.
getId
());
}
String
id
=
codeIdMap
.
get
(
"001"
);
List
<
MaterialType
>
materialTypeList1
=
InitMaterialType
.
initType
(
filePath
,
"07"
,
id
,
"0,"
+
id
+
","
);
for
(
MaterialType
materialType
:
materialTypeList1
)
{
materialTypeService
.
save
(
materialType
);
}
id
=
codeIdMap
.
get
(
"002"
);
List
<
MaterialType
>
materialTypeList2
=
InitMaterialType
.
initType
(
filePath
,
"0206"
,
id
,
"0,"
+
id
+
","
);
for
(
MaterialType
materialType
:
materialTypeList2
)
{
materialTypeService
.
save
(
materialType
);
}
id
=
codeIdMap
.
get
(
"003"
);
List
<
MaterialType
>
materialTypeList3
=
InitMaterialType
.
initType
(
filePath
,
"1821"
,
id
,
"0,"
+
id
+
","
);
for
(
MaterialType
materialType
:
materialTypeList3
)
{
materialTypeService
.
save
(
materialType
);
}
id
=
codeIdMap
.
get
(
"004"
);
List
<
MaterialType
>
materialTypeList4
=
InitMaterialType
.
initType
(
filePath
,
"21"
,
id
,
"0,"
+
id
+
","
);
for
(
MaterialType
materialType
:
materialTypeList4
)
{
materialTypeService
.
save
(
materialType
);
}
id
=
codeIdMap
.
get
(
"005"
);
List
<
MaterialType
>
materialTypeList5
=
InitMaterialType
.
initType
(
filePath
,
"qt"
,
id
,
"0,"
+
id
+
","
);
for
(
MaterialType
materialType
:
materialTypeList5
)
{
materialTypeService
.
save
(
materialType
);
}
AjaxJson
j
=
new
AjaxJson
();
j
.
setMsg
(
"初始化成功"
);
return
j
;
}
}
\ No newline at end of file
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