Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
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
youjj
cloud-platform
Commits
65f697d2
Commit
65f697d2
authored
Aug 28, 2019
by
hanfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改新闻系列接口
parent
dc5fc768
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
174 additions
and
34 deletions
+174
-34
UrlType.java
...src/main/java/com/xxfc/platform/uccn/comstnt/UrlType.java
+26
-0
ArticleQuery.java
...src/main/java/com/xxfc/platform/uccn/vo/ArticleQuery.java
+14
-0
ArticleBiz.java
.../src/main/java/com/xxfc/platform/uccn/biz/ArticleBiz.java
+78
-25
ArticleController.java
...n/java/com/xxfc/platform/uccn/rest/ArticleController.java
+56
-9
No files found.
xx-uccn/xx-uccn-api/src/main/java/com/xxfc/platform/uccn/comstnt/UrlType.java
0 → 100644
View file @
65f697d2
package
com
.
xxfc
.
platform
.
uccn
.
comstnt
;
/**
* 访问路径
* @author Administrator
*/
public
enum
UrlType
{
OFFICIAL_WEBSITE
(
"官网访问"
,
1
),
BACKGROUND_MANAGEMENT
(
"后台访问"
,
2
);
private
String
name
;
private
Integer
code
;
UrlType
(
String
name
,
Integer
code
)
{
this
.
name
=
name
;
this
.
code
=
code
;
}
public
String
getName
()
{
return
name
;
}
public
Integer
getCode
()
{
return
code
;
}
}
xx-uccn/xx-uccn-api/src/main/java/com/xxfc/platform/uccn/vo/ArticleQuery.java
0 → 100644
View file @
65f697d2
package
com
.
xxfc
.
platform
.
uccn
.
vo
;
import
lombok.Data
;
/**
* 新闻文章查询条件
* @author Administrator
*/
@Data
public
class
ArticleQuery
{
private
Integer
page
;
private
Integer
limit
;
// private String newsContent;
}
xx-uccn/xx-uccn-server/src/main/java/com/xxfc/platform/uccn/biz/ArticleBiz.java
View file @
65f697d2
...
@@ -3,8 +3,10 @@ package com.xxfc.platform.uccn.biz;
...
@@ -3,8 +3,10 @@ package com.xxfc.platform.uccn.biz;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.github.wxiaoqi.security.common.biz.BaseBiz
;
import
com.github.wxiaoqi.security.common.biz.BaseBiz
;
import
com.xxfc.platform.uccn.comstnt.UrlType
;
import
com.xxfc.platform.uccn.entity.Article
;
import
com.xxfc.platform.uccn.entity.Article
;
import
com.xxfc.platform.uccn.mapper.ArticleMapper
;
import
com.xxfc.platform.uccn.mapper.ArticleMapper
;
import
com.xxfc.platform.uccn.vo.ArticleQuery
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
tk.mybatis.mapper.entity.Example
;
import
tk.mybatis.mapper.entity.Example
;
...
@@ -21,16 +23,17 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
...
@@ -21,16 +23,17 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
/**
/**
* 随机文章条数
* 随机文章条数
*/
*/
private
final
Integer
RANDOM_NUMBER
=
3
;
private
final
Integer
RANDOM_NUMBER
=
3
;
/**
/**
* 首页文章条数
* 首页文章条数
*/
*/
private
final
Integer
HOME_PAGE_NUMBER
=
4
;
private
final
Integer
HOME_PAGE_NUMBER
=
4
;
/**
/**
* 文章列表
* 文章列表
*
* @param page
* @param page
* @param limit
* @param limit
* @param type
* @param type
...
@@ -43,24 +46,28 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
...
@@ -43,24 +46,28 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
}
}
/**
/**
* 获取一条数据
* 获取一条数据
*
* @param id
* @param id
* @param urlType
* @return
* @return
*/
*/
public
Article
getOne
(
Integer
id
)
{
public
Article
getOne
(
Integer
id
,
Integer
urlType
)
{
Example
example
=
Example
.
builder
(
Article
.
class
).
where
(
WeekendSqls
.<
Article
>
custom
()
Example
example
=
new
Example
(
Article
.
class
);
.
andEqualTo
(
Article:
:
getId
,
id
)
Example
.
Criteria
criteria
=
example
.
createCriteria
();
.
andEqualTo
(
Article:
:
getIsDel
,
0
)
criteria
.
andEqualTo
(
"id"
,
id
);
.
andEqualTo
(
Article:
:
getStatus
,
1
)
criteria
.
andEqualTo
(
"isDel"
,
0
);
).
build
();
if
(
UrlType
.
OFFICIAL_WEBSITE
.
getCode
().
equals
(
urlType
))
{
Article
article
=
mapper
.
selectOneByExample
(
example
);
criteria
.
andEqualTo
(
"status"
,
1
);
return
article
;
}
return
mapper
.
selectOneByExample
(
example
);
}
}
/**
/**
* 随机获取三条连续的文章
* 随机获取三条连续的文章
*
* @param type
* @param type
* @return
* @return
*/
*/
...
@@ -69,14 +76,14 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
...
@@ -69,14 +76,14 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
List
<
Article
>
articleList
=
mapper
.
getArticleList
(
type
);
List
<
Article
>
articleList
=
mapper
.
getArticleList
(
type
);
if
(!
Objects
.
isNull
(
articleList
))
{
if
(!
Objects
.
isNull
(
articleList
))
{
int
size
=
articleList
.
size
();
int
size
=
articleList
.
size
();
if
(
RANDOM_NUMBER
>=
size
)
{
if
(
RANDOM_NUMBER
>=
size
)
{
return
articleList
;
return
articleList
;
}
else
{
}
else
{
Random
random
=
new
Random
();
Random
random
=
new
Random
();
int
r
=
random
.
nextInt
(
size
-
RANDOM_NUMBER
+
1
);
int
r
=
random
.
nextInt
(
size
-
RANDOM_NUMBER
+
1
);
List
<
Article
>
result
=
new
ArrayList
<>();
List
<
Article
>
result
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
RANDOM_NUMBER
.
intValue
();
i
++)
{
for
(
int
i
=
0
;
i
<
RANDOM_NUMBER
.
intValue
();
i
++)
{
int
index
=
i
+
r
;
int
index
=
i
+
r
;
result
.
add
(
articleList
.
get
(
index
));
result
.
add
(
articleList
.
get
(
index
));
}
}
return
result
;
return
result
;
...
@@ -88,17 +95,18 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
...
@@ -88,17 +95,18 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
/**
/**
* 首页文章列表
* 首页文章列表
*
* @param type
* @param type
* @return
* @return
*/
*/
public
List
getHomePageArticle
(
Integer
type
){
public
List
getHomePageArticle
(
Integer
type
)
{
List
<
Article
>
articleList
=
mapper
.
getArticleList
(
type
);
List
<
Article
>
articleList
=
mapper
.
getArticleList
(
type
);
if
(
Objects
.
isNull
(
articleList
))
{
if
(
Objects
.
isNull
(
articleList
))
{
return
new
ArrayList
();
return
new
ArrayList
();
}
else
{
}
else
{
if
(
articleList
.
size
()
>
HOME_PAGE_NUMBER
)
{
if
(
articleList
.
size
()
>
HOME_PAGE_NUMBER
)
{
return
articleList
.
subList
(
0
,
HOME_PAGE_NUMBER
);
return
articleList
.
subList
(
0
,
HOME_PAGE_NUMBER
);
}
else
{
}
else
{
return
articleList
;
return
articleList
;
}
}
}
}
...
@@ -106,19 +114,64 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
...
@@ -106,19 +114,64 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
add
(
Article
article
)
{
public
void
add
(
Article
article
)
{
if
(
article
==
null
)
{
if
(
article
==
null
)
{
return
;
return
;
}
}
article
.
setIsDel
(
0
);
article
.
setIsDel
(
0
);
if
(
article
.
getStatus
()
==
null
)
{
if
(
article
.
getStatus
()
==
null
)
{
article
.
setStatus
(
0
);
article
.
setStatus
(
0
);
}
}
if
(
article
.
getType
()
==
null
)
{
if
(
article
.
getType
()
==
null
)
{
article
.
setType
(
0
);
article
.
setType
(
0
);
}
}
article
.
setCreTime
(
new
Date
());
article
.
setCreTime
(
new
Date
());
mapper
.
insertSelective
(
article
);
mapper
.
insertSelective
(
article
);
}
}
public
PageInfo
findAll
(
ArticleQuery
query
)
{
PageHelper
.
startPage
(
query
.
getPage
(),
query
.
getLimit
());
Example
exa
=
Example
.
builder
(
Article
.
class
).
where
(
WeekendSqls
.<
Article
>
custom
()
.
andEqualTo
(
Article:
:
getIsDel
,
0
)
).
build
();
List
<
Article
>
articles
=
mapper
.
selectByExample
(
exa
);
return
PageInfo
.
of
(
articles
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
updateSelectiveByIdRe
(
Article
article
){
article
.
setUpdTime
(
new
Date
());
return
mapper
.
updateByPrimaryKeySelective
(
article
);
}
public
int
putaway
(
Integer
id
)
{
Article
article
=
new
Article
();
article
.
setId
(
id
);
article
.
setUpdTime
(
new
Date
());
article
.
setAddTime
(
new
Date
());
article
.
setStatus
(
1
);
return
mapper
.
updateByPrimaryKeySelective
(
article
);
}
public
int
soldOut
(
Integer
id
)
{
Article
article
=
new
Article
();
article
.
setId
(
id
);
article
.
setUpdTime
(
new
Date
());
article
.
setStatus
(
0
);
return
mapper
.
updateByPrimaryKeySelective
(
article
);
}
public
int
remove
(
Integer
id
)
{
Article
article
=
new
Article
();
article
.
setId
(
id
);
article
.
setUpdTime
(
new
Date
());
article
.
setIsDel
(
1
);
return
mapper
.
updateByPrimaryKeySelective
(
article
);
}
}
}
xx-uccn/xx-uccn-server/src/main/java/com/xxfc/platform/uccn/rest/ArticleController.java
View file @
65f697d2
...
@@ -4,12 +4,11 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
...
@@ -4,12 +4,11 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import
com.github.wxiaoqi.security.common.rest.BaseController
;
import
com.github.wxiaoqi.security.common.rest.BaseController
;
import
com.xxfc.platform.uccn.biz.ArticleBiz
;
import
com.xxfc.platform.uccn.biz.ArticleBiz
;
import
com.xxfc.platform.uccn.entity.Article
;
import
com.xxfc.platform.uccn.entity.Article
;
import
com.xxfc.platform.uccn.vo.ArticleQuery
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Map
;
/**
/**
* 文章
* 文章
...
@@ -21,7 +20,7 @@ import java.util.Map;
...
@@ -21,7 +20,7 @@ import java.util.Map;
@Api
(
tags
=
{
"文章"
})
@Api
(
tags
=
{
"文章"
})
public
class
ArticleController
extends
BaseController
<
ArticleBiz
,
Article
>
{
public
class
ArticleController
extends
BaseController
<
ArticleBiz
,
Article
>
{
@GetMapping
(
"/list"
)
@GetMapping
(
"/
app/unauth/
list"
)
@ApiOperation
(
value
=
"获取文章列表"
)
@ApiOperation
(
value
=
"获取文章列表"
)
public
ObjectRestResponse
getArticleList
(
public
ObjectRestResponse
getArticleList
(
@RequestParam
(
name
=
"page"
,
defaultValue
=
"1"
)
Integer
page
,
@RequestParam
(
name
=
"page"
,
defaultValue
=
"1"
)
Integer
page
,
...
@@ -30,20 +29,21 @@ public class ArticleController extends BaseController<ArticleBiz, Article> {
...
@@ -30,20 +29,21 @@ public class ArticleController extends BaseController<ArticleBiz, Article> {
return
ObjectRestResponse
.
succ
(
baseBiz
.
getArticleList
(
page
,
limit
,
type
));
return
ObjectRestResponse
.
succ
(
baseBiz
.
getArticleList
(
page
,
limit
,
type
));
}
}
@GetMapping
(
"/
one/{id}
"
)
@GetMapping
(
"/
app/unauth/one
"
)
@ApiOperation
(
value
=
"获取一条数据"
)
@ApiOperation
(
value
=
"获取一条数据"
)
public
ObjectRestResponse
getOne
(
@PathVariable
Integer
id
)
{
public
ObjectRestResponse
getOne
(
@RequestParam
Integer
id
,
return
ObjectRestResponse
.
succ
(
baseBiz
.
getOne
(
id
));
@RequestParam
(
required
=
false
)
Integer
urlType
)
{
return
ObjectRestResponse
.
succ
(
baseBiz
.
getOne
(
id
,
urlType
));
}
}
@GetMapping
(
"/three/{type}"
)
@GetMapping
(
"/
app/unauth/
three/{type}"
)
@ApiOperation
(
value
=
"随机获取三条数据"
)
@ApiOperation
(
value
=
"随机获取三条数据"
)
public
ObjectRestResponse
randomAccessToThreeData
(
@PathVariable
Integer
type
){
public
ObjectRestResponse
randomAccessToThreeData
(
@PathVariable
Integer
type
){
return
ObjectRestResponse
.
succ
(
baseBiz
.
getThree
(
type
));
return
ObjectRestResponse
.
succ
(
baseBiz
.
getThree
(
type
));
}
}
@GetMapping
(
"/homePage/{type}"
)
@GetMapping
(
"/
app/unauth/
homePage/{type}"
)
@ApiOperation
(
value
=
"获取首页文章列表"
)
@ApiOperation
(
value
=
"获取首页文章列表"
)
public
ObjectRestResponse
getHomePageArticle
(
@PathVariable
Integer
type
){
public
ObjectRestResponse
getHomePageArticle
(
@PathVariable
Integer
type
){
return
ObjectRestResponse
.
succ
(
baseBiz
.
getHomePageArticle
(
type
));
return
ObjectRestResponse
.
succ
(
baseBiz
.
getHomePageArticle
(
type
));
...
@@ -51,11 +51,58 @@ public class ArticleController extends BaseController<ArticleBiz, Article> {
...
@@ -51,11 +51,58 @@ public class ArticleController extends BaseController<ArticleBiz, Article> {
@Override
@Override
@PostMapping
(
"/add"
)
@PostMapping
(
"/add"
)
@ApiOperation
(
value
=
"
获取首页文章列表
"
)
@ApiOperation
(
value
=
"
添加
"
)
public
ObjectRestResponse
add
(
@RequestBody
Article
article
){
public
ObjectRestResponse
add
(
@RequestBody
Article
article
){
baseBiz
.
add
(
article
);
baseBiz
.
add
(
article
);
return
ObjectRestResponse
.
succ
();
return
ObjectRestResponse
.
succ
();
}
}
@PostMapping
(
"/All"
)
@ApiOperation
(
value
=
"获取新闻列表"
)
public
ObjectRestResponse
<
Article
>
findAll
(
@RequestBody
ArticleQuery
query
){
return
ObjectRestResponse
.
succ
(
baseBiz
.
findAll
(
query
));
}
@Override
@PutMapping
(
"/update"
)
@ApiOperation
(
value
=
"修改"
)
public
ObjectRestResponse
update
(
@RequestBody
Article
article
){
int
flag
=
baseBiz
.
updateSelectiveByIdRe
(
article
);
if
(
flag
==
1
)
{
return
ObjectRestResponse
.
succ
();
}
return
ObjectRestResponse
.
createDefaultFail
();
}
@PutMapping
(
"/putaway/{id}"
)
@ApiOperation
(
value
=
"上架"
)
public
ObjectRestResponse
putaway
(
@PathVariable
Integer
id
){
int
flag
=
baseBiz
.
putaway
(
id
);
if
(
flag
==
1
)
{
return
ObjectRestResponse
.
succ
();
}
return
ObjectRestResponse
.
createDefaultFail
();
}
@PutMapping
(
"/soldOut/{id}"
)
@ApiOperation
(
value
=
"下架"
)
public
ObjectRestResponse
soldOut
(
@PathVariable
Integer
id
){
int
flag
=
baseBiz
.
soldOut
(
id
);
if
(
flag
==
1
)
{
return
ObjectRestResponse
.
succ
();
}
return
ObjectRestResponse
.
createDefaultFail
();
}
@PutMapping
(
"/remove/{id}"
)
@ApiOperation
(
value
=
"删除"
)
public
ObjectRestResponse
remove
(
@PathVariable
Integer
id
){
int
flag
=
baseBiz
.
remove
(
id
);
if
(
flag
==
1
)
{
return
ObjectRestResponse
.
succ
();
}
return
ObjectRestResponse
.
createDefaultFail
();
}
}
}
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