Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
向汉
/
uc-engine
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
9087512d
...
9087512d7247eec7ff064852ccab71e7a70196b6
authored
2022-08-18 16:30:21 +0800
by
xianghan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1.修改任务关联实体id
1 parent
f1e0e3b6
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
309 additions
and
88 deletions
member-service-impl/pom.xml
member-service-impl/src/main/java/com/topdraw/business/module/task/domain/Task.java
member-service-impl/src/main/java/com/topdraw/business/module/task/progress/service/impl/TrTaskProgressServiceImpl.java
member-service-impl/src/main/java/com/topdraw/business/module/task/service/dto/TaskDTO.java
member-service-impl/src/main/java/com/topdraw/business/module/task/service/impl/TaskServiceImpl.java
member-service-impl/src/main/java/com/topdraw/business/module/user/app/rest/UserAppController.java
member-service-impl/src/main/java/com/topdraw/business/module/user/iptv/growreport/rest/GrowthReportController.java
member-service-impl/src/main/java/com/topdraw/business/module/user/weixin/wechatshare/rest/WechatShareRecordController.java
member-service-impl/src/main/java/com/topdraw/business/process/rest/TaskOperationController.java
member-service-impl/src/main/java/com/topdraw/business/process/rest/UserOperationController.java
member-service-impl/src/main/java/com/topdraw/business/process/service/TaskOperationService.java
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/TaskOperationServiceImpl.java
member-service-impl/src/main/java/com/topdraw/common/IResultCode.java
member-service-impl/src/main/java/com/topdraw/common/IResultInfo.java
member-service-impl/src/main/java/com/topdraw/common/ResultCode.java
member-service-impl/src/main/java/com/topdraw/common/ResultInfo.java
member-service-impl/pom.xml
View file @
9087512
...
...
@@ -15,24 +15,24 @@
<maven.compiler.source>
8
</maven.compiler.source>
<maven.compiler.target>
8
</maven.compiler.target>
<jjwt.version>
0.9.1
</jjwt.version>
<cronos.version>
1.
1
.0
</cronos.version>
<cronos.version>
1.
2
.0
</cronos.version>
</properties>
<dependencies>
<
!--<
dependency>
<dependency>
<groupId>
com.topdraw
</groupId>
<artifactId>
cronos-system
</artifactId>
<version>
${cronos.version}
</version>
</dependency>
-->
</dependency>
<dependency>
<
!--<
dependency>
<groupId>com.topdraw</groupId>
<artifactId>code-generator</artifactId>
<version>3.1.0</version>
</dependency>
-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-cache
</artifactId>
...
...
member-service-impl/src/main/java/com/topdraw/business/module/task/domain/Task.java
View file @
9087512
...
...
@@ -38,6 +38,10 @@ public class Task implements Serializable {
@NotNull
(
message
=
"taskTemplateId is null"
,
groups
=
{
CreateGroup
.
class
})
private
Long
taskTemplateId
;
/** 关联实体id */
@Column
(
name
=
"entity_id"
,
nullable
=
false
)
private
String
entityId
;
@Transient
private
String
taskTemplateCode
;
...
...
member-service-impl/src/main/java/com/topdraw/business/module/task/progress/service/impl/TrTaskProgressServiceImpl.java
View file @
9087512
...
...
@@ -94,7 +94,7 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService {
}
if
(
finishTasks
.
size
()
>
0
)
{
// 总记录一直存储
this
.
redisUtils
.
hmset
(
RedisKeyConstants
.
cacheTotalFinishTaskCount
+
"::"
+
memberId
,
finishTasks
);
this
.
redisUtils
.
hmset
ForObject
(
RedisKeyConstants
.
cacheTotalFinishTaskCount
+
"::"
+
memberId
,
finishTasks
);
}
return
finishTasks
;
...
...
@@ -124,7 +124,7 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService {
if
(
finishTasks
.
size
()
>
0
)
{
// 单天的记录只存储一天
this
.
redisUtils
.
hmset
(
RedisKeyConstants
.
cacheTodayFinishTaskCount
+
"::"
+
memberId
+
":"
+
LocalDate
.
now
(),
finishTasks
,
24
*
60
*
60
);
this
.
redisUtils
.
hmset
ForObject
(
RedisKeyConstants
.
cacheTodayFinishTaskCount
+
"::"
+
memberId
+
":"
+
LocalDate
.
now
(),
finishTasks
,
24
*
60
*
60
);
}
return
finishTasks
;
...
...
member-service-impl/src/main/java/com/topdraw/business/module/task/service/dto/TaskDTO.java
View file @
9087512
...
...
@@ -20,6 +20,9 @@ public class TaskDTO implements Serializable {
/** 任务模板id */
private
Long
taskTemplateId
;
/** 关联实体id */
private
String
entityId
;
/** 删除标识 0:正常;1:已删除;*/
private
Integer
deleteMark
;
...
...
member-service-impl/src/main/java/com/topdraw/business/module/task/service/impl/TaskServiceImpl.java
View file @
9087512
...
...
@@ -19,10 +19,7 @@ import org.springframework.transaction.annotation.Propagation;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -69,8 +66,14 @@ public class TaskServiceImpl implements TaskService {
@Override
public
TaskDTO
update
(
Task
task
)
{
Task
save
=
this
.
taskRepository
.
save
(
task
);
return
this
.
taskMapper
.
toDto
(
save
);
Optional
<
Task
>
taskOptional
=
this
.
taskRepository
.
findById
(
task
.
getId
());
if
(
taskOptional
.
isPresent
())
{
Task
task1
=
taskOptional
.
get
();
task1
.
copy
(
task
);
Task
result
=
this
.
taskRepository
.
save
(
task1
);
return
this
.
taskMapper
.
toDto
(
result
);
}
return
this
.
taskMapper
.
toDto
(
task
);
}
@Override
...
...
@@ -102,32 +105,11 @@ public class TaskServiceImpl implements TaskService {
return
tasks
;
}
List
<
TaskAttrDTO
>
taskAttrDTOS
=
this
.
taskAttrService
.
findTasksByTaskIds
(
maps
.
stream
().
map
(
t
->
t
.
get
(
"id"
)).
collect
(
Collectors
.
toSet
()));
if
(!
CollectionUtils
.
isEmpty
(
taskAttrDTOS
))
{
for
(
Map
<
String
,
Object
>
map
:
maps
)
{
Task
task
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
map
),
Task
.
class
);
List
<
String
>
taskAttrs
=
taskAttrDTOS
.
stream
().
filter
(
taskAttrDTO
->
taskAttrDTO
.
getTaskId
().
equals
(
task
.
getId
())).
map
(
TaskAttrDTO:
:
getAttrStr
).
collect
(
Collectors
.
toList
());
log
.
info
(
"任务属性值, dealTask# taskAttrs ==>> {}"
,
taskAttrs
);
if
(!
CollectionUtils
.
isEmpty
(
taskAttrs
))
{
task
.
setAttr
(
String
.
join
(
","
,
taskAttrs
));
}
tasks
.
add
(
task
);
}
}
else
{
for
(
Map
<
String
,
Object
>
map
:
maps
)
{
Task
task
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
map
),
Task
.
class
);
tasks
.
add
(
task
);
}
}
if
(!
CollectionUtils
.
isEmpty
(
tasks
))
{
this
.
redisUtils
.
lSet
(
RedisKeyConstants
.
cacheTaskByEventAndMemberLevelAndVip
+
"::"
+
event
+
":"
+
level
+
":"
+
vip
,
tasks
,
45
*
60
);
}
...
...
member-service-impl/src/main/java/com/topdraw/business/module/user/app/rest/UserAppController.java
View file @
9087512
package
com
.
topdraw
.
business
.
module
.
user
.
app
.
rest
;
import
com.topdraw.annotation.AnonymousAccess
;
import
com.topdraw.aop.log.Log
;
import
com.topdraw.business.module.user.app.domain.UserApp
;
import
com.topdraw.business.module.user.app.domain.UserAppBind
;
import
com.topdraw.business.module.user.app.service.UserAppBindService
;
...
...
@@ -11,7 +12,6 @@ import com.topdraw.business.module.vis.hainan.qq.domain.VisUserQq;
import
com.topdraw.business.module.vis.hainan.weibo.domain.VisUserWeibo
;
import
com.topdraw.business.module.vis.hainan.weixin.domain.VisUserWeixin
;
import
com.topdraw.common.ResultInfo
;
import
com.topdraw.annotation.Log
;
import
com.topdraw.business.module.user.app.service.UserAppService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
...
...
member-service-impl/src/main/java/com/topdraw/business/module/user/iptv/growreport/rest/GrowthReportController.java
View file @
9087512
package
com
.
topdraw
.
business
.
module
.
user
.
iptv
.
growreport
.
rest
;
import
com.topdraw.aop.log.Log
;
import
com.topdraw.common.ResultInfo
;
import
com.topdraw.annotation.Log
;
import
com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport
;
import
com.topdraw.business.module.user.iptv.growreport.service.GrowthReportService
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
member-service-impl/src/main/java/com/topdraw/business/module/user/weixin/wechatshare/rest/WechatShareRecordController.java
View file @
9087512
package
com
.
topdraw
.
business
.
module
.
user
.
weixin
.
wechatshare
.
rest
;
import
com.alibaba.fastjson.JSONObject
;
import
com.topdraw.aop.log.Log
;
import
com.topdraw.common.ResultInfo
;
import
com.topdraw.annotation.Log
;
import
com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord
;
import
com.topdraw.business.module.user.weixin.wechatshare.service.WechatShareRecordService
;
import
lombok.extern.slf4j.Slf4j
;
...
...
member-service-impl/src/main/java/com/topdraw/business/process/rest/TaskOperationController.java
View file @
9087512
...
...
@@ -9,6 +9,7 @@ import com.topdraw.business.process.service.TaskOperationService;
import
com.topdraw.business.process.service.dto.TaskOperationQueryCriteria
;
import
com.topdraw.common.IResultInfo
;
import
com.topdraw.common.ResultInfo
;
import
com.topdraw.exception.BadRequestException
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -19,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
import
java.util.Arrays
;
import
java.util.Objects
;
//byte[] b = Base64Utils.decodeFromString(baseStrs[1]);
@Api
(
"任务处理"
)
@RestController
...
...
@@ -70,18 +72,14 @@ public class TaskOperationController {
@PostMapping
(
value
=
"/updateTask"
)
@ApiOperation
(
"修改任务"
)
@AnonymousAccess
public
void
updateTask
(
@RequestBody
@Validated
Task
content
)
{
log
.
info
(
"
taskOperation ==>> updateTask ==>> param
==>> {}"
,
content
);
public
ResultInfo
updateTask
(
@RequestBody
@Validated
Task
content
)
{
log
.
info
(
"
修改任务,参数 updateTask#
==>> {}"
,
content
);
Long
id
=
content
.
getId
();
TaskDTO
taskDTO
=
this
.
taskOperationService
.
findById
(
id
);
if
(
Objects
.
nonNull
(
taskDTO
.
getId
()))
{
content
.
setCode
(
taskDTO
.
getCode
());
Task
task
=
new
Task
();
BeanUtils
.
copyProperties
(
taskDTO
,
task
);
task
.
copy
(
content
);
// 修改任务
this
.
taskOperationService
.
updateTask
(
task
);
if
(
Objects
.
isNull
(
id
))
{
throw
new
BadRequestException
(
"修改任务失败,id不得为空"
);
}
// 修改任务
return
this
.
taskOperationService
.
updateTask
(
content
);
}
/**
...
...
member-service-impl/src/main/java/com/topdraw/business/process/rest/UserOperationController.java
View file @
9087512
...
...
@@ -5,7 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.topdraw.annotation.AnonymousAccess
;
import
com.topdraw.a
nnotation
.Log
;
import
com.topdraw.a
op.log
.Log
;
import
com.topdraw.business.module.common.validated.CreateGroup
;
import
com.topdraw.business.module.common.validated.UpdateGroup
;
import
com.topdraw.business.module.member.service.MemberService
;
...
...
member-service-impl/src/main/java/com/topdraw/business/process/service/TaskOperationService.java
View file @
9087512
...
...
@@ -42,7 +42,7 @@ public interface TaskOperationService {
*
* @param task
*/
TaskDTO
updateTask
(
Task
task
);
ResultInfo
updateTask
(
Task
task
);
/**
*
...
...
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/TaskOperationServiceImpl.java
View file @
9087512
...
...
@@ -51,6 +51,7 @@ import org.springframework.data.redis.core.RedisTemplate;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.core.ValueOperations
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
java.sql.Timestamp
;
...
...
@@ -100,66 +101,70 @@ public class TaskOperationServiceImpl implements TaskOperationService {
private
static
final
Integer
POINTS_MIN
=
1
;
@Override
public
TaskDTO
createTask
(
Task
task
)
{
Long
taskTemplateId
=
task
.
getTaskTemplateId
();
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
TaskDTO
createTask
(
Task
content
)
{
Long
taskTemplateId
=
content
.
getTaskTemplateId
();
TaskTemplateDTO
taskTemplateDTO
=
this
.
taskTemplateService
.
findById
(
taskTemplateId
);
task
.
setTaskTemplateCode
(
taskTemplateDTO
.
getCode
());
Task
task
_
=
TaskBuilder
.
build
(
task
);
TaskDTO
taskDTO
=
this
.
taskService
.
create
(
task
_
);
content
.
setTaskTemplateCode
(
taskTemplateDTO
.
getCode
());
Task
task
=
TaskBuilder
.
build
(
content
);
TaskDTO
taskDTO
=
this
.
taskService
.
create
(
task
);
((
TaskOperationServiceImpl
)
AopContext
.
currentProxy
()).
asyncCreateTask
(
task
_
);
((
TaskOperationServiceImpl
)
AopContext
.
currentProxy
()).
asyncCreateTask
(
task
);
return
taskDTO
;
}
@Override
public
TaskDTO
updateTask
(
Task
task
)
{
Long
taskTemplateId
=
task
.
getTaskTemplateId
();
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
ResultInfo
updateTask
(
Task
content
)
{
Long
taskTemplateId
=
content
.
getTaskTemplateId
();
if
(
Objects
.
nonNull
(
taskTemplateId
))
{
TaskTemplateDTO
taskTemplateDTO
=
this
.
taskTemplateService
.
findById
(
taskTemplateId
);
task
.
setTaskTemplateCode
(
taskTemplateDTO
.
getCode
());
TaskDTO
update
=
this
.
taskService
.
update
(
task
);
if
(
Objects
.
nonNull
(
update
.
getId
()))
{
this
.
updateTaskAttr
(
task
);
content
.
setTaskTemplateCode
(
taskTemplateDTO
.
getCode
());
}
((
TaskOperationServiceImpl
)
AopContext
.
currentProxy
()).
asyncUpdateTask
(
task
);
TaskDTO
taskDTO
=
this
.
taskService
.
update
(
content
);
((
TaskOperationServiceImpl
)
AopContext
.
currentProxy
()).
asyncUpdateTask
(
content
);
return
update
;
Set
<
Object
>
tasks
=
this
.
redisUtils
.
keys
(
RedisKeyConstants
.
cacheTaskByEventAndMemberLevelAndVip
+
"*"
);
if
(!
CollectionUtils
.
isEmpty
(
tasks
))
{
for
(
Object
key
:
tasks
)
{
this
.
redisUtils
.
del
(
key
.
toString
());
}
/**
*
* @param task 任务
*/
private
void
updateTaskAttr
(
Task
task
)
{
TaskAttrDTO
taskAttrDTO
=
this
.
taskAttrService
.
findByTaskId
(
task
.
getId
());
if
(
Objects
.
nonNull
(
taskAttrDTO
.
getId
()))
{
TaskAttr
taskAttr
=
new
TaskAttr
();
BeanUtils
.
copyProperties
(
taskAttrDTO
,
taskAttr
);
taskAttr
.
setAttrStr
(
task
.
getAttr
());
this
.
taskAttrService
.
update
(
taskAttr
);
}
return
ResultInfo
.
success
(
taskDTO
);
}
@Override
// @CacheEvict(cacheNames = RedisKeyConstants.cacheTaskByEvent, key = "#task.event"
)
public
Integer
deleteTask
(
Task
task
)
{
Long
id
=
task
.
getId
();
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Integer
deleteTask
(
Task
content
)
{
Long
id
=
content
.
getId
();
TaskDTO
taskDTO
=
this
.
findById
(
id
);
if
(
Objects
.
nonNull
(
taskDTO
.
getId
()))
{
task
.
setId
(
taskDTO
.
getId
());
Integer
delete
=
this
.
taskService
.
delete
(
task
);
task
.
setCode
(
taskDTO
.
getCode
());
((
TaskOperationServiceImpl
)
AopContext
.
currentProxy
()).
asyncDeleteTask
(
task
);
content
.
setId
(
taskDTO
.
getId
());
Integer
count
=
this
.
taskService
.
delete
(
content
);
content
.
setCode
(
taskDTO
.
getCode
());
((
TaskOperationServiceImpl
)
AopContext
.
currentProxy
()).
asyncDeleteTask
(
content
);
Set
<
Object
>
tasks
=
this
.
redisUtils
.
keys
(
RedisKeyConstants
.
cacheTaskByEventAndMemberLevelAndVip
+
"*"
);
if
(!
CollectionUtils
.
isEmpty
(
tasks
))
{
for
(
Object
key
:
tasks
)
{
this
.
redisUtils
.
del
(
key
.
toString
());
}
}
return
delete
;
return
count
;
}
return
0
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Integer
deleteTask
(
Long
id
)
{
TaskDTO
taskDTO
=
this
.
findById
(
id
);
if
(
Objects
.
nonNull
(
taskDTO
.
getId
()))
{
...
...
@@ -173,6 +178,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
}
@Override
@Transactional
(
readOnly
=
true
)
public
TaskDTO
findById
(
Long
id
)
{
TaskDTO
taskDTO
=
this
.
taskService
.
findById
(
id
);
Long
id1
=
taskDTO
.
getId
();
...
...
@@ -185,6 +191,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
}
@Override
@Transactional
(
readOnly
=
true
)
public
TaskDTO
findByCode
(
String
code
)
{
return
this
.
taskService
.
findByCode
(
code
);
}
...
...
@@ -312,7 +319,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
Map
<
Object
,
Object
>
finishTasks
=
new
HashMap
<>();
finishTasks
.
put
(
task
.
getId
(),
1
);
// 单天的记录只存储一天
this
.
redisUtils
.
hmset
(
RedisKeyConstants
.
cacheTodayFinishTaskCount
+
"::"
+
memberId
+
":"
+
LocalDate
.
now
(),
finishTasks
,
24
*
60
*
60
);
this
.
redisUtils
.
hmset
ForObject
(
RedisKeyConstants
.
cacheTodayFinishTaskCount
+
"::"
+
memberId
+
":"
+
LocalDate
.
now
(),
finishTasks
,
24
*
60
*
60
);
}
else
{
this
.
redisUtils
.
hincr
(
RedisKeyConstants
.
cacheTodayFinishTaskCount
+
"::"
+
memberId
+
":"
+
LocalDate
.
now
(),
task
.
getId
().
toString
(),
1
);
}
...
...
@@ -544,8 +551,8 @@ public class TaskOperationServiceImpl implements TaskOperationService {
private
boolean
doActivityEvent
(
JSONObject
msgData
,
Task
task
,
MemberSimpleDTO
memberDTO
)
{
Integer
actionAmount
=
task
.
getActionAmount
();
String
attrStr
=
task
.
getAttr
();
if
(
StringUtils
.
isBlank
(
attrStr
))
{
String
entityId
=
task
.
getEntityId
();
if
(
StringUtils
.
isBlank
(
entityId
))
{
int
joinCount
=
1
;
//msgData.getInteger("joinCount");
if
(
joinCount
>=
actionAmount
)
{
this
.
saveOrUpdateTaskProcess
(
null
,
memberDTO
.
getId
(),
task
,
joinCount
,
TASK_FINISH_STATUS
);
...
...
@@ -554,7 +561,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
}
Integer
marketingActivityId
=
msgData
.
getInteger
(
"marketingActivityId"
);
if
(
new
ArrayList
<>(
Arrays
.
asList
(
attrStr
.
split
(
","
))).
contains
(
Integer
.
toString
(
marketingActivityId
)))
{
if
(
new
ArrayList
<>(
Arrays
.
asList
(
entityId
.
split
(
","
))).
contains
(
Integer
.
toString
(
marketingActivityId
)))
{
int
joinCount
=
1
;
//msgData.getInteger("joinCount");
if
(
joinCount
>=
actionAmount
)
{
this
.
saveOrUpdateTaskProcess
(
null
,
memberDTO
.
getId
(),
task
,
joinCount
,
TASK_FINISH_STATUS
);
...
...
@@ -562,7 +569,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
}
}
log
.
warn
(
"未找到对应的活动,参数 marketingActivityId ==>> {} ||
任务属性 ==>> {}"
,
marketingActivityId
,
attrStr
);
log
.
warn
(
"未找到对应的活动,参数 marketingActivityId ==>> {} ||
营销活动id ==>> [{}]"
,
marketingActivityId
,
entityId
);
return
false
;
}
...
...
member-service-impl/src/main/java/com/topdraw/common/IResultCode.java
0 → 100644
View file @
9087512
package
com
.
topdraw
.
common
;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/8/18 11:36
* @version: :
* @modified By:
* @since : modified in 2022/8/18 11:36
*/
public
interface
IResultCode
{
long
getCode
();
String
getDescription
();
}
member-service-impl/src/main/java/com/topdraw/common/IResultInfo.java
0 → 100644
View file @
9087512
package
com
.
topdraw
.
common
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* @author lvjian
* @Title:
* @Package
* @Description:
* @date 2021/1/7 17:26
*/
public
interface
IResultInfo
<
T
>
extends
Serializable
{
long
getBusinessCode
();
List
<
T
>
getResultSet
();
String
getDescription
();
long
getCount
();
}
member-service-impl/src/main/java/com/topdraw/common/ResultCode.java
0 → 100644
View file @
9087512
package
com
.
topdraw
.
common
;
/**
* 枚举了一些常用API返回码
* Created by cy on 2021/01/08.
*/
public
enum
ResultCode
implements
IResultCode
{
SUCCESS
(
200
,
"操作成功"
),
FAILED
(
500
,
"操作失败"
),
VALIDATE_FAILED
(
400
,
"参数检验失败"
),
UNAUTHORIZED
(
401
,
"未登录或token已经过期"
),
FORBIDDEN
(
403
,
"无权限"
),
METHOD_NOT_ALLOWED
(
405
,
"方法不允许"
);
private
long
code
;
private
String
description
;
ResultCode
(
long
code
,
String
description
)
{
this
.
code
=
code
;
this
.
description
=
description
;
}
public
long
getCode
()
{
return
code
;
}
public
String
getDescription
()
{
return
description
;
}
}
\ No newline at end of file
member-service-impl/src/main/java/com/topdraw/common/ResultInfo.java
0 → 100644
View file @
9087512
package
com
.
topdraw
.
common
;
import
com.alibaba.fastjson.JSON
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Getter
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* 通用返回对象
* Created by cy on 2021/01/08.
*/
@Getter
public
class
ResultInfo
<
T
>
implements
IResultInfo
<
T
>
{
private
static
final
long
serialVersionUID
=
-
7313465544799377989L
;
private
long
businessCode
;
private
List
<
T
>
resultSet
;
private
String
description
;
private
long
count
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
LocalDateTime
currentTime
;
public
ResultInfo
(
long
businessCode
,
List
<
T
>
resultSet
,
String
description
)
{
this
.
businessCode
=
businessCode
;
this
.
resultSet
=
resultSet
;
this
.
description
=
description
;
this
.
count
=
resultSet
.
size
();
currentTime
=
LocalDateTime
.
now
();
}
public
ResultInfo
(
long
businessCode
,
Map
<
String
,
Object
>
page
,
String
description
)
{
this
.
businessCode
=
businessCode
;
this
.
resultSet
=
(
List
<
T
>)
page
.
get
(
"content"
);
this
.
count
=
(
Long
)
page
.
get
(
"totalElements"
);
this
.
description
=
description
;
currentTime
=
LocalDateTime
.
now
();
}
/**
* 成功返回不分页结果集
* @param resultSet
* @param <T>
* @return
*/
public
static
<
T
>
ResultInfo
<
T
>
success
(
List
<
T
>
resultSet
)
{
return
new
ResultInfo
<
T
>(
ResultCode
.
SUCCESS
.
getCode
(),
resultSet
,
""
);
}
/**
* 成功返回单一实体结果集
* @param result
* @param <T>
* @return
*/
public
static
<
T
>
ResultInfo
<
T
>
success
(
T
result
)
{
List
<
T
>
list
=
new
ArrayList
<>();
list
.
add
(
result
);
return
new
ResultInfo
<
T
>(
ResultCode
.
SUCCESS
.
getCode
(),
list
,
""
);
}
public
static
<
T
>
ResultInfo
<
T
>
success
()
{
return
new
ResultInfo
<>(
ResultCode
.
SUCCESS
.
getCode
(),
new
ArrayList
<>(),
""
);
}
/**
* 成功返回分页结果集
* @param page
* @param <T>
* @return
*/
public
static
<
T
>
ResultInfo
<
T
>
successPage
(
Map
<
String
,
Object
>
page
)
{
return
new
ResultInfo
<
T
>(
ResultCode
.
SUCCESS
.
getCode
(),
page
,
""
);
}
/**
* 成功返回带描述的不分页结果集
* @param resultSet
* @param description
* @param <T>
* @return
*/
public
static
<
T
>
ResultInfo
<
T
>
success
(
List
<
T
>
resultSet
,
String
description
)
{
return
new
ResultInfo
<
T
>(
ResultCode
.
SUCCESS
.
getCode
(),
resultSet
,
description
);
}
/**
* 带描述的服务端处理失败返回
* @param description
* @param <T>
* @return
*/
public
static
<
T
>
ResultInfo
<
T
>
failed
(
String
description
)
{
return
new
ResultInfo
<
T
>(
ResultCode
.
FAILED
.
getCode
(),
new
ArrayList
<>(),
description
);
}
/**
* 带描述的服务端处理失败返回
* @param description
* @param <T>
* @return
*/
public
static
<
T
>
ResultInfo
<
T
>
failure
(
String
description
)
{
return
new
ResultInfo
<
T
>(
ResultCode
.
FAILED
.
getCode
(),
new
ArrayList
<>(),
description
);
}
/**
* 未登录或token过期的失败返回
* @param <T>
* @return
*/
public
static
<
T
>
ResultInfo
<
T
>
unauthorized
()
{
return
new
ResultInfo
<
T
>(
ResultCode
.
UNAUTHORIZED
.
getCode
(),
new
ArrayList
<>(),
ResultCode
.
UNAUTHORIZED
.
getDescription
());
}
/**
* 未授权的失败返回
* @param description
* @param <T>
* @return
*/
public
static
<
T
>
ResultInfo
<
T
>
forbidden
(
String
description
)
{
return
new
ResultInfo
<
T
>(
ResultCode
.
FORBIDDEN
.
getCode
(),
new
ArrayList
<>(),
description
);
}
/**
* 参数验证失败的返回
* @param <T>
* @return
*/
public
static
<
T
>
ResultInfo
<
T
>
validateFailed
()
{
return
new
ResultInfo
<
T
>(
ResultCode
.
VALIDATE_FAILED
.
getCode
(),
new
ArrayList
<>(),
ResultCode
.
VALIDATE_FAILED
.
getDescription
());
}
/**
* 带描述的参数验证失败返回
* @param description
* @param <T>
* @return
*/
public
static
<
T
>
ResultInfo
<
T
>
validateFailed
(
String
description
)
{
return
new
ResultInfo
<
T
>(
ResultCode
.
VALIDATE_FAILED
.
getCode
(),
new
ArrayList
<>(),
description
);
}
/**
* 请求方法错误的返回
* @param description
* @param <T>
* @return
*/
public
static
<
T
>
ResultInfo
<
T
>
methodNotAllowed
(
String
description
)
{
return
new
ResultInfo
<
T
>(
ResultCode
.
METHOD_NOT_ALLOWED
.
getCode
(),
new
ArrayList
<>(),
description
);
}
@Override
public
String
toString
()
{
return
JSON
.
toJSONString
(
this
);
}
}
Please
register
or
sign in
to post a comment