Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zhny
Project
Project
Details
Activity
Releases
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
王夏晖
zhny
Commits
b7d4aad6
Commit
b7d4aad6
authored
Jun 01, 2018
by
jichao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
改bug,增加基准碳排放量是否上传接口
parent
fce6ab98
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
6 deletions
+62
-6
EnergyEmissionPlanController.java
...iness/manage/controller/EnergyEmissionPlanController.java
+16
-3
EnergyEmissionPlanService.java
...ft/business/manage/service/EnergyEmissionPlanService.java
+7
-0
EnergyEmissionPlanServiceImpl.java
...ss/manage/service/impl/EnergyEmissionPlanServiceImpl.java
+36
-2
EnergyEmissionPlanRepository.java
...t/business/overview/dao/EnergyEmissionPlanRepository.java
+3
-1
No files found.
src/main/java/org/rcisoft/business/manage/controller/EnergyEmissionPlanController.java
View file @
b7d4aad6
...
...
@@ -5,6 +5,9 @@ import io.swagger.annotations.ApiImplicitParam;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.rcisoft.business.manage.service.EnergyEmissionPlanService
;
import
org.rcisoft.core.constant.MessageConstant
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.result.Result
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
...
...
@@ -32,13 +35,23 @@ public class EnergyEmissionPlanController {
energyEmissionPlanServiceImpl
.
downloadExcel
(
request
,
response
);
}
@ApiOperation
(
value
=
"
下载模板文件"
,
notes
=
"excel文件下载
"
)
@ApiOperation
(
value
=
"
上传模板文件"
,
notes
=
"excel文件上传
"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"proId"
,
value
=
"项目主键"
,
required
=
true
,
dataType
=
"字符串"
)
})
@RequestMapping
(
"/uploadExcel"
)
public
void
uploadExcel
(
@RequestParam
MultipartFile
file
,
@RequestParam
String
proId
)
{
energyEmissionPlanServiceImpl
.
uploadExcel
(
file
,
proId
);
public
Result
uploadExcel
(
@RequestParam
MultipartFile
file
,
@RequestParam
String
proId
)
{
Integer
result
=
energyEmissionPlanServiceImpl
.
uploadExcel
(
file
,
proId
);
return
new
Result
().
builder
(
new
PersistModel
(
result
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
result
);
}
@ApiOperation
(
value
=
"判断是否上传过"
,
notes
=
"判断是否上传过"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"proId"
,
value
=
"项目主键"
,
required
=
true
,
dataType
=
"字符串"
)
})
@RequestMapping
(
"/checkExcel"
)
public
Result
checkExcel
(
@RequestParam
String
proId
)
{
return
new
Result
().
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
energyEmissionPlanServiceImpl
.
checkExcel
(
proId
));
}
}
src/main/java/org/rcisoft/business/manage/service/EnergyEmissionPlanService.java
View file @
b7d4aad6
...
...
@@ -25,4 +25,11 @@ public interface EnergyEmissionPlanService {
*/
Integer
uploadExcel
(
MultipartFile
file
,
String
proId
);
/**
* 判断是否上传过
* @param proId
* @return
*/
Integer
checkExcel
(
String
proId
);
}
src/main/java/org/rcisoft/business/manage/service/impl/EnergyEmissionPlanServiceImpl.java
View file @
b7d4aad6
...
...
@@ -2,9 +2,11 @@ package org.rcisoft.business.manage.service.impl;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.hssf.usermodel.HSSFCell
;
import
org.apache.poi.hssf.usermodel.HSSFRow
;
import
org.apache.poi.hssf.usermodel.HSSFSheet
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.rcisoft.business.manage.service.EnergyEmissionPlanService
;
import
org.rcisoft.business.overview.dao.EnergyEmissionPlanRepository
;
import
org.rcisoft.business.overview.entity.EnergyEmissionPlan
;
...
...
@@ -13,6 +15,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.ResourceUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
tk.mybatis.mapper.entity.Example
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
...
...
@@ -83,11 +86,11 @@ public class EnergyEmissionPlanServiceImpl implements EnergyEmissionPlanService
HSSFRow
row
=
sheet
.
getRow
(
i
);
if
(
row
!=
null
)
{
// 如果第一列为空,认为已经结束,跳出循环
if
(
StringUtils
.
isEmpty
(
row
.
getCell
(
0
).
getStringCellValue
(
)))
break
;
if
(
StringUtils
.
isEmpty
(
this
.
getValue
(
row
.
getCell
(
0
)
)))
break
;
// 从第二列开始,读取12个月份
for
(
int
j
=
1
;
j
<
13
;
j
++)
{
// 获得单元格的值
String
emission
=
row
.
getCell
(
j
).
getStringCellValue
(
);
String
emission
=
this
.
getValue
(
row
.
getCell
(
j
)
);
if
(
StringUtils
.
isNotEmpty
(
emission
))
{
// id,proId,月,日,值
EnergyEmissionPlan
e
=
new
EnergyEmissionPlan
(
null
,
proId
,
j
,
i
,
new
BigDecimal
(
emission
));
...
...
@@ -114,4 +117,35 @@ public class EnergyEmissionPlanServiceImpl implements EnergyEmissionPlanService
}
return
result
;
}
@Override
public
Integer
checkExcel
(
String
proId
)
{
Example
example
=
new
Example
(
EnergyEmissionPlan
.
class
);
Example
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andEqualTo
(
"proId"
,
proId
);
return
energyEmissionPlanRepository
.
selectCountByExample
(
example
);
}
/**
* 读取cell的内容
* @param cell
* @return
*/
@SuppressWarnings
(
"deprecation"
)
private
String
getValue
(
HSSFCell
cell
)
{
if
(
cell
==
null
)
return
null
;
switch
(
cell
.
getCellType
())
{
case
Cell
.
CELL_TYPE_BOOLEAN
:
return
cell
.
getBooleanCellValue
()
?
"TRUE"
:
"FALSE"
;
case
Cell
.
CELL_TYPE_FORMULA
:
return
cell
.
getCellFormula
();
case
Cell
.
CELL_TYPE_NUMERIC
:
cell
.
setCellType
(
Cell
.
CELL_TYPE_STRING
);
return
cell
.
getStringCellValue
();
case
Cell
.
CELL_TYPE_STRING
:
return
cell
.
getStringCellValue
();
default
:
return
null
;
}
}
}
src/main/java/org/rcisoft/business/overview/dao/EnergyEmissionPlanRepository.java
View file @
b7d4aad6
package
org
.
rcisoft
.
business
.
overview
.
dao
;
import
org.apache.ibatis.annotations.Insert
;
import
org.apache.ibatis.annotations.ResultType
;
import
org.rcisoft.business.overview.entity.EnergyEmissionPlan
;
import
org.rcisoft.core.base.BaseMapper
;
import
org.apache.ibatis.annotations.ResultMap
;
...
...
@@ -30,10 +31,11 @@ public interface EnergyEmissionPlanRepository extends BaseMapper<EnergyEmissionP
* @param list
* @return
*/
@Insert
(
"<script><foreach collection=\"
resultL
ist\" item=\"item\" separator=\";\">"
+
@Insert
(
"<script><foreach collection=\"
l
ist\" item=\"item\" separator=\";\">"
+
"insert into energy_emission_plan(PRO_ID,MON,DAY,EMISSION) "
+
"values(#{item.proId},#{item.mon},#{item.day},#{item.emission})"
+
"</foreach></script>"
)
@ResultType
(
value
=
Integer
.
class
)
Integer
batchSave
(
List
<
EnergyEmissionPlan
>
list
);
}
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