Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
slm-bi
Project
Project
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
林锐标
slm-bi
Commits
6cea78a6
Commit
6cea78a6
authored
Apr 20, 2021
by
linruibiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口编写
parent
87ed373b
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
115 additions
and
38 deletions
+115
-38
RestTemplateUtils.java
.../java/com/syc/slm/common/core/util/RestTemplateUtils.java
+46
-25
BaseRestController.java
...java/com/syc/slm/slmbi/controller/BaseRestController.java
+4
-1
BusinessConfigController.java
...om/syc/slm/slmbi/controller/BusinessConfigController.java
+10
-4
BusinessDTO.java
src/main/java/com/syc/slm/slmbi/dto/BusinessDTO.java
+4
-2
BusinessConfigService.java
...java/com/syc/slm/slmbi/service/BusinessConfigService.java
+11
-0
BusinessConfigServiceImpl.java
...syc/slm/slmbi/service/impl/BusinessConfigServiceImpl.java
+34
-0
DeptServiceImpl.java
.../java/com/syc/slm/slmbi/service/impl/DeptServiceImpl.java
+1
-1
InstrumentPanelTreeServiceImpl.java
...lm/slmbi/service/impl/InstrumentPanelTreeServiceImpl.java
+1
-1
PositionServiceImpl.java
...a/com/syc/slm/slmbi/service/impl/PositionServiceImpl.java
+1
-1
UserServiceImpl.java
.../java/com/syc/slm/slmbi/service/impl/UserServiceImpl.java
+1
-1
VariableServiceImpl.java
...a/com/syc/slm/slmbi/service/impl/VariableServiceImpl.java
+2
-2
No files found.
src/main/java/com/syc/slm/common/core/util/RestTemplateUtils.java
View file @
6cea78a6
...
...
@@ -23,6 +23,49 @@ public final class RestTemplateUtils {
private
static
final
RestTemplate
REST_TEMPLATE
=
new
RestTemplate
();
public
static
<
TResult
>
TResult
get
(
String
url
,
Map
<
String
,
String
>
headerMap
,
final
Type
resultType
,
Map
<
String
,
?>
uriVariables
)
{
try
{
ResponseEntity
<
String
>
response
=
get
(
url
,
headerMap
,
String
.
class
,
uriVariables
);
if
(
response
.
getStatusCodeValue
()==
200
){
if
(
resultType
.
equals
(
String
.
class
))
{
return
(
TResult
)
response
.
getBody
();
}
return
SlmConstants
.
gson
.
fromJson
(
response
.
getBody
(),
resultType
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
SysException
(
"出错啦,请联系管理员"
,
e
.
toString
());
}
return
null
;
}
public
static
<
TResult
>
TResult
post
(
String
url
,
Map
<
String
,
String
>
headerMap
,
Object
requestBody
,
final
Type
resultType
,
Map
<
String
,
?>
uriVariables
)
{
try
{
ResponseEntity
<
String
>
response
=
post
(
url
,
headerMap
,
requestBody
,
String
.
class
,
uriVariables
);
if
(
response
.
getStatusCodeValue
()==
200
){
if
(
resultType
.
equals
(
String
.
class
))
{
return
(
TResult
)
response
.
getBody
();
}
return
SlmConstants
.
gson
.
fromJson
(
response
.
getBody
(),
resultType
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
SysException
(
"出错啦,请联系管理员"
,
e
.
toString
());
}
return
null
;
}
//#region ----------------------------------GET-------------------------------------------------------
/**
...
...
@@ -76,31 +119,6 @@ public final class RestTemplateUtils {
}
public
static
<
TResult
>
TResult
get
(
String
url
,
Map
<
String
,
String
>
headerMap
,
final
Type
resultType
,
Map
<
String
,
?>
uriVariables
)
{
try
{
ResponseEntity
<
String
>
response
=
get
(
url
,
headerMap
,
String
.
class
,
uriVariables
);
if
(
response
.
getStatusCodeValue
()==
200
){
if
(
resultType
.
equals
(
String
.
class
))
{
return
(
TResult
)
response
.
getBody
();
}
return
SlmConstants
.
gson
.
fromJson
(
response
.
getBody
(),
resultType
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
SysException
(
"出错啦,请联系管理员"
,
e
.
toString
());
}
return
null
;
}
/**
* 带请求头的GET请求调用方式
*
...
...
@@ -212,6 +230,9 @@ public final class RestTemplateUtils {
return
post
(
url
,
httpHeaders
,
requestBody
,
responseType
,
uriVariables
);
}
/**
* 带请求头的POST请求调用方式
*
...
...
src/main/java/com/syc/slm/slmbi/controller/BaseRestController.java
View file @
6cea78a6
...
...
@@ -60,6 +60,9 @@ public class BaseRestController {
@Value
(
"${dc_client.interfaces.deptsRoles}"
)
protected
String
deptsRoles
;
@Value
(
"${dc_client.interfaces.businessFiledData}"
)
protected
String
businessFiledData
;
...
...
@@ -90,7 +93,7 @@ public class BaseRestController {
Map
<
String
,
String
>
map
=
(
Map
<
String
,
String
>)
webRequest
.
getAttribute
(
HandlerMapping
.
URI_TEMPLATE_VARIABLES_ATTRIBUTE
,
RequestAttributes
.
SCOPE_REQUEST
);
// Map<String, Object> map = (Map<String, Object>) webRequest.getAttribute(View.PATH_VARIABLES, RequestAttributes.SCOPE_REQUEST);
Map
<
String
,
String
>
heads
=
Maps
.
newHashMap
();
heads
.
put
(
"
t
oken"
,
token
);
heads
.
put
(
"
X-T
oken"
,
token
);
Map
<
String
,
String
>
uriVariables
=
Maps
.
newHashMap
();
uriVariables
.
put
(
"appId"
,
map
.
get
(
"appId"
)+
""
);
String
getUrl
=
dcClientHost
+
"/{appId}/users/user-info"
;
...
...
src/main/java/com/syc/slm/slmbi/controller/BusinessConfigController.java
View file @
6cea78a6
package
com
.
syc
.
slm
.
slmbi
.
controller
;
import
com.syc.slm.common.core.util.R
;
import
com.syc.slm.slmbi.dto.BusinessDTO
;
import
com.syc.slm.slmbi.service.BusinessConfigService
;
import
com.syc.slm.slmbi.vo.BusinessConfigVo
;
import
io.swagger.annotations.Api
;
...
...
@@ -8,12 +9,10 @@ import io.swagger.annotations.ApiImplicitParam;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
java.util.Map
;
/**
* slm-bi
...
...
@@ -46,4 +45,11 @@ public class BusinessConfigController extends BaseRestController{
public
R
<
BusinessConfigVo
>
selectOneConfig
(
@PathVariable
String
appId
,
@PathVariable
String
id
)
{
return
call
(()->(
businessConfigService
.
selectOneConfig
(
id
)));
}
@PostMapping
(
"/filed"
)
@ApiOperation
(
"根据配置字段获取字段数据"
)
@ApiImplicitParam
(
name
=
"appId"
,
value
=
"租户id"
,
required
=
true
,
dataTypeClass
=
String
.
class
)
public
R
<
List
<
Map
<
String
,
Object
>>>
getBusinessData
(
@PathVariable
String
appId
,
@RequestBody
BusinessDTO
dto
)
{
return
call
(()->(
businessConfigService
.
getBusinessData
(
dto
,
businessFiledData
,
currentUser
)));
}
}
src/main/java/com/syc/slm/slmbi/dto/BusinessDTO.java
View file @
6cea78a6
...
...
@@ -17,8 +17,10 @@ import java.util.List;
public
class
BusinessDTO
{
@ApiModelProperty
(
value
=
"查询表名"
,
required
=
true
)
private
String
table
;
@ApiModelProperty
(
value
=
"查询配置的字段"
,
required
=
true
)
private
String
filed
;
@ApiModelProperty
(
value
=
"纵轴变量"
,
required
=
true
)
private
String
y
;
@ApiModelProperty
(
value
=
"横轴纬度"
,
required
=
true
)
private
String
x
;
@ApiModelProperty
(
value
=
"查询配置的时间区间(如果为空不要调用后台)"
,
required
=
true
)
List
<
BusinessConditionDTO
>
where
;
@ApiModelProperty
(
value
=
"统计类型(平均值 avg ,合计值 sum, 最大值 max ,最小值 min,中位数 middle ,原值 original)"
,
required
=
true
)
...
...
src/main/java/com/syc/slm/slmbi/service/BusinessConfigService.java
View file @
6cea78a6
package
com
.
syc
.
slm
.
slmbi
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.syc.slm.slmbi.dto.BusinessDTO
;
import
com.syc.slm.slmbi.entity.BusinessConfig
;
import
com.syc.slm.slmbi.entity.CurrentUser
;
import
com.syc.slm.slmbi.vo.BusinessConfigVo
;
import
java.util.List
;
import
java.util.Map
;
/**
* slm-bi
...
...
@@ -26,4 +29,12 @@ public interface BusinessConfigService extends IService<BusinessConfig> {
*/
BusinessConfigVo
selectOneConfig
(
String
id
);
/**
* 字段数据
* @param dto
* @param uri
* @param user
* @return
*/
List
<
Map
<
String
,
Object
>>
getBusinessData
(
BusinessDTO
dto
,
String
uri
,
CurrentUser
user
);
}
src/main/java/com/syc/slm/slmbi/service/impl/BusinessConfigServiceImpl.java
View file @
6cea78a6
...
...
@@ -6,11 +6,16 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.google.gson.reflect.TypeToken
;
import
com.syc.slm.common.core.constant.SlmConstants
;
import
com.syc.slm.common.core.util.R
;
import
com.syc.slm.common.core.util.RestTemplateUtils
;
import
com.syc.slm.slmbi.dao.BusinessConfigMapper
;
import
com.syc.slm.slmbi.dto.BusinessDTO
;
import
com.syc.slm.slmbi.entity.BaseEntity
;
import
com.syc.slm.slmbi.entity.BusinessConfig
;
import
com.syc.slm.slmbi.entity.CurrentUser
;
import
com.syc.slm.slmbi.exception.SysException
;
import
com.syc.slm.slmbi.service.BusinessConfigService
;
import
com.syc.slm.slmbi.vo.BusinessConfigVo
;
...
...
@@ -20,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
import
java.net.URLDecoder
;
import
java.nio.charset.StandardCharsets
;
import
java.util.List
;
import
java.util.Map
;
/**
* slm-bi
...
...
@@ -72,4 +78,32 @@ public class BusinessConfigServiceImpl extends ServiceImpl<BusinessConfigMapper,
}
return
ObjectUtils
.
isNotEmpty
(
co
)?
SlmConstants
.
gson
.
fromJson
(
SlmConstants
.
gson
.
toJson
(
co
),
BusinessConfigVo
.
class
):
null
;
}
@Override
@Transactional
(
readOnly
=
true
)
public
List
<
Map
<
String
,
Object
>>
getBusinessData
(
BusinessDTO
dto
,
String
uri
,
CurrentUser
user
)
{
if
(
StringUtils
.
isBlank
(
dto
.
getTable
())){
throw
new
SysException
(
"请传入对应的表名"
);
}
if
(
StringUtils
.
isBlank
(
dto
.
getStatisticsType
())){
throw
new
SysException
(
"统计类型不能为空"
);
}
if
(
StringUtils
.
isBlank
(
dto
.
getX
())){
throw
new
SysException
(
"x轴维度不能为空"
);
}
if
(
StringUtils
.
isBlank
(
dto
.
getY
())){
throw
new
SysException
(
"y轴配置字段不能为空"
);
}
if
(
CollectionUtils
.
isEmpty
(
dto
.
getWhere
())){
throw
new
SysException
(
"where 条件不能为空"
);
}
if
(
dto
.
getWhere
().
stream
().
anyMatch
(
x
->
StringUtils
.
isBlank
(
x
.
getKey
()))
||
dto
.
getWhere
().
stream
().
anyMatch
(
x
->
StringUtils
.
isBlank
(
x
.
getValue
()))
||
dto
.
getWhere
().
stream
().
anyMatch
(
x
->
StringUtils
.
isBlank
(
x
.
getQueryType
())))
{
throw
new
SysException
(
"where 条件不能key value queryType 都不能为空"
);
}
Map
<
String
,
String
>
heads
=
Maps
.
newHashMap
();
heads
.
put
(
"X-Token"
,
user
.
getToken
());
R
<
List
<
Map
<
String
,
Object
>>>
result
=
RestTemplateUtils
.
post
(
uri
,
heads
,
dto
,
new
TypeToken
<
R
<
List
<
Map
<
String
,
Object
>>>>()
{}.
getType
(),
null
);
return
result
.
detach
();
}
}
src/main/java/com/syc/slm/slmbi/service/impl/DeptServiceImpl.java
View file @
6cea78a6
...
...
@@ -29,7 +29,7 @@ public class DeptServiceImpl implements DeptService {
log
.
info
(
"部门查询uri:---------------->"
+
uri
);
log
.
info
(
"部门查询token:---------------->"
+
token
);
Map
<
String
,
String
>
heads
=
Maps
.
newHashMap
();
heads
.
put
(
"
t
oken"
,
token
);
heads
.
put
(
"
X-T
oken"
,
token
);
Map
<
String
,
String
>
uriVariables
=
Maps
.
newHashMap
();
uriVariables
.
put
(
"deptName"
,
deptName
);
uriVariables
.
put
(
"appId"
,
appId
);
...
...
src/main/java/com/syc/slm/slmbi/service/impl/InstrumentPanelTreeServiceImpl.java
View file @
6cea78a6
...
...
@@ -416,7 +416,7 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
private
R
<
Map
<
String
,
String
>>
setDeptAndRole
(
CurrentUser
user
,
String
uri
){
Map
<
String
,
String
>
heads
=
Maps
.
newHashMap
();
heads
.
put
(
"
t
oken"
,
user
.
getToken
());
heads
.
put
(
"
X-T
oken"
,
user
.
getToken
());
Map
<
String
,
String
>
uriVariables
=
Maps
.
newHashMap
();
uriVariables
.
put
(
"appId"
,
user
.
getAppId
());
return
RestTemplateUtils
.
get
(
uri
,
heads
,
new
TypeToken
<
R
<
Map
<
String
,
String
>>>()
{}.
getType
(),
uriVariables
);
...
...
src/main/java/com/syc/slm/slmbi/service/impl/PositionServiceImpl.java
View file @
6cea78a6
...
...
@@ -28,7 +28,7 @@ public class PositionServiceImpl implements PositionService {
@Override
public
List
<
PositionVo
>
selectPositionList
(
String
uri
,
String
token
,
String
appId
,
String
name
)
{
Map
<
String
,
String
>
heads
=
Maps
.
newHashMap
();
heads
.
put
(
"
t
oken"
,
token
);
heads
.
put
(
"
X-T
oken"
,
token
);
Map
<
String
,
String
>
uriVariables
=
Maps
.
newHashMap
();
uriVariables
.
put
(
"positionName"
,
name
);
uriVariables
.
put
(
"appId"
,
appId
);
...
...
src/main/java/com/syc/slm/slmbi/service/impl/UserServiceImpl.java
View file @
6cea78a6
...
...
@@ -27,7 +27,7 @@ public class UserServiceImpl implements UserService {
@Override
public
List
<
UserTreeVo
>
selectUserList
(
String
appId
,
String
uri
,
String
token
,
String
userName
)
{
Map
<
String
,
String
>
heads
=
Maps
.
newHashMap
();
heads
.
put
(
"
t
oken"
,
token
);
heads
.
put
(
"
X-T
oken"
,
token
);
Map
<
String
,
String
>
uriVariables
=
Maps
.
newHashMap
();
uriVariables
.
put
(
"userName"
,
userName
);
uriVariables
.
put
(
"appId"
,
appId
);
...
...
src/main/java/com/syc/slm/slmbi/service/impl/VariableServiceImpl.java
View file @
6cea78a6
...
...
@@ -48,7 +48,7 @@ public class VariableServiceImpl implements VariableService {
p
.
put
(
"current"
,
variableDTO
.
getCurrent
()+
""
);
p
.
put
(
"size"
,
variableDTO
.
getSize
()+
""
);
Map
<
String
,
String
>
heads
=
Maps
.
newHashMap
();
heads
.
put
(
"
t
oken"
,
token
);
heads
.
put
(
"
X-T
oken"
,
token
);
R
<
Map
<
String
,
Object
>>
result
=
RestTemplateUtils
.
get
(
uri
,
heads
,
new
TypeToken
<
R
<
Map
<
String
,
Object
>>>()
{
}.
getType
(),
p
);
...
...
@@ -99,7 +99,7 @@ public class VariableServiceImpl implements VariableService {
p
.
put
(
"page_num"
,
queryPageDTO
.
getCurrent
()
+
""
);
p
.
put
(
"page_size"
,
queryPageDTO
.
getSize
()
+
""
);
Map
<
String
,
String
>
heads
=
Maps
.
newHashMap
();
heads
.
put
(
"
t
oken"
,
token
);
heads
.
put
(
"
X-T
oken"
,
token
);
R
<
Map
<
String
,
Object
>>
result
=
RestTemplateUtils
.
get
(
uri
,
heads
,
new
TypeToken
<
R
<
Map
<
String
,
Object
>>>()
{
}.
getType
(),
p
);
Map
<
String
,
Object
>
detach
=
result
.
detach
();
...
...
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