Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
wangming
/
kzy-oss
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 4bf3fe30
authored
Mar 13, 2020
by
wangming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'wangming' into '105'
分类管理 See merge request
!3
2 parents
c6a68a2e
23a19dcf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
359 additions
and
144 deletions
src/main/java/com/server/web/controller/ClassController.java
src/main/resources/mybatis/mapping/queryModel.xml
src/main/java/com/server/web/controller/ClassController.java
View file @
4bf3fe3
...
...
@@ -3,7 +3,9 @@ package com.server.web.controller;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageInfo
;
import
com.server.utils.ErrorCode
;
import
com.server.web.common.model.PageModel
;
import
com.server.web.common.mapper.TBaseFirstClassMapper
;
import
com.server.web.common.mapper.TBaseSecondClassMapper
;
import
com.server.web.common.model.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -21,150 +23,299 @@ import java.util.Map;
@RestController
@RequestMapping
(
BaseController
.
OSS_NAMESPACE
+
"/class"
)
public
class
ClassController
extends
BaseController
{
// @Autowired
// private TBaseClassMapper classMapper;
//
//
//
// /**
// * 查询所有分类
// * @param request
// * @param response
// * @return
// */
// @ResponseBody
// @RequestMapping(value = "/queryClassAllList", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
// public Map<String,Object> queryClassAllList(HttpServletRequest request, HttpServletResponse response) {
// Map<String,Object> paramMap = new HashMap<String,Object>();
// paramMap.put("status",1);
// List list =this.openSqlRingsService.selectList_Rings("com.mapping.queryModel.queryClass", paramMap);
// return success(list);
// }
//
//
//
// /**
// * 分类 查询
// * @param request
// * @param response
// * @return
// */
// @ResponseBody
// @RequestMapping(value = "/queryClass", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
// public Map<String,Object> queryClass(int pageNo, int pageSize, HttpServletRequest request, HttpServletResponse response) {
// if(pageNo<=0){
// pageNo = 1;
// }
// if(pageSize==0){
// pageSize = 10;
// }
// Map<String,Object> paramMap = new HashMap<String,Object>();
// String className = request.getParameter("className");//类型 1 APP 2 微信 3 PC 4 小程序
// if(StringUtils.hasText(className)){
// paramMap.put("className","%"+className+"%");
// }
// PageHelper.startPage(pageNo, pageSize);
// List list =this.openSqlRingsService.selectList_Rings("com.mapping.queryModel.queryClass", paramMap);
// PageInfo pageInfo = new PageInfo(list);
// PageModel model = new PageModel();
// model.setTotal(pageInfo.getTotal());
// model.setList(list);
// return success(model);
// }
//
//
// /**
// * 分类启用关闭
// * @param id
// * @param status 状态 1 启用 0 关闭
// * @param request
// * @param response
// * @return
// */
// @ResponseBody
// @RequestMapping(value = "/updateStatus", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
// public Map<String,Object> updateStatus(@RequestParam("id") long id , @RequestParam("status") int status, HttpServletRequest request, HttpServletResponse response) {
// try{
// if(status==0||status==1){
// TBaseClass baseClass = new TBaseClass();
// baseClass.setId(id);
// baseClass.setStatus(status);
// classMapper.updateByPrimaryKeySelective(baseClass);
// return success("");
// }else{
// return error(ErrorCode.ERROR.getCode(),"服务器忙,请稍后重试~","服务器忙,请稍后重试~");
// }
// }catch (Exception e){
// e.printStackTrace();
// return error(ErrorCode.ERROR.getCode(),"服务器忙,请稍后重试~","服务器忙,请稍后重试~");
// }
// }
//
// /**
// * 根据id查询分类
// * @param id
// * @param request
// * @param response
// * @return
// */
// @ResponseBody
// @RequestMapping(value = "/getClassById", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
// public Map<String,Object> getClassById(@RequestParam("id") Long id , HttpServletRequest request, HttpServletResponse response) {
// try{
// TBaseClass baseClass=classMapper.selectByPrimaryKey(id);
// return success(baseClass);
// }catch (Exception e){
// e.printStackTrace();
// return error(ErrorCode.ERROR.getCode(),"服务器忙,请稍后重试~","服务器忙,请稍后重试~");
// }
// }
// /**
// * 保存修改分类
// * @param request
// * @param response
// * @return
// */
// @ResponseBody
// @RequestMapping(value = "/saveOrUpdateClass", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
// public Map<String,Object> saveOrUpdateClass(HttpServletRequest request, HttpServletResponse response) {
// try{
// String id = request.getParameter("id");
// TBaseClass baseClass = new TBaseClass();
// if(StringUtils.hasText(id)){
// baseClass.setId(Long.valueOf(id.trim()));
// }else{
// baseClass.setCreateDt(new Date());
// }
// baseClass.setClassName(request.getParameter("className"));
// if(StringUtils.hasText(request.getParameter("fid"))){
// baseClass.setLevel(2);
// baseClass.setFid(Long.valueOf(request.getParameter("fid")));
// }else{
// baseClass.setLevel(1);
// }
// if(StringUtils.hasText(request.getParameter("status"))){
// baseClass.setStatus(Integer.valueOf(request.getParameter("status")));
// }else{
// baseClass.setStatus(1);
// }
// baseClass.setPicUrl(request.getParameter("picUrl"));
// if(StringUtils.hasText(request.getParameter("weight"))){
// baseClass.setWeight(Integer.valueOf(request.getParameter("weight")));
// }else{
// baseClass.setWeight(1);
// }
// if(baseClass.getId()!=null){
// classMapper.updateByPrimaryKeySelective(baseClass);
// }else{
// classMapper.insertSelective(baseClass);
// }
// return success("");
// }catch (Exception e){
// e.printStackTrace();
// return error(ErrorCode.ERROR.getCode(),"服务器忙,请稍后重试~","服务器忙,请稍后重试~");
// }
// }
@Autowired
private
TBaseFirstClassMapper
classMapper
;
@Autowired
private
TBaseSecondClassMapper
secondClassMapper
;
/**
* 一级分类列表
* @param pageNo
* @param pageSize
* @return
*/
@ResponseBody
@RequestMapping
(
value
=
"/firstClassList"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
},
produces
=
"application/json"
)
public
Map
<
String
,
Object
>
firstClassList
(
@RequestParam
(
defaultValue
=
"1"
)
Integer
pageNo
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
pageSize
)
{
TBaseFirstClassExample
example
=
new
TBaseFirstClassExample
();
PageHelper
.
startPage
(
pageNo
,
pageSize
,
true
,
false
);
List
list
=
classMapper
.
selectByExample
(
example
);
PageInfo
pageInfo
=
new
PageInfo
(
list
);
PageModel
model
=
new
PageModel
();
model
.
setTotal
(
pageInfo
.
getTotal
());
model
.
setList
(
list
);
return
success
(
model
);
}
/**
* 二级分类列表
* @param firstClassId
* @param pageNo
* @param pageSize
* @return
*/
@ResponseBody
@RequestMapping
(
value
=
"/secondClassList"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
},
produces
=
"application/json"
)
public
Map
<
String
,
Object
>
secondClassList
(
Long
firstClassId
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
pageNo
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
pageSize
)
{
Map
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"firstClassId"
,
firstClassId
);
PageHelper
.
startPage
(
pageNo
,
pageSize
,
true
,
false
);
List
list
=
openSqlRingsService
.
selectList_Rings
(
"com.mapping.queryModel.secondClassList"
,
paramMap
);
PageInfo
pageInfo
=
new
PageInfo
(
list
);
PageModel
model
=
new
PageModel
();
model
.
setTotal
(
pageInfo
.
getTotal
());
model
.
setList
(
list
);
return
success
(
model
);
}
/**
* 保存修改一级分类
* @param request
* @param response
* @return
*/
@ResponseBody
@RequestMapping
(
value
=
"/saveOrUpdateFirstClass"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
},
produces
=
"application/json"
)
public
Map
<
String
,
Object
>
saveOrUpdateFirstClass
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
try
{
String
id
=
request
.
getParameter
(
"id"
);
TBaseFirstClass
baseClass
=
new
TBaseFirstClass
();
if
(
StringUtils
.
hasText
(
id
)){
baseClass
.
setId
(
Long
.
valueOf
(
id
.
trim
()));
}
else
{
baseClass
.
setCreateDt
(
new
Date
());
}
baseClass
.
setClassName
(
request
.
getParameter
(
"className"
));
if
(
StringUtils
.
hasText
(
request
.
getParameter
(
"status"
))){
baseClass
.
setStatus
(
Integer
.
valueOf
(
request
.
getParameter
(
"status"
)));
}
else
{
baseClass
.
setStatus
(
1
);
}
baseClass
.
setPicUrl
(
request
.
getParameter
(
"picUrl"
));
if
(
StringUtils
.
hasText
(
request
.
getParameter
(
"weight"
))){
baseClass
.
setWeight
(
Integer
.
valueOf
(
request
.
getParameter
(
"weight"
)));
}
else
{
baseClass
.
setWeight
(
1
);
}
if
(
baseClass
.
getId
()!=
null
){
classMapper
.
updateByPrimaryKeySelective
(
baseClass
);
}
else
{
baseClass
.
setCreateDt
(
new
Date
());
classMapper
.
insertSelective
(
baseClass
);
}
return
success
(
""
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
error
(
ErrorCode
.
ERROR
.
getCode
(),
"服务器忙,请稍后重试~"
,
"服务器忙,请稍后重试~"
);
}
}
/**
* 保存二级分类
* @param request
* @param response
* @return
*/
@ResponseBody
@RequestMapping
(
value
=
"/saveSecondClass"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
},
produces
=
"application/json"
)
public
Map
<
String
,
Object
>
saveOrUpdateSecondClass
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
try
{
String
className
=
request
.
getParameter
(
"className"
);
Integer
status
=
Integer
.
valueOf
(
request
.
getParameter
(
"status"
));
Integer
type
=
Integer
.
valueOf
(
request
.
getParameter
(
"type"
));
String
picUrl
=
request
.
getParameter
(
"picUrl"
);
Long
firstId
=
Long
.
valueOf
(
request
.
getParameter
(
"firstId"
));
Integer
weight
=
Integer
.
valueOf
(
request
.
getParameter
(
"weight"
));
TBaseSecondClass
baseClass
=
new
TBaseSecondClass
();
baseClass
.
setPicUrl
(
picUrl
);
baseClass
.
setClassName
(
className
);
baseClass
.
setType
(
type
);
baseClass
.
setStatus
(
status
);
baseClass
.
setFirstId
(
firstId
);
baseClass
.
setWeight
(
weight
);
baseClass
.
setCreateDt
(
new
Date
());
secondClassMapper
.
insertSelective
(
baseClass
);
return
success
(
""
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
error
(
ErrorCode
.
ERROR
.
getCode
(),
"服务器忙,请稍后重试~"
,
"服务器忙,请稍后重试~"
);
}
}
/**
* 修改二级分类
* @param request
* @param response
* @return
*/
@ResponseBody
@RequestMapping
(
value
=
"/updateSecondClass"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
},
produces
=
"application/json"
)
public
Map
<
String
,
Object
>
updateSecondClass
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
try
{
Long
id
=
Long
.
valueOf
(
request
.
getParameter
(
"id"
));
TBaseSecondClass
baseClass
=
secondClassMapper
.
selectByPrimaryKey
(
id
);
if
(
null
==
baseClass
){
return
error
(
ErrorCode
.
ERROR
.
getCode
(),
"无效ID"
,
"无效ID"
);
}
String
className
=
request
.
getParameter
(
"className"
);
Integer
status
=
Integer
.
valueOf
(
request
.
getParameter
(
"status"
));
String
picUrl
=
request
.
getParameter
(
"picUrl"
);
Integer
weight
=
Integer
.
valueOf
(
request
.
getParameter
(
"weight"
));
baseClass
.
setPicUrl
(
picUrl
);
baseClass
.
setClassName
(
className
);
baseClass
.
setStatus
(
status
);
baseClass
.
setWeight
(
weight
);
secondClassMapper
.
updateByPrimaryKeySelective
(
baseClass
);
return
success
(
""
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
error
(
ErrorCode
.
ERROR
.
getCode
(),
"服务器忙,请稍后重试~"
,
"服务器忙,请稍后重试~"
);
}
}
/**
* 一级分类启用关闭
* @param id
* @param status 状态 1 启用 0 关闭
* @return
*/
@ResponseBody
@RequestMapping
(
value
=
"/updateFirstClassStatus"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
},
produces
=
"application/json"
)
public
Map
<
String
,
Object
>
updateFirstClassStatus
(
@RequestParam
(
"id"
)
long
id
,
@RequestParam
(
"status"
)
int
status
)
{
try
{
if
(
status
==
0
||
status
==
1
){
TBaseFirstClass
baseClass
=
new
TBaseFirstClass
();
baseClass
.
setId
(
id
);
baseClass
.
setStatus
(
status
);
classMapper
.
updateByPrimaryKeySelective
(
baseClass
);
return
success
(
""
);
}
else
{
return
error
(
ErrorCode
.
ERROR
.
getCode
(),
"服务器忙,请稍后重试~"
,
"服务器忙,请稍后重试~"
);
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
error
(
ErrorCode
.
ERROR
.
getCode
(),
"服务器忙,请稍后重试~"
,
"服务器忙,请稍后重试~"
);
}
}
/**
* 二级分类启用关闭
* @param id
* @param status 状态 1 启用 0 关闭
* @return
*/
@ResponseBody
@RequestMapping
(
value
=
"/updateSecondClassStatus"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
},
produces
=
"application/json"
)
public
Map
<
String
,
Object
>
updateSecondClassStatus
(
@RequestParam
(
"id"
)
long
id
,
@RequestParam
(
"status"
)
int
status
)
{
try
{
if
(
status
==
0
||
status
==
1
){
TBaseSecondClass
baseClass
=
new
TBaseSecondClass
();
baseClass
.
setId
(
id
);
baseClass
.
setStatus
(
status
);
secondClassMapper
.
updateByPrimaryKeySelective
(
baseClass
);
return
success
(
""
);
}
else
{
return
error
(
ErrorCode
.
ERROR
.
getCode
(),
"服务器忙,请稍后重试~"
,
"服务器忙,请稍后重试~"
);
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
error
(
ErrorCode
.
ERROR
.
getCode
(),
"服务器忙,请稍后重试~"
,
"服务器忙,请稍后重试~"
);
}
}
/**
* 根据id查询一级分类
* @param id
* @param request
* @param response
* @return
*/
@ResponseBody
@RequestMapping
(
value
=
"/getFirstClassById"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
},
produces
=
"application/json"
)
public
Map
<
String
,
Object
>
getClassById
(
@RequestParam
(
"id"
)
Long
id
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
try
{
TBaseFirstClass
baseClass
=
classMapper
.
selectByPrimaryKey
(
id
);
return
success
(
baseClass
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
error
(
ErrorCode
.
ERROR
.
getCode
(),
"服务器忙,请稍后重试~"
,
"服务器忙,请稍后重试~"
);
}
}
/**
* 根据二级分类ID获取二级分类
* @param id
* @return
*/
@ResponseBody
@RequestMapping
(
value
=
"/getSecondClassById"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
},
produces
=
"application/json"
)
public
Map
<
String
,
Object
>
getSecondClassById
(
@RequestParam
(
"id"
)
Long
id
)
{
try
{
Map
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"id"
,
id
);
Map
map
=
(
Map
)
openSqlRingsService
.
selectOne_Rings
(
"com.mapping.queryModel.getSecondClassById"
,
paramMap
);
return
success
(
map
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
error
(
ErrorCode
.
ERROR
.
getCode
(),
"服务器忙,请稍后重试~"
,
"服务器忙,请稍后重试~"
);
}
}
/**
* 用于前端下拉一级分类列表
* @param pageNo
* @param pageSize
* @return
*/
@ResponseBody
@RequestMapping
(
value
=
"/selectFirstClassList"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
},
produces
=
"application/json"
)
public
Map
<
String
,
Object
>
selectFirstClassList
(
@RequestParam
(
defaultValue
=
""
)
String
name
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
pageNo
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
pageSize
)
{
Map
paramMap
=
new
HashMap
<>();
if
(!(
""
).
equals
(
name
)){
paramMap
.
put
(
"name"
,
"%"
+
name
+
"%"
);
}
PageHelper
.
startPage
(
pageNo
,
pageSize
,
true
,
false
);
List
list
=
openSqlRingsService
.
selectList_Rings
(
"com.mapping.queryModel.selectFirstClassList"
,
paramMap
);
PageInfo
pageInfo
=
new
PageInfo
(
list
);
PageModel
model
=
new
PageModel
();
model
.
setTotal
(
pageInfo
.
getTotal
());
model
.
setList
(
list
);
return
success
(
model
);
}
/**
* 用于前端下拉二级分类列表
* @param pageNo
* @param pageSize
* @param type 1资讯 2录播 3直播
* @return
*/
@ResponseBody
@RequestMapping
(
value
=
"/selectSecondClassList"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
},
produces
=
"application/json"
)
public
Map
<
String
,
Object
>
selectSecondClassList
(
@RequestParam
(
defaultValue
=
"-1"
)
Integer
type
,
@RequestParam
(
defaultValue
=
""
)
String
name
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
pageNo
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
pageSize
)
{
Map
paramMap
=
new
HashMap
<>();
if
(!(
""
).
equals
(
name
)){
paramMap
.
put
(
"name"
,
"%"
+
name
+
"%"
);
}
if
(
type
!=-
1
){
paramMap
.
put
(
"type"
,
type
);
}
PageHelper
.
startPage
(
pageNo
,
pageSize
,
true
,
false
);
List
list
=
openSqlRingsService
.
selectList_Rings
(
"com.mapping.queryModel.selectSecondClassList"
,
paramMap
);
PageInfo
pageInfo
=
new
PageInfo
(
list
);
PageModel
model
=
new
PageModel
();
model
.
setTotal
(
pageInfo
.
getTotal
());
model
.
setList
(
list
);
return
success
(
model
);
}
}
src/main/resources/mybatis/mapping/queryModel.xml
View file @
4bf3fe3
...
...
@@ -61,4 +61,67 @@
ORDER BY t.create_dt DESC
</select>
<select
id=
"secondClassList"
resultType=
"java.util.HashMap"
parameterType=
"java.util.HashMap"
>
SELECT
t.id,
t.class_name as className,
t.type,
t.`status`,
t1.class_name as firstName,
t.pic_url as picUrl,
t.weight,
date_format(t.create_dt,'%Y-%m-%d %H:%i:%S') createDt
FROM
t_base_second_class t
LEFT JOIN t_base_first_class t1 ON t.first_id=t1.id
WHERE t.first_id = #{firstClassId,jdbcType=BIGINT}
ORDER BY t.weight DESC
</select>
<select
id=
"getSecondClassById"
resultType=
"java.util.HashMap"
parameterType=
"java.util.HashMap"
>
SELECT
t.id,
t.class_name as className,
t.type,
t.`status`,
t1.class_name as firstName,
t.pic_url as picUrl,
t.weight
FROM
t_base_second_class t
LEFT JOIN t_base_first_class t1 ON t.first_id=t1.id
WHERE t.id= #{id,jdbcType=BIGINT}
</select>
<select
id=
"selectFirstClassList"
resultType=
"java.util.HashMap"
parameterType=
"java.util.HashMap"
>
SELECT
t.id,
t.class_name as className
FROM
t_base_first_class t
WHERE t.`status` = 1
<if
test=
"name != null"
>
AND t.class_name LIKE #{name}
</if>
ORDER BY t.id DESC
</select>
<select
id=
"selectSecondClassList"
resultType=
"java.util.HashMap"
parameterType=
"java.util.HashMap"
>
SELECT
t.id,
t.class_name AS className
FROM
t_base_second_class t
WHERE
t.`status` = 1
<if
test=
"type != null"
>
AND t.type = #{type,jdbcType=INTEGER}
</if>
<if
test=
"name != null"
>
AND t.class_name LIKE #{name}
</if>
ORDER BY t.id DESC
</select>
</mapper>
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment