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
42f2dd98
Commit
42f2dd98
authored
Sep 06, 2018
by
jichao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
公式
parent
f93f15b5
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
698 additions
and
2 deletions
+698
-2
FormulaController.java
.../business/device/report/controller/FormulaController.java
+68
-0
FormulaRepository.java
...rcisoft/business/device/report/dao/FormulaRepository.java
+37
-0
TotalDataRepository.java
...isoft/business/device/report/dao/TotalDataRepository.java
+22
-0
VariableRepository.java
...cisoft/business/device/report/dao/VariableRepository.java
+45
-0
Formula.java
...va/org/rcisoft/business/device/report/entity/Formula.java
+26
-0
TotalData.java
.../org/rcisoft/business/device/report/entity/TotalData.java
+28
-0
Variable.java
...a/org/rcisoft/business/device/report/entity/Variable.java
+29
-0
FormulaService.java
...cisoft/business/device/report/service/FormulaService.java
+85
-0
VariableService.java
...isoft/business/device/report/service/VariableService.java
+33
-0
FormulaServiceImpl.java
...siness/device/report/service/impl/FormulaServiceImpl.java
+201
-0
ReportServiceImpl.java
...usiness/device/report/service/impl/ReportServiceImpl.java
+3
-2
VariableServiceImpl.java
...iness/device/report/service/impl/VariableServiceImpl.java
+45
-0
FormulaVo.java
...java/org/rcisoft/business/device/report/vo/FormulaVo.java
+22
-0
UuidUtil.java
src/main/java/org/rcisoft/core/util/UuidUtil.java
+14
-0
FormulaMapper.xml
...main/resources/mapper/sys/device/report/FormulaMapper.xml
+13
-0
TotalDataMapper.xml
...in/resources/mapper/sys/device/report/TotalDataMapper.xml
+12
-0
VariableMapper.xml
...ain/resources/mapper/sys/device/report/VariableMapper.xml
+15
-0
No files found.
src/main/java/org/rcisoft/business/device/report/controller/FormulaController.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
business
.
device
.
report
.
controller
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.rcisoft.business.device.report.service.FormulaService
;
import
org.rcisoft.business.device.report.vo.FormulaVo
;
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.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletResponse
;
/**
* Created by JiChao on 2018/8/29.
* 公式
*/
@Api
(
tags
=
"设备报表--公式"
)
@RestController
@RequestMapping
(
"formula"
)
public
class
FormulaController
{
@Autowired
private
FormulaService
formulaServiceImpl
;
@ApiOperation
(
value
=
"新增公式和变量"
,
notes
=
"新增公式和变量"
)
@RequestMapping
(
"/addFormulaVariable"
)
public
Result
addFormulaVariable
(
@RequestBody
FormulaVo
formulaVo
)
{
Integer
result
=
formulaServiceImpl
.
addFormulaVariable
(
formulaVo
);
return
Result
.
builder
(
new
PersistModel
(
result
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
result
);
}
@ApiOperation
(
value
=
"修改公式和变量"
,
notes
=
"修改公式和变量"
)
@RequestMapping
(
"/updateFormulaVariable"
)
public
Result
updateFormulaVariable
(
@RequestBody
FormulaVo
formulaVo
)
{
Integer
result
=
formulaServiceImpl
.
updateFormulaVariable
(
formulaVo
);
return
Result
.
builder
(
new
PersistModel
(
result
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
result
);
}
@ApiOperation
(
value
=
"删除公式和变量"
,
notes
=
"删除公式和变量"
)
@RequestMapping
(
"/deleteFormulaVariable"
)
public
Result
deleteFormulaVariable
(
@RequestParam
String
formulaId
)
{
Integer
result
=
formulaServiceImpl
.
deleteFormulaVariable
(
formulaId
);
return
Result
.
builder
(
new
PersistModel
(
result
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
result
);
}
@ApiOperation
(
value
=
"查询公式和变量"
,
notes
=
"查询公式和变量"
)
@RequestMapping
(
"/selectFormulaVariable"
)
public
Result
selectFormulaVariable
(
@RequestParam
String
formulaId
)
{
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
formulaServiceImpl
.
selectFormulaVariable
(
formulaId
));
}
@ApiOperation
(
value
=
"查询公式列表"
,
notes
=
"查询公式列表"
)
@RequestMapping
(
"/selectFormulaList"
)
public
Result
selectFormulaList
(
@RequestParam
String
proId
)
{
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
formulaServiceImpl
.
selectFormulaList
(
proId
));
}
@ApiOperation
(
value
=
"导出公式"
,
notes
=
"导出公式"
)
@RequestMapping
(
"/downloadFormula"
)
public
void
downloadFormula
(
HttpServletResponse
response
,
String
formulaId
,
String
start
,
String
end
)
{
formulaServiceImpl
.
downloadFormula
(
response
,
formulaId
,
start
,
end
);
}
}
src/main/java/org/rcisoft/business/device/report/dao/FormulaRepository.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
business
.
device
.
report
.
dao
;
import
org.apache.ibatis.annotations.*
;
import
org.rcisoft.business.device.report.entity.Formula
;
import
org.springframework.stereotype.Repository
;
import
tk.mybatis.mapper.common.Mapper
;
import
java.util.List
;
/**
* Created by JiChao on 2018/8/29.
*/
@Repository
public
interface
FormulaRepository
extends
Mapper
<
Formula
>
{
@Insert
(
"<script>insert into bus_formula(ID, NAME, FORMULA, PRO_ID, CREATE_TIME) "
+
"values(#{id}, #{name}, #{formula}, #{proId}, #{createTime})</script>"
)
@ResultType
(
Integer
.
class
)
Integer
addFormula
(
Formula
formula
);
@Update
(
"<script>update bus_formula set NAME=#{name},FORMULA=#{formula} where ID=#{id}</script>"
)
@ResultType
(
Integer
.
class
)
Integer
updateFormula
(
Formula
formula
);
@Delete
(
"<script>delete from bus_formula where ID=#{id}</script>"
)
@ResultType
(
Integer
.
class
)
Integer
deleteFormula
(
@Param
(
"id"
)
String
id
);
@Select
(
"<script>select * from bus_formula where id = #{id}</script>"
)
@ResultMap
(
"formula"
)
Formula
selectFormula
(
@Param
(
"id"
)
String
id
);
@Select
(
"<script>select * from bus_formula where PRO_ID=#{proId} order by CREATE_TIME desc</script>"
)
@ResultMap
(
"formula"
)
List
<
Formula
>
selectFormulaList
(
@Param
(
"proId"
)
String
proId
);
}
src/main/java/org/rcisoft/business/device/report/dao/TotalDataRepository.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
business
.
device
.
report
.
dao
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.ResultMap
;
import
org.apache.ibatis.annotations.Select
;
import
org.rcisoft.business.device.report.entity.TotalData
;
import
org.springframework.stereotype.Repository
;
import
tk.mybatis.mapper.common.Mapper
;
import
java.util.List
;
/**
* Created by JiChao on 2018/9/3.
*/
@Repository
public
interface
TotalDataRepository
extends
Mapper
<
TotalData
>
{
@Select
(
"<script>select * from total_data where PRO_ID=#{proId} and tm between #{start} and #{end} order by tm asc</script>"
)
@ResultMap
(
"totalData"
)
List
<
TotalData
>
selectTotalData
(
@Param
(
"proId"
)
String
proId
,
@Param
(
"start"
)
String
start
,
@Param
(
"end"
)
String
end
);
}
src/main/java/org/rcisoft/business/device/report/dao/VariableRepository.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
business
.
device
.
report
.
dao
;
import
org.apache.ibatis.annotations.*
;
import
org.rcisoft.business.device.report.entity.Variable
;
import
org.springframework.stereotype.Repository
;
import
tk.mybatis.mapper.common.Mapper
;
import
java.util.List
;
/**
* Created by JiChao on 2018/8/29.
*/
@Repository
public
interface
VariableRepository
extends
Mapper
<
Variable
>
{
/**
* 批量新增
* @param list
* @return
*/
@Insert
(
"<script><foreach collection=\"list\" item=\"item\" separator=\";\">"
+
"insert into bus_variable(ID, VARIABLE, SOURCE, PARAM, FORMULA_ID, PRO_ID, CREATE_TIME, POSITION) "
+
"values(#{item.id}, #{item.variable}, #{item.source}, #{item.param}, #{item.formulaId}, #{item.proId}, #{item.createTime}, #{item.position})"
+
"</foreach></script>"
)
@ResultType
(
Integer
.
class
)
Integer
addVariable
(
List
<
Variable
>
list
);
/**
* 根据公式id删除变量
* @param formulaId
* @return
*/
@Delete
(
"<script>delete from bus_variable where FORMULA_ID = #{formulaId}</script>"
)
Integer
deleteVariable
(
@Param
(
"formulaId"
)
String
formulaId
);
/**
* 根据公式id查找所有变量
* @param formulaId
* @return
*/
@Select
(
"<script>select * from bus_variable where FORMULA_ID = #{formulaId} order by POSITION asc</script>"
)
@ResultMap
(
"variable"
)
List
<
Variable
>
selectVariable
(
@Param
(
"formulaId"
)
String
formulaId
);
}
src/main/java/org/rcisoft/business/device/report/entity/Formula.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
business
.
device
.
report
.
entity
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
javax.persistence.Entity
;
import
java.util.Date
;
/**
* Created by JiChao on 2018/8/29.
* 公式
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
Formula
{
private
String
id
;
private
String
name
;
private
String
formula
;
private
String
proId
;
private
Date
createTime
;
}
src/main/java/org/rcisoft/business/device/report/entity/TotalData.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
business
.
device
.
report
.
entity
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
javax.persistence.Entity
;
import
javax.persistence.Table
;
import
java.util.Date
;
/**
* Created by JiChao on 2018/8/28.
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
TotalData
{
private
Integer
id
;
private
String
proId
;
private
Date
tm
;
private
String
json
;
}
src/main/java/org/rcisoft/business/device/report/entity/Variable.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
business
.
device
.
report
.
entity
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
javax.persistence.Entity
;
import
java.util.Date
;
/**
* Created by JiChao on 2018/8/29.
* 变量
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
Variable
{
private
String
id
;
private
String
variable
;
private
String
source
;
private
String
param
;
private
String
formulaId
;
private
String
proId
;
private
Date
createTime
;
private
Integer
position
;
}
src/main/java/org/rcisoft/business/device/report/service/FormulaService.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
business
.
device
.
report
.
service
;
import
org.rcisoft.business.device.report.entity.Formula
;
import
org.rcisoft.business.device.report.vo.FormulaVo
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.List
;
/**
* Created by JiChao on 2018/8/31.
*/
public
interface
FormulaService
{
/**
* 新增公式
* @param formula
* @return
*/
Integer
addFormula
(
Formula
formula
);
/**
* 编辑公式
* @param formula
* @return
*/
Integer
updateFormula
(
Formula
formula
);
/**
* 删除公式
* @param id
* @return
*/
Integer
deleteFormula
(
String
id
);
/**
* 根据id查询
* @param id
* @return
*/
Formula
selectFormula
(
String
id
);
/**
* 根据项目id查询公式的list
* @param proId
* @return
*/
List
<
Formula
>
selectFormulaList
(
String
proId
);
/**
* 新增公式和变量
* @param formulaVo
* @return
*/
Integer
addFormulaVariable
(
FormulaVo
formulaVo
);
/**
* 编辑公式和变量
* @param formulaVo
* @return
*/
Integer
updateFormulaVariable
(
FormulaVo
formulaVo
);
/**
* 删除公式和变量
* @param formulaId
* @return
*/
Integer
deleteFormulaVariable
(
String
formulaId
);
/**
* 根据公式id查询公式和其所拥有的变量
* @param formulaId
* @return
*/
FormulaVo
selectFormulaVariable
(
String
formulaId
);
/**
* 导出公式excel数据
* @param formulaId 公式id
* @param start 开始时间
* @param end 结束时间
*/
void
downloadFormula
(
HttpServletResponse
response
,
String
formulaId
,
String
start
,
String
end
);
}
src/main/java/org/rcisoft/business/device/report/service/VariableService.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
business
.
device
.
report
.
service
;
import
org.rcisoft.business.device.report.entity.Variable
;
import
java.util.List
;
/**
* Created by JiChao on 2018/8/31.
*/
public
interface
VariableService
{
/**
* 批量新增变量
* @param list
* @return
*/
Integer
addVariable
(
List
<
Variable
>
list
,
String
formulaId
,
String
proId
);
/**
* 根据公式id删除所有变量
* @param formulaId
* @return
*/
Integer
deleteVariable
(
String
formulaId
);
/**
* 根据公式id查找所有变量
* @param formulaId
* @return
*/
List
<
Variable
>
selectVariable
(
String
formulaId
);
}
src/main/java/org/rcisoft/business/device/report/service/impl/FormulaServiceImpl.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
business
.
device
.
report
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.greenpineyu.fel.FelEngine
;
import
com.greenpineyu.fel.FelEngineImpl
;
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.CellType
;
import
org.rcisoft.business.device.report.dao.FormulaRepository
;
import
org.rcisoft.business.device.report.dao.TotalDataRepository
;
import
org.rcisoft.business.device.report.entity.Formula
;
import
org.rcisoft.business.device.report.entity.TotalData
;
import
org.rcisoft.business.device.report.entity.Variable
;
import
org.rcisoft.business.device.report.service.FormulaService
;
import
org.rcisoft.business.device.report.service.VariableService
;
import
org.rcisoft.business.device.report.vo.FormulaVo
;
import
org.rcisoft.core.util.UuidUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
/**
* Created by JiChao on 2018/8/31.
*/
@Service
public
class
FormulaServiceImpl
implements
FormulaService
{
@Autowired
private
FormulaRepository
formulaRepository
;
@Autowired
private
VariableService
variableServiceImpl
;
@Autowired
private
TotalDataRepository
totalDataRepository
;
@Override
public
Integer
addFormula
(
Formula
formula
)
{
formula
.
setCreateTime
(
new
Date
());
return
formulaRepository
.
addFormula
(
formula
);
}
@Override
public
Integer
updateFormula
(
Formula
formula
)
{
return
formulaRepository
.
updateFormula
(
formula
);
}
@Override
public
Integer
deleteFormula
(
String
id
)
{
return
formulaRepository
.
deleteFormula
(
id
);
}
@Override
public
Formula
selectFormula
(
String
id
)
{
return
formulaRepository
.
selectFormula
(
id
);
}
@Override
public
List
<
Formula
>
selectFormulaList
(
String
proId
)
{
return
formulaRepository
.
selectFormulaList
(
proId
);
}
@Transactional
@Override
public
Integer
addFormulaVariable
(
FormulaVo
formulaVo
)
{
Formula
formula
=
formulaVo
.
getFormula
();
String
uuid
=
UuidUtil
.
create32
();
formula
.
setId
(
uuid
);
Integer
i
=
this
.
addFormula
(
formula
);
Integer
k
=
variableServiceImpl
.
addVariable
(
formulaVo
.
getVariableList
(),
uuid
,
formula
.
getProId
());
return
i
;
}
@Transactional
@Override
public
Integer
updateFormulaVariable
(
FormulaVo
formulaVo
)
{
Formula
formula
=
formulaVo
.
getFormula
();
String
id
=
formula
.
getId
();
Integer
i
=
this
.
updateFormula
(
formula
);
Integer
j
=
variableServiceImpl
.
deleteVariable
(
id
);
Integer
k
=
variableServiceImpl
.
addVariable
(
formulaVo
.
getVariableList
(),
id
,
formula
.
getProId
());
return
i
;
}
@Transactional
@Override
public
Integer
deleteFormulaVariable
(
String
formulaId
)
{
Integer
i
=
this
.
deleteFormula
(
formulaId
);
Integer
j
=
variableServiceImpl
.
deleteVariable
(
formulaId
);
return
i
;
}
@Transactional
@Override
public
FormulaVo
selectFormulaVariable
(
String
formulaId
)
{
Formula
formula
=
this
.
selectFormula
(
formulaId
);
List
<
Variable
>
variableList
=
variableServiceImpl
.
selectVariable
(
formulaId
);
return
new
FormulaVo
(
formula
,
variableList
);
}
@Override
public
void
downloadFormula
(
HttpServletResponse
response
,
String
formulaId
,
String
start
,
String
end
)
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
// 公式计算
FelEngine
fel
=
new
FelEngineImpl
();
// 根据id查找公式
Formula
formula
=
this
.
selectFormula
(
formulaId
);
// 根据id查找变量
List
<
Variable
>
variableList
=
variableServiceImpl
.
selectVariable
(
formulaId
);
// 根据proId和时间区间,查找数据list
String
proId
=
formula
.
getProId
();
start
=
start
+
" 00:00:00"
;
end
=
end
+
" 23:59:59"
;
List
<
TotalData
>
totalDataList
=
totalDataRepository
.
selectTotalData
(
proId
,
start
,
end
);
// 生成excel
HSSFWorkbook
workbook
=
new
HSSFWorkbook
();
//定义sheet
HSSFSheet
sheet
=
workbook
.
createSheet
(
"sheet1"
);
// 创建第一行
int
i
=
0
;
HSSFRow
head
=
sheet
.
createRow
(
i
++);
head
.
createCell
(
0
,
CellType
.
STRING
).
setCellValue
(
"时间"
);
head
.
createCell
(
1
,
CellType
.
STRING
).
setCellValue
(
"数值"
);
// 循环数据list
for
(
TotalData
totalData
:
totalDataList
)
{
// 创建row
HSSFRow
row
=
sheet
.
createRow
(
i
++);
// 公式
String
f
=
formula
.
getFormula
();
// 得到原始数据
String
json
=
totalData
.
getJson
();
// 变成json对象
JSONObject
jsonObject
=
JSON
.
parseObject
(
json
);
// 循环变量list
for
(
Variable
variable
:
variableList
)
{
// 公式中的变量
String
v
=
variable
.
getVariable
();
// 来源
String
s
=
variable
.
getSource
();
// 参数
String
p
=
variable
.
getParam
();
// 根据来源参数,获取json中对应的值
String
value
=
null
;
JSONObject
s_json
=
(
JSONObject
)
jsonObject
.
get
(
s
);
if
(
s_json
!=
null
)
{
JSONObject
r_json
=
(
JSONObject
)
s_json
.
get
(
"REG_VAL"
);
if
(
r_json
!=
null
)
{
Object
p_json
=
r_json
.
get
(
p
);
if
(
p_json
!=
null
)
{
value
=
p_json
.
toString
();
}
}
}
if
(
value
!=
null
)
// 替换公式
f
=
f
.
replaceAll
(
v
,
value
);
}
// 判断表达式是否由数字和运算符号组成
boolean
flag
=
true
;
String
[]
split
=
f
.
split
(
""
);
for
(
String
s
:
split
)
{
if
(!
s
.
matches
(
"\\d|\\(|\\)|\\+|\\-|\\*|/|%|\\."
))
flag
=
false
;
}
String
eval
=
""
;
// 计算出公式的最终结果
if
(
flag
)
{
Object
result
=
fel
.
eval
(
f
);
if
(
result
!=
null
)
{
eval
=
result
.
toString
();
}
}
// String eval = fel.eval(f).toString();
// 放入row中
row
.
createCell
(
0
,
CellType
.
STRING
).
setCellValue
(
sdf
.
format
(
totalData
.
getTm
()));
row
.
createCell
(
1
,
CellType
.
STRING
).
setCellValue
(
eval
);
}
//下载
try
(
OutputStream
outputStream
=
response
.
getOutputStream
())
{
//设置下载头
response
.
setHeader
(
"Content-disposition"
,
"attachment;filename="
+
formulaId
+
".xls"
);
workbook
.
write
(
outputStream
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
workbook
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
src/main/java/org/rcisoft/business/device/report/service/impl/ReportServiceImpl.java
View file @
42f2dd98
...
...
@@ -67,10 +67,11 @@ public class ReportServiceImpl implements ReportService {
if
(!
file
.
getParentFile
().
exists
())
file
.
getParentFile
().
mkdirs
();
try
(
OutputStream
outputStream
=
response
.
getOutputStream
())
{
// 如果已经存在文件,直接下载
if
(!
file
.
exists
())
{
//
if (!file.exists()) {
// 不存在直接生成一个文件,生成文件太耗时间
// 总会出问题,还是每次都生成吧
file
=
this
.
createExcel
(
proId
,
year
,
month
,
day
,
file
);
}
//
}
//转成字节
bytes
=
FileUtils
.
readFileToByteArray
(
file
);
//设置下载头
...
...
src/main/java/org/rcisoft/business/device/report/service/impl/VariableServiceImpl.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
business
.
device
.
report
.
service
.
impl
;
import
org.rcisoft.business.device.report.dao.VariableRepository
;
import
org.rcisoft.business.device.report.entity.Variable
;
import
org.rcisoft.business.device.report.service.VariableService
;
import
org.rcisoft.core.util.UuidUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
/**
* Created by JiChao on 2018/8/31.
*/
@Service
public
class
VariableServiceImpl
implements
VariableService
{
@Autowired
private
VariableRepository
variableRepository
;
@Override
public
Integer
addVariable
(
List
<
Variable
>
list
,
String
formulaId
,
String
proId
)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Variable
variable
=
list
.
get
(
i
);
variable
.
setId
(
UuidUtil
.
create32
());
variable
.
setFormulaId
(
formulaId
);
variable
.
setProId
(
proId
);
variable
.
setCreateTime
(
new
Date
());
variable
.
setPosition
(
i
);
}
return
variableRepository
.
addVariable
(
list
);
}
@Override
public
Integer
deleteVariable
(
String
formulaId
)
{
return
variableRepository
.
deleteVariable
(
formulaId
);
}
@Override
public
List
<
Variable
>
selectVariable
(
String
formulaId
)
{
return
variableRepository
.
selectVariable
(
formulaId
);
}
}
src/main/java/org/rcisoft/business/device/report/vo/FormulaVo.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
business
.
device
.
report
.
vo
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.rcisoft.business.device.report.entity.Formula
;
import
org.rcisoft.business.device.report.entity.Variable
;
import
java.util.List
;
/**
* Created by JiChao on 2018/8/31.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
FormulaVo
{
private
Formula
formula
;
private
List
<
Variable
>
variableList
;
}
src/main/java/org/rcisoft/core/util/UuidUtil.java
0 → 100644
View file @
42f2dd98
package
org
.
rcisoft
.
core
.
util
;
import
java.util.UUID
;
/**
* Created by JiChao on 2018/8/31.
*/
public
class
UuidUtil
{
public
static
String
create32
()
{
return
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
}
}
src/main/resources/mapper/sys/device/report/FormulaMapper.xml
0 → 100644
View file @
42f2dd98
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"org.rcisoft.business.device.report.dao.FormulaRepository"
>
<resultMap
id=
"formula"
type=
"org.rcisoft.business.device.report.entity.Formula"
>
<id
column=
"ID"
jdbcType=
"VARCHAR"
property=
"id"
></id>
<result
column=
"NAME"
jdbcType=
"VARCHAR"
property=
"name"
/>
<result
column=
"FORMULA"
jdbcType=
"VARCHAR"
property=
"formula"
/>
<result
column=
"PRO_ID"
jdbcType=
"VARCHAR"
property=
"proId"
/>
<result
column=
"CREATE_TIME"
jdbcType=
"TIMESTAMP"
property=
"createTime"
/>
</resultMap>
</mapper>
\ No newline at end of file
src/main/resources/mapper/sys/device/report/TotalDataMapper.xml
0 → 100644
View file @
42f2dd98
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"org.rcisoft.business.device.report.dao.TotalDataRepository"
>
<resultMap
id=
"totalData"
type=
"org.rcisoft.business.device.report.entity.TotalData"
>
<id
column=
"ID"
jdbcType=
"VARCHAR"
property=
"id"
></id>
<result
column=
"PRO_ID"
jdbcType=
"VARCHAR"
property=
"proId"
/>
<result
column=
"TM"
jdbcType=
"TIMESTAMP"
property=
"tm"
/>
<result
column=
"JSON"
jdbcType=
"VARCHAR"
property=
"json"
/>
</resultMap>
</mapper>
\ No newline at end of file
src/main/resources/mapper/sys/device/report/VariableMapper.xml
0 → 100644
View file @
42f2dd98
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"org.rcisoft.business.device.report.dao.VariableRepository"
>
<resultMap
id=
"variable"
type=
"org.rcisoft.business.device.report.entity.Variable"
>
<id
column=
"ID"
jdbcType=
"VARCHAR"
property=
"id"
></id>
<result
column=
"VARIABLE"
jdbcType=
"VARCHAR"
property=
"variable"
/>
<result
column=
"SOURCE"
jdbcType=
"VARCHAR"
property=
"source"
/>
<result
column=
"FORMULA_ID"
jdbcType=
"VARCHAR"
property=
"formulaId"
/>
<result
column=
"PRO_ID"
jdbcType=
"VARCHAR"
property=
"proId"
/>
<result
column=
"CREATE_TIME"
jdbcType=
"TIMESTAMP"
property=
"createTime"
/>
<result
column=
"POSITION"
jdbcType=
"INTEGER"
property=
"position"
/>
</resultMap>
</mapper>
\ 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