Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gs1-office-web-sit
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
吴迪
gs1-office-web-sit
Commits
b0f19646
Commit
b0f19646
authored
Jul 09, 2023
by
吴迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加点击统计
parent
8ed109be
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
191 additions
and
0 deletions
+191
-0
ClickHitEnum.java
...n/java/io/office/common/enumpack/manage/ClickHitEnum.java
+34
-0
RRExceptionHandler.java
...n/java/io/office/common/exception/RRExceptionHandler.java
+8
-0
ClickHitController.java
.../office/modules/manage/controller/ClickHitController.java
+36
-0
ClickHitDTO.java
...java/io/office/modules/manage/entity/dto/ClickHitDTO.java
+21
-0
CenterNewsStrategy.java
...io/office/modules/manage/strategy/CenterNewsStrategy.java
+53
-0
ClickHitStrategy.java
...a/io/office/modules/manage/strategy/ClickHitStrategy.java
+15
-0
ClickHitStrategyContext.java
...fice/modules/manage/strategy/ClickHitStrategyContext.java
+24
-0
No files found.
src/main/java/io/office/common/enumpack/manage/ClickHitEnum.java
0 → 100644
View file @
b0f19646
package
io
.
office
.
common
.
enumpack
.
manage
;
/**
* @author wudi
* @date 2023/7/9
* @comment
*/
public
enum
ClickHitEnum
{
;
private
String
code
;
private
String
value
;
ClickHitEnum
(
String
code
,
String
value
)
{
this
.
code
=
code
;
this
.
value
=
value
;
}
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
}
src/main/java/io/office/common/exception/RRExceptionHandler.java
View file @
b0f19646
...
@@ -8,6 +8,7 @@ import io.office.common.utils.R;
...
@@ -8,6 +8,7 @@ import io.office.common.utils.R;
import
org.apache.shiro.authz.AuthorizationException
;
import
org.apache.shiro.authz.AuthorizationException
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.dao.DuplicateKeyException
;
import
org.springframework.dao.DuplicateKeyException
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
...
@@ -34,6 +35,13 @@ public class RRExceptionHandler {
...
@@ -34,6 +35,13 @@ public class RRExceptionHandler {
return
r
;
return
r
;
}
}
@ExceptionHandler
(
NoSuchBeanDefinitionException
.
class
)
public
R
NoSuchBeanDefinitionException
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
return
R
.
error
(
403
,
"参数不正确,请检查参数是否正确"
);
}
@ExceptionHandler
(
NoHandlerFoundException
.
class
)
@ExceptionHandler
(
NoHandlerFoundException
.
class
)
public
R
handlerNoFoundException
(
Exception
e
)
{
public
R
handlerNoFoundException
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
logger
.
error
(
e
.
getMessage
(),
e
);
...
...
src/main/java/io/office/modules/manage/controller/ClickHitController.java
0 → 100644
View file @
b0f19646
package
io
.
office
.
modules
.
manage
.
controller
;
import
io.office.common.utils.R
;
import
io.office.modules.manage.entity.dto.ClickHitDTO
;
import
io.office.modules.manage.strategy.ClickHitStrategy
;
import
io.office.modules.manage.strategy.ClickHitStrategyContext
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @author wudi
* @date 2023/7/9
* @comment
*/
@RestController
@RequestMapping
(
"/clickHit"
)
@RequiredArgsConstructor
public
class
ClickHitController
{
private
final
ClickHitStrategyContext
clickHitStrategyContext
;
@RequestMapping
(
"/api/save"
)
// @RequiresPermissions("datamanage:clickdetail:save")
public
R
save
(
@RequestBody
ClickHitDTO
clickHitDTO
)
{
ClickHitStrategy
clickHitStrategy
=
clickHitStrategyContext
.
getStrategy
(
clickHitDTO
.
getBusinessCode
(),
ClickHitStrategy
.
class
);
if
(
clickHitStrategy
==
null
)
{
return
R
.
error
(
"code错误!"
);
}
clickHitStrategy
.
addClickHit
(
clickHitDTO
.
getBusinessCode
(),
clickHitDTO
.
getId
());
return
R
.
ok
();
}
}
src/main/java/io/office/modules/manage/entity/dto/ClickHitDTO.java
0 → 100644
View file @
b0f19646
package
io
.
office
.
modules
.
manage
.
entity
.
dto
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @author wudi
* @date 2023/7/9
* @comment 点击量统计实体类
*/
@Data
public
class
ClickHitDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
businessCode
;
private
String
id
;
}
src/main/java/io/office/modules/manage/strategy/CenterNewsStrategy.java
0 → 100644
View file @
b0f19646
package
io
.
office
.
modules
.
manage
.
strategy
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
io.office.common.exception.RRException
;
import
io.office.modules.manage.dao.NewsDao
;
import
io.office.modules.manage.entity.NewsEntity
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Transactional
;
/**
* @author wudi
* @date 2023/7/9
* {@code @comment} 中心咨询策略实现
*/
@Component
(
value
=
"centerNewsStrategy"
)
@RequiredArgsConstructor
public
class
CenterNewsStrategy
implements
ClickHitStrategy
{
private
final
NewsDao
newsDao
;
/**
* 添加业务点击事件
*
* @param businessCode,id
*/
@Transactional
@Override
public
void
addClickHit
(
String
businessCode
,
String
id
)
{
/**
* 1.先获取知识详情
* 2.如果是有效状态就+1
*/
NewsEntity
newsEntity
=
newsDao
.
selectById
(
Integer
.
parseInt
(
id
));
if
(
newsEntity
!=
null
)
{
//点击量+1
NewsEntity
newsUpdate
=
new
NewsEntity
();
if
(
newsEntity
.
getHits
()
!=
null
)
{
newsUpdate
.
setHits
(
newsEntity
.
getHits
()
+
1
);
}
else
{
newsUpdate
.
setHits
(
1
);
}
UpdateWrapper
<
NewsEntity
>
updateWrapper
=
new
UpdateWrapper
();
updateWrapper
.
eq
(
"id"
,
Integer
.
parseInt
(
id
));
newsDao
.
update
(
newsUpdate
,
updateWrapper
);
}
else
{
throw
new
RRException
(
"id不存在,请核实后重试!"
);
}
}
}
src/main/java/io/office/modules/manage/strategy/ClickHitStrategy.java
0 → 100644
View file @
b0f19646
package
io
.
office
.
modules
.
manage
.
strategy
;
/**
* @author wudi
* @date 2023/7/9
* @comment 点击事件策略
*/
public
interface
ClickHitStrategy
{
/**
* 添加业务点击事件
* @param businessCode
*/
void
addClickHit
(
String
businessCode
,
String
id
);
}
src/main/java/io/office/modules/manage/strategy/ClickHitStrategyContext.java
0 → 100644
View file @
b0f19646
package
io
.
office
.
modules
.
manage
.
strategy
;
import
io.office.common.utils.SpringContextUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.stereotype.Component
;
/**
* @author wudi
* @date 2023/7/9
* @comment 点击事件策略加载器
*/
@Component
public
class
ClickHitStrategyContext
{
public
<
T
>
T
getStrategy
(
String
strategyId
,
Class
<
T
>
t
)
{
// strategyId beanId
if
(
StringUtils
.
isEmpty
(
strategyId
))
{
return
null
;
}
return
SpringContextUtils
.
getBean
(
strategyId
,
t
);
}
}
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