Mall商城

·本篇:28.4k字 大约需要: 152分钟

Mall商城

从头到尾,一步一步复现Mall商城项目

Mall项目主要结构

mall-mbg

mall-mbg模块主要用于通过MyBatis生成器生成的数据交互代码,mall-mbg模块目录结构如下

mall-mbg模块目录结构

generatorConfig.xml文件对MBG进行了一些配置,如生成的实体类存储在com.macro.mall.model包下,生成的mapper接口存储在com.macro.mall.mapper包下,生成的mapper.xml文件放在resources中的com.macro.mall.mapper目录下

CommentGenerator.java继承了DefaultCommentGenerator,可以自定义实体类代码的生成,这里添加了Swagger注解的支持

mall-common

分页插件pagehelper-spring-boot-starterpagehelper的区别

SpringBoot之分页PageHelper 求求别误导了_weixin_33770878的博客-CSDN博客

先对pom.xml文件进行分析,再对包结构进行分析。

validation进行数据的合理性校验

SpringBoot 使用validation数据校验-超级详细超级多干货 - 第406篇 - 知乎 (zhihu.com)

还是先从mbg模块开始

// TODO

应该分析下各模块的实现思路

Mall项目主要结构

mall-admin

后台商城管理系统接口

mall-portal

前台商城系统接口

mall-common

工具类及通用代码

mall-mbg

MyBatis Generator生成的数据库操作代码

基于Elasticsearch的商品搜索系统

mall-security

SpringSecurity封装公用模块

mall-common模块

pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<dependencies>
<!--SpringWeb启动项-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--spring-boot-starter-validation可以用来校验SpringMVC的入参,
也就是可以用来校验参数的合理性-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!--Mybatis分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</dependency>
<!--SpringData Redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--SpringData工具包-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<!--集成logstash-->
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
</dependency>
<!--Swagger-UI API文档生产工具-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
</dependency>
</dependencies>

包结构

1
2
3
4
5
6
7
8
9
10
11
12
13
mall-common
└─com
└─macro
└─mall
└─common
├─api
├─config
├─domain
├─exception
├─log
├─service
│ └─impl
└─util

mall-common模块的包都统一放在了com.macro.mall.common包下

  • api包中存放了一些封装了通用返回结果的类,用于前后端交互

  • config包中存放了Redis基础配置和Swagger基础配置类,如果其他模块也需要配置Redis和Swagger,可以直接继承该类

  • domain包中存放了Swagger的自定义配置和Controller层的日志封装类

  • exception包中存放了一些异常处理类

  • log包中存放了统一日志处理切面类

  • service包中存放了Redis相关操作业务类

  • util包中存放了请求工具类

主要代码分析

全局异常处理类

  • @ControllerAdvice:用于捕获全局异常,能作用于所有controller中
  • @ExceptionHandler:修饰方法,表示该方法为处理全局异常的方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.macro.mall.common.exception;
/**
* 全局异常处理类
*/
// 常与 @ExceptionHandler 注解一起使用,用于捕获全局异常,能作用于所有controller中
@ControllerAdvice
public class GlobalExceptionHandler {

@ResponseBody
// 修饰方法,表示该方法为处理全局异常的方法,value表示能处理的异常
@ExceptionHandler(value = ApiException.class)
public CommonResult handle(ApiException e) {
if (e.getErrorCode() != null) {
return CommonResult.failed(e.getErrorCode());
}
return CommonResult.failed(e.getMessage());
}

@ResponseBody
@ExceptionHandler(value = MethodArgumentNotValidException.class)
public CommonResult handleValidException(MethodArgumentNotValidException e) {
BindingResult bindingResult = e.getBindingResult();
String message = null;
if (bindingResult.hasErrors()) {
FieldError fieldError = bindingResult.getFieldError();
if (fieldError != null) {
message = fieldError.getField() + fieldError.getDefaultMessage();
}
}
return CommonResult.validateFailed(message);
}

@ResponseBody
@ExceptionHandler(value = BindException.class)
public CommonResult handleValidException(BindException e) {
BindingResult bindingResult = e.getBindingResult();
String message = null;
if (bindingResult.hasErrors()) {
FieldError fieldError = bindingResult.getFieldError();
if (fieldError != null) {
message = fieldError.getField() + fieldError.getDefaultMessage();
}
}
return CommonResult.validateFailed(message);
}
}

统一日志处理切面

  • @Aspect:表示该类为切面类
  • @Around():通知方法会将目标方法封装起来
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* 统一日志处理切面
*/
// 表示该类为切面类
@Aspect
@Component
@Order(1)
public class WebLogAspect
{
private static final Logger LOGGER = LoggerFactory.getLogger(WebLogAspect.class);

// 切点表达式
@Pointcut("execution(public * com.macro.mall.controller.*.*(..))||execution(public * com.macro.mall.*.controller.*.*(..))")
public void webLog(){}

// 表示被增强方法执行之前调用
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable
{}

@AfterReturning(value = "webLog()", returning = "ret")
public void doAfterReturning(Object ret) throws Throwable
{}

// 通知方法会将目标方法封装起来
@Around("webLog()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable
{
// 返回当前时间
long startTime = System.currentTimeMillis();
//获取当前请求对象
ServletRequestAttributes attributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = Objects.requireNonNull(attributes).getRequest();
//记录请求信息(通过Logstash传入Elasticsearch)
WebLog webLog = new WebLog();
// 目标方法执行
Object result = joinPoint.proceed();
// 获取签名
Signature signature = joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
// 获取到目标方法
Method method = methodSignature.getMethod();
// 判断该方法是否有ApiOperation注解
if(method.isAnnotationPresent(ApiOperation.class)){
// 获取ApiOperation注解的value,加入到log
ApiOperation log = method.getAnnotation(ApiOperation.class);
webLog.setDescription(log.value());
}
// 获取目标方法执行结束时间
long endTime = System.currentTimeMillis();
// 构造日志对象
String urlStr = request.getRequestURL().toString();
LOGGER.info("urlStr = {}", urlStr);
webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath()));
webLog.setUsername(request.getRemoteUser());
webLog.setIp(RequestUtil.getRequestIp(request));
webLog.setMethod(request.getMethod());
// 处理目标方法请求参数
webLog.setParameter(getParameter(method, joinPoint.getArgs()));
webLog.setResult(result);
webLog.setSpendTime((int) (endTime - startTime));
webLog.setStartTime(startTime);
webLog.setUri(request.getRequestURI());
webLog.setUrl(request.getRequestURL().toString());
Map<String, Object> logMap = new HashMap<>();
logMap.put("url", webLog.getUrl());
logMap.put("method", webLog.getMethod());
logMap.put("parameter", webLog.getParameter());
logMap.put("spendTime", webLog.getSpendTime());
logMap.put("description", webLog.getDescription());
// LOGGER.info("{}", JSONUtil.parse(webLog));
LOGGER.info(Markers.appendEntries(logMap), JSONUtil.parse(webLog).toString());
return result;
}

/**
* 根据方法和传入的参数获取请求参数
*/
private Object getParameter(Method method, Object[] args)
{
List<Object> argList = new ArrayList<>();
Parameter[] parameters = method.getParameters();
for(int i = 0; i < parameters.length; i++){
//将RequestBody注解修饰的参数作为请求参数
RequestBody requestBody = parameters[i].getAnnotation(RequestBody.class);
if(requestBody != null){
argList.add(args[i]);
}
//将RequestParam注解修饰的参数作为请求参数
RequestParam requestParam = parameters[i].getAnnotation(RequestParam.class);
if(requestParam != null){
Map<String, Object> map = new HashMap<>();
String key = parameters[i].getName();
if(!StrUtil.isEmpty(requestParam.value())){
key = requestParam.value();
}
if(args[i] != null){
map.put(key, args[i]);
argList.add(map);
}
}
}
if(argList.size() == 0){
return null;
} else if(argList.size() == 1){
return argList.get(0);
} else{
return argList;
}
}
}

mall-mbg模块

pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<dependencies>
<!--工具类及通用代码模块-->
<dependency>
<groupId>com.macro.mall</groupId>
<artifactId>mall-common</artifactId>
</dependency>
<!--MyBatis分页插件starter-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<!--集成druid连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<!-- MyBatis 生成器 -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
</dependency>
<!--Mysql数据库驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>

包结构

1
2
3
4
5
6
7
8
9
10
11
12
mall-mbg
├─java
│ └─com
│ └─macro
│ └─mall
│ ├─mapper
│ └─model
└─resources
└─com
└─macro
└─mall
└─mapper

mall-mbg模块的包都统一放在com.macro.mall包下

  • mapper包中存放了MyBatis Generator生成的数据库中相关表的mapper
  • model包中存放了MyBatis Generator生成的数据库中相关表的实体类
  • resources中com.macro.mall.mapper文件夹下存放了mapper包中对应的mapper.xml文件

mall-search模块

pom.xml

1
2
3
4
5
6
7
8
9
10
<!--mall中MBG生成模块-->
<dependency>
<groupId>com.macro.mall</groupId>
<artifactId>mall-mbg</artifactId>
</dependency>
<!--SpringBoot-Data-elasticsearch-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>

包结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mall-search
├─java
│ └─com
│ └─macro
│ └─mall
│ └─search
│ ├─config
│ ├─controller
│ ├─dao
│ ├─domain
│ ├─repository
│ └─service
│ └─impl
└─resources
└─dao

mall-search模块的包都统一放在com.macro.mall.search包下

  • config包中存放了一些配置类
  • controller包中存放了商品搜索管理的接口
  • dao包中存放了商品搜索的自定义Dao,主要用来将数据库中的商品导入ES
  • domain包中存放了商品的相关信息类
  • repository包中存放了ES操作类
  • service包中存放了商品搜索管理的业务类

主要代码分析

搜索商品的信息类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* 搜索商品的信息
*/
@Data
@EqualsAndHashCode
// indexName索引名称,表示该类为文档
@Document(indexName = "pms")
// shards:分片,replicas:副本
@Setting(shards = 1, replicas = 0)
public class EsProduct implements Serializable
{
private static final long serialVersionUID = -1L;
@Id
private Long id;
@Field(type = FieldType.Keyword)
private String productSn;
private Long brandId;
@Field(type = FieldType.Keyword)
private String brandName;
private Long productCategoryId;
@Field(type = FieldType.Keyword)
private String productCategoryName;
private String pic;
@Field(analyzer = "ik_max_word", type = FieldType.Text)
private String name;
@Field(analyzer = "ik_max_word", type = FieldType.Text)
private String subTitle;
@Field(analyzer = "ik_max_word", type = FieldType.Text)
private String keywords;
private BigDecimal price;
private Integer sale;
private Integer newStatus;
private Integer recommandStatus;
private Integer stock;
private Integer promotionType;
private Integer sort;
@Field(type = FieldType.Nested, fielddata = true)
private List<EsProductAttributeValue> attrValueList;
}

搜索商品管理业务类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* 搜索商品管理Service
*/
public interface EsProductService
{
/**
* 从数据库中导入所有商品到ES
*/
int importAll();

/**
* 根据id删除商品
*/
void delete(Long id);

/**
* 根据id创建商品
*/
EsProduct create(Long id);

/**
* 批量删除商品
*/
void delete(List<Long> ids);

/**
* 根据关键字搜索名称或者副标题
*/
Page<EsProduct> search(String keyword, Integer pageNum, Integer pageSize);

/**
* 根据关键字搜索名称或者副标题复合查询
*/
Page<EsProduct> search(String keyword, Long brandId, Long productCategoryId, Integer pageNum, Integer pageSize,
Integer sort);

/**
* 根据商品id推荐相关商品
*/
Page<EsProduct> recommend(Long id, Integer pageNum, Integer pageSize);

/**
* 获取搜索词相关品牌、分类、属性
*/
EsProductRelatedInfo searchRelatedInfo(String keyword);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/**
* 搜索商品管理Service实现类
*/
@Service
public class EsProductServiceImpl implements EsProductService
{
private static final Logger LOGGER = LoggerFactory.getLogger(EsProductServiceImpl.class);
@Resource
private EsProductDao productDao;
@Resource
private EsProductRepository productRepository;
@Resource
private ElasticsearchRestTemplate elasticsearchRestTemplate;

@Override
public int importAll()
{
// 从数据库中获取所有商品数据信息
List<EsProduct> esProductList = productDao.getAllEsProductList(null);
// 将数据库中的商品信息导入ES
Iterable<EsProduct> esProductIterable = productRepository.saveAll(esProductList);
// 获取相应对象的迭代器
Iterator<EsProduct> iterator = esProductIterable.iterator();
// 统计导入的数据条数
int result = 0;
while(iterator.hasNext()){
result++;
iterator.next();
}
return result;
}

@Override
public void delete(Long id)
{
productRepository.deleteById(id);
}

@Override
public EsProduct create(Long id)
{
EsProduct result = null;
// 从数据库中获取该id的商品信息
List<EsProduct> esProductList = productDao.getAllEsProductList(id);
// 将该商品信息导入ES
if(esProductList.size() > 0){
EsProduct esProduct = esProductList.get(0);
result = productRepository.save(esProduct);
}
return result;
}

@Override
public void delete(List<Long> ids)
{
if(!CollectionUtils.isEmpty(ids)){
List<EsProduct> esProductList = new ArrayList<>();
for(Long id : ids){
EsProduct esProduct = new EsProduct();
esProduct.setId(id);
esProductList.add(esProduct);
}
productRepository.deleteAll(esProductList);
}
}

@Override
public Page<EsProduct> search(String keyword, Integer pageNum, Integer pageSize)
{
Pageable pageable = PageRequest.of(pageNum, pageSize);
return productRepository.findByNameOrSubTitleOrKeywords(keyword, keyword, keyword, pageable);
}

@Override
public Page<EsProduct> search(String keyword, Long brandId, Long productCategoryId, Integer pageNum,
Integer pageSize, Integer sort)
{
// 获取分页信息包装类
Pageable pageable = PageRequest.of(pageNum, pageSize);

// NativeSearchQuery查询对象构造器
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
//分页
nativeSearchQueryBuilder.withPageable(pageable);
//过滤
if(brandId != null || productCategoryId != null){
// 获取bool查询对象构造器
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if(brandId != null){
// terms查询,基于关键字查询
boolQueryBuilder.must(QueryBuilders.termQuery("brandId", brandId));
}
if(productCategoryId != null){
boolQueryBuilder.must(QueryBuilders.termQuery("productCategoryId", productCategoryId));
}
// 加入过滤条件
nativeSearchQueryBuilder.withFilter(boolQueryBuilder);
}
//搜索
if(StrUtil.isEmpty(keyword)){
// 如果关键词为空,则查询所有文档
nativeSearchQueryBuilder.withQuery(QueryBuilders.matchAllQuery());
}else{
// 过滤器列表
List<FunctionScoreQueryBuilder.FilterFunctionBuilder> filterFunctionBuilders = new ArrayList<>();
// 过滤函数构造器
filterFunctionBuilders.add(new FunctionScoreQueryBuilder
.FilterFunctionBuilder(QueryBuilders.matchQuery("name", keyword),
ScoreFunctionBuilders.weightFactorFunction(10))); // 设置多字段查询权重
filterFunctionBuilders.add(new FunctionScoreQueryBuilder
.FilterFunctionBuilder(QueryBuilders.matchQuery("subTitle", keyword),
ScoreFunctionBuilders.weightFactorFunction(5)));
filterFunctionBuilders.add(new FunctionScoreQueryBuilder
.FilterFunctionBuilder(QueryBuilders.matchQuery("keywords", keyword),
ScoreFunctionBuilders.weightFactorFunction(2)));
FunctionScoreQueryBuilder.FilterFunctionBuilder[] builders = new FunctionScoreQueryBuilder
.FilterFunctionBuilder[filterFunctionBuilders.size()];
filterFunctionBuilders.toArray(builders); // 转换为数组形式
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery(builders)
.scoreMode(FunctionScoreQuery.ScoreMode.SUM) // 对结果分数求和
.setMinScore(2);
// 添加过滤条件
nativeSearchQueryBuilder.withQuery(functionScoreQueryBuilder);
}
//排序
if(sort == 1){
//按新品从新到旧
nativeSearchQueryBuilder.withSorts(SortBuilders.fieldSort("id").order(SortOrder.DESC));
}else if(sort == 2){
//按销量从高到低
nativeSearchQueryBuilder.withSorts(SortBuilders.fieldSort("sale").order(SortOrder.DESC));
}else if(sort == 3){
//按价格从低到高
nativeSearchQueryBuilder.withSorts(SortBuilders.fieldSort("price").order(SortOrder.ASC));
}else if(sort == 4){
//按价格从高到低
nativeSearchQueryBuilder.withSorts(SortBuilders.fieldSort("price").order(SortOrder.DESC));
}else{
//按相关度,即文档得分
nativeSearchQueryBuilder.withSorts(SortBuilders.scoreSort().order(SortOrder.DESC));
}
// 按相关度
nativeSearchQueryBuilder.withSorts(SortBuilders.scoreSort().order(SortOrder.DESC));
// NativeSearchQuery 查询对象
NativeSearchQuery searchQuery = nativeSearchQueryBuilder.build();
LOGGER.info("DSL:{}", Objects.requireNonNull(searchQuery.getQuery()));
// 查询结果Hit数组
SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class);
// 查询到的总条数
if(searchHits.getTotalHits() <= 0){
// 没有查询到,返回空
return new PageImpl<>(ListUtil.empty(), pageable, 0);
}
// 获取查询到的对象
List<EsProduct> searchProductList = searchHits.stream()
.map(SearchHit::getContent)
.collect(Collectors.toList());
// 封装为分页对象返回
return new PageImpl<>(searchProductList, pageable, searchHits.getTotalHits());
}

@Override
public Page<EsProduct> recommend(Long id, Integer pageNum, Integer pageSize)
{
// 封装分页信息对象
Pageable pageable = PageRequest.of(pageNum, pageSize);
// 从数据库中获取对应id商品
List<EsProduct> esProductList = productDao.getAllEsProductList(id);
// 如果获取到该商品
if(esProductList.size() > 0){
// 获取该商品对象
EsProduct esProduct = esProductList.get(0);
// 获取商品名
String keyword = esProduct.getName();
// 获取品牌id
Long brandId = esProduct.getBrandId();
// 获取商品属性类别id
Long productCategoryId = esProduct.getProductCategoryId();
// 根据商品标题、品牌、分类进行搜索
// 多字段权重排序
List<FunctionScoreQueryBuilder.FilterFunctionBuilder> filterFunctionBuilders = new ArrayList<>();

filterFunctionBuilders.add(new FunctionScoreQueryBuilder
.FilterFunctionBuilder(QueryBuilders.matchQuery("name", keyword),
ScoreFunctionBuilders.weightFactorFunction(8)));
filterFunctionBuilders.add(new FunctionScoreQueryBuilder
.FilterFunctionBuilder(QueryBuilders.matchQuery("subTitle", keyword),
ScoreFunctionBuilders.weightFactorFunction(2)));
filterFunctionBuilders.add(new FunctionScoreQueryBuilder
.FilterFunctionBuilder(QueryBuilders.matchQuery("keywords", keyword),
ScoreFunctionBuilders.weightFactorFunction(2)));
filterFunctionBuilders.add(new FunctionScoreQueryBuilder
.FilterFunctionBuilder(QueryBuilders.matchQuery("brandId", brandId),
ScoreFunctionBuilders.weightFactorFunction(5)));
filterFunctionBuilders.add(new FunctionScoreQueryBuilder
.FilterFunctionBuilder(QueryBuilders.matchQuery("productCategoryId", productCategoryId),
ScoreFunctionBuilders.weightFactorFunction(3)));
FunctionScoreQueryBuilder.FilterFunctionBuilder[] builders =
new FunctionScoreQueryBuilder.FilterFunctionBuilder[filterFunctionBuilders.size()];
filterFunctionBuilders.toArray(builders);

// 允许自定评分的函数查询
FunctionScoreQueryBuilder functionScoreQueryBuilder =
QueryBuilders.functionScoreQuery(builders)
.scoreMode(FunctionScoreQuery.ScoreMode.SUM)
.setMinScore(2);
// 用于过滤掉相同的商品
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder()
.mustNot(QueryBuilders.termQuery("id", id));

//构建查询条件
NativeSearchQueryBuilder builder =
new NativeSearchQueryBuilder().withQuery(functionScoreQueryBuilder)
.withFilter(boolQueryBuilder)
.withPageable(pageable);
NativeSearchQuery searchQuery = builder.build();
LOGGER.info("DSL: {}", Objects.requireNonNull(searchQuery.getQuery()));
// 获取结果hit数组
SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class);
// 如果查询到的总条数小于0,即没有查到,则返回空列表
if(searchHits.getTotalHits() <= 0){
return new PageImpl<>(ListUtil.empty(), pageable, 0);
}
// 将查询到的商品信息对象封装为列表返回
List<EsProduct> searchProductList =
searchHits.stream()
.map(SearchHit::getContent)
.collect(Collectors.toList());
return new PageImpl<>(searchProductList, pageable, searchHits.getTotalHits());
}
return new PageImpl<>(ListUtil.empty());
}

@Override
public EsProductRelatedInfo searchRelatedInfo(String keyword)
{
// 获取NativeSearchQueryBuilder
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
//搜索条件
if(StrUtil.isEmpty(keyword)){
// 如果关键词为空,就查询所有
nativeSearchQueryBuilder.withQuery(QueryBuilders.matchAllQuery());
} else{
// 进行多字段查询
nativeSearchQueryBuilder.withQuery(QueryBuilders.multiMatchQuery(keyword,"name", "subTitle", "keywords"));
}
//聚合搜索品牌名称
nativeSearchQueryBuilder.withAggregations(AggregationBuilders.terms("brandNames")
.field("brandName"))
//聚合搜索分类名称
.withAggregations(AggregationBuilders.terms("productCategoryNames")
.field("productCategoryName"));
//聚合搜索商品属性,去除type=1的属性
NestedAggregationBuilder nestedAggregationBuilder =
AggregationBuilders
.nested("allAttrValues", "attrValueList") // 对attrValueList进行聚合查询
// 子聚合
.subAggregation(AggregationBuilders
.filter("productAttrs", QueryBuilders.termQuery("attrValueList.type",1)) // 添加过滤器,取出type=1的attrValue
.subAggregation(AggregationBuilders.terms("attrIds").field("attrValueList.productAttributeId")
.subAggregation(AggregationBuilders.terms("attrValues").field("attrValueList.value"))
.subAggregation(AggregationBuilders.terms("attrNames").field("attrValueList.name"))));
// 针对前面子聚合,实际上是按这样一种方式聚合
// "aggregations": { "attrIds": { "aggregations": { "attrValues": {}, "attrNames": {} } } }
nativeSearchQueryBuilder.withAggregations(nestedAggregationBuilder);
// 构建NativeSearchQuery对象
NativeSearchQuery nativeSearchQuery = nativeSearchQueryBuilder.build();
LOGGER.info("searchRelatedInfoSub:DSL = {}", Objects.requireNonNull(nativeSearchQuery.getQuery()));
SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(nativeSearchQuery, EsProduct.class);
return convertProductRelatedInfo(searchHits);
}

/**
* 将返回结果转换为对象
*/
private EsProductRelatedInfo convertProductRelatedInfo(SearchHits<EsProduct> response)
{
// 创建EsProductRelatedInfo对象
EsProductRelatedInfo productRelatedInfo = new EsProductRelatedInfo();
// 将hits中的aggregations转换为map对象
Map<String, Aggregation> aggregationMap = ((Aggregations) Objects
.requireNonNull(response.getAggregations())
.aggregations())
.asMap();
//设置品牌
Terms brandNames = (Terms) aggregationMap.get("brandNames");
List<String> brandNameList = new ArrayList<>();
brandNames.getBuckets()
.forEach(brandName -> brandNameList.add(brandName.getKeyAsString()));
productRelatedInfo.setBrandNames(brandNameList);

//设置分类
Terms productCategoryNames = (Terms) aggregationMap.get("productCategoryNames");
List<String> productCategoryNameList = new ArrayList<>();
productCategoryNames.getBuckets()
.forEach(productCategoryName ->
productCategoryNameList
.add(productCategoryName.getKeyAsString()));
productRelatedInfo.setProductCategoryNames(productCategoryNameList);

// 获取nested
ParsedNested allAttrValues = (ParsedNested) aggregationMap.get("allAttrValues");
// 获取filter
ParsedFilter productAttrs = allAttrValues.getAggregations().get("productAttrs");
// 按照字段类型获取获取terms,attrId为Long类型
ParsedLongTerms attrIds = productAttrs.getAggregations().get("attrIds");
LOGGER.info("attrIds = {}", attrIds);
// 处理子聚合返回结果,构建为内部类对象
// 针对前面子聚合,实际上是按这样一种方式聚合
// "aggregations": { "attrIds": { "aggregations": { "attrValues": {}, "attrNames": {} } } }
List<EsProductRelatedInfo.ProductAttr> productAttrList = new ArrayList<>();
attrIds.getBuckets().forEach(attrId -> {
EsProductRelatedInfo.ProductAttr productAttr = new EsProductRelatedInfo.ProductAttr();
productAttr.setAttrId(Long.valueOf(attrId.getKey().toString()));
ParsedStringTerms attrNames = attrId.getAggregations().get("attrNames");
productAttr.setAttrName(Objects.requireNonNull(attrNames.getBuckets())
.get(0)
.getKeyAsString());
ParsedStringTerms attrValues = attrId.getAggregations().get("attrValues");
List<String> attrValueList =
attrValues.getBuckets()
.stream()
.map((MultiBucketsAggregation.Bucket::getKeyAsString))
.collect(Collectors.toList());
productAttr.setAttrValues(attrValueList);
productAttrList.add(productAttr);
});
productRelatedInfo.setProductAttrs(productAttrList);
return productRelatedInfo;
}
}

mall-security模块

pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<dependencies>
<!--mall工具类及通用模块-->
<dependency>
<groupId>com.macro.mall</groupId>
<artifactId>mall-common</artifactId>
</dependency>
<!--SpringBoot启动相关依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--SpringSecurity依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!--redis依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--jwt依赖-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
</dependency>
</dependencies>

包结构

1
2
3
4
5
6
7
8
9
10
mall-security
└─com
└─macro
└─mall
└─security
├─annotation
├─aspect
├─component
├─config
└─util

mall-security模块的包都统一放在com.macro.mall.security包下

  • annotation包中存放了自定义缓存异常注解

  • aspect包中存放了Redis缓存切面

  • component包中存放了权限相关处理器和JWT过滤器

  • config包中存放了一些配置类

  • util包中存放了一些工具类

主要代码分析

自定义缓存异常注解

1
2
3
4
5
6
7
/**
* 自定义缓存异常注解,有该注解的缓存方法会抛出异常
*/
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CacheException {}

Redis缓存切面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Redis缓存切面,防止Redis宕机影响正常业务逻辑
*/
@Aspect
@Component
@Order(2)
public class RedisCacheAspect
{
private static final Logger LOGGER = LoggerFactory.getLogger(RedisCacheAspect.class);

@Pointcut("execution(public * com.macro.mall.portal.service.*CacheService.*(..)) || execution(public * com.macro.mall.service.*CacheService.*(..))")
public void cacheAspect(){}

@Around("cacheAspect()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable
{
// 获取签名
Signature signature = joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
// 获取目标方法
Method method = methodSignature.getMethod();
Object result = null;
try{
// 目标方法执行
result = joinPoint.proceed();
} catch(Throwable throwable){
//有CacheException注解的方法需要抛出异常
if(method.isAnnotationPresent(CacheException.class)){
throw throwable;
} else{
LOGGER.error(throwable.getMessage());
}
}
return result;
}
}

mall-admin模块

数据库表前缀说明

  • *cms_:内容管理模块相关表
  • *oms_:订单管理模块相关表
  • *pms_:商品模块相关表
  • *sms_:营销模块相关表
  • *ums_:会员模块相关表

pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<dependencies>
<!--mall中MBG生成模块-->
<dependency>
<groupId>com.macro.mall</groupId>
<artifactId>mall-mbg</artifactId>
</dependency>
<!--mall安全模块-->
<dependency>
<groupId>com.macro.mall</groupId>
<artifactId>mall-security</artifactId>
</dependency>
<!-- 阿里云OSS -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
</dependency>
<!--MinIO JAVA SDK-->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
</dependency>
</dependencies>

包结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mall-admin
├─java
│ └─com
│ └─macro
│ └─mall
│ ├─bo
│ ├─config
│ ├─controller
│ ├─dao
│ ├─dto
│ ├─service
│ │ └─impl
│ └─validator
└─resources
├─dao
└─META-INF

mall-admin模块的包都统一放在com.macro.mall包下

  • bo包中存放了SpringSecurity需要的用户信息封装类
  • config包中存放了一些配置类
  • controller包中存放了后台管理相关接口类
  • service包中存放了后台管理相关业务类
  • dao包中存放了一些自定义DAO
  • dto包中存放了一些后台管理相关DTO
  • validator包中存放了状态校验器类
  • resources目录中dao文件夹下存放了dao包中对应的xml文件

主要代码分析

后台用户模块相关表分析,ums_admin*

my_ums_admin
ums_admin相关表分析

其中ums_permission(后台用户权限表)、ums_admin_permission_relation(后台用户和权限关系表(除角色中定义的权限以外的加减权限))和ums_role_permission_relation(后台用户角色和权限关系表)三张表已弃用

  • ums_admin表为后台用户信息表
  • ums_admin_login_log表为后台用户登录日志表,其中admin_id字段ums_admin表的外键
  • ums_role表为后台用户角色表
  • ums_admin_role_relation表为后台用户和角色关系表,其中admin_id字段为ums_admin表的外键,role_id字段为ums_role表的外键
  • ums_menu表为后台菜单表,其中parent_id为自身的外键,表示父级id
  • ums_role_menu_relation表为后台角色菜单关系表,其中role_id字段为ums_role表的外键,menu_id字段为ums_menu表的外键
  • ums_resource_category表为资源分类表
  • ums_resource表为后台资源表,其中category_id字段为ums_resource_category表的外键
  • ums_role_resource_relation表为后台角色资源关系表,其中role_id字段为ums_role表的外键,resource_id字段为表ums_resource表的外键

后台用户相关接口设计

UmsAdminController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* 后台用户管理Controller
*/
@Controller
@Api(tags = "UmsAdminController")
@Tag(name = "UmsAdminController", description = "后台用户管理")
@RequestMapping("/admin")
public class UmsAdminController
{
// Authorization #JWT存储的请求头
@Value("${jwt.tokenHeader}")
private String tokenHeader;
// 'Bearer ' #JWT负载中拿到开头
@Value("${jwt.tokenHead}")
private String tokenHead;
@Resource
private UmsAdminService adminService;
@Resource
private UmsRoleService roleService;

@ApiOperation(value = "用户注册")
@RequestMapping(value = "/register", method = RequestMethod.POST)
@ResponseBody
// @Validated 注解式参数校验
public CommonResult<UmsAdmin> register(@Validated @RequestBody UmsAdminParam umsAdminParam)
{
UmsAdmin umsAdmin = adminService.register(umsAdminParam);
if(umsAdmin == null){
return CommonResult.failed();
}
return CommonResult.success(umsAdmin);
}

@ApiOperation(value = "登录以后返回token")
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public CommonResult login(@Validated @RequestBody UmsAdminLoginParam umsAdminLoginParam)
{
String token = adminService.login(umsAdminLoginParam.getUsername(), umsAdminLoginParam.getPassword());
if(token == null){
return CommonResult.validateFailed("用户名或密码错误");
}
Map<String, String> tokenMap = new HashMap<>();
tokenMap.put("token", token);
tokenMap.put("tokenHead", tokenHead);
return CommonResult.success(tokenMap);
}

@ApiOperation(value = "刷新token")
@RequestMapping(value = "/refreshToken", method = RequestMethod.GET)
@ResponseBody
public CommonResult refreshToken(HttpServletRequest request)
{
// 获取连接中的token
String token = request.getHeader(tokenHeader);
// 刷新之后的token
String refreshToken = adminService.refreshToken(token);
if(refreshToken == null){
return CommonResult.failed("token已经过期!");
}
Map<String, String> tokenMap = new HashMap<>();
tokenMap.put("token", refreshToken);
tokenMap.put("tokenHead", tokenHead);
return CommonResult.success(tokenMap);
}

@ApiOperation(value = "获取当前登录用户信息")
@RequestMapping(value = "/info", method = RequestMethod.GET)
@ResponseBody
// Principal此接口表示主体的抽象概念,它可以用来表示任何实体,例如,个人、公司或登录id
public CommonResult getAdminInfo(Principal principal)
{
// 表示未登录
if(principal == null){
return CommonResult.unauthorized(null);
}
// 返回此主题的名称
String username = principal.getName();
UmsAdmin umsAdmin = adminService.getAdminByUsername(username);
// 将相关用户信息存入map
Map<String, Object> data = new HashMap<>();
data.put("username", umsAdmin.getUsername());
data.put("menus", roleService.getMenuList(umsAdmin.getId()));
data.put("icon", umsAdmin.getIcon());
// 获取用户权限列表
List<UmsRole> roleList = adminService.getRoleList(umsAdmin.getId());
if(CollUtil.isNotEmpty(roleList)){
List<String> roles = roleList.stream()
.map(UmsRole::getName)
.collect(Collectors.toList());
data.put("roles", roles);
}
return CommonResult.success(data);
}

@ApiOperation(value = "登出功能")
@RequestMapping(value = "/logout", method = RequestMethod.POST)
@ResponseBody
public CommonResult logout()
{
return CommonResult.success(null);
}

@ApiOperation("根据用户名或姓名分页获取用户列表")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
// required 是否为必要参数 false
// defaultValue 默认参数
public CommonResult<CommonPage<UmsAdmin>> list(@RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
// TODO 这里是用从数据库中使用模糊查询获得的,或许可以改用Elasticsearch
List<UmsAdmin> adminList = adminService.list(keyword, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(adminList));
}

@ApiOperation("获取指定用户信息")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
// @PathVariable 映射URL绑定的占位符,当方法参数名称与url中的变量名称一致时,可以简写
public CommonResult<UmsAdmin> getItem(@PathVariable Long id)
{
UmsAdmin admin = adminService.getItem(id);
return CommonResult.success(admin);
}

@ApiOperation("修改指定用户信息")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody UmsAdmin admin)
{
int count = adminService.update(id, admin);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改指定用户密码")
@RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
@ResponseBody
public CommonResult updatePassword(@Validated @RequestBody UpdateAdminPasswordParam updatePasswordParam)
{
int status = adminService.updatePassword(updatePasswordParam);
if(status == 1){
return CommonResult.success(status);
} else if(status == -1){
return CommonResult.failed("提交参数不合法");
} else if(status == -2){
return CommonResult.failed("找不到该用户");
} else if(status == -3){
return CommonResult.failed("旧密码错误");
} else{
return CommonResult.failed("其他错误");
}
}

@ApiOperation("删除指定用户信息")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id)
{
int count = adminService.delete(id);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改帐号状态")
@RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateStatus(@PathVariable Long id, @RequestParam(value = "status") Integer status)
{
UmsAdmin umsAdmin = new UmsAdmin();
umsAdmin.setStatus(status);
int count = adminService.update(id, umsAdmin);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("给用户分配角色")
@RequestMapping(value = "/role/update", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateRole(@RequestParam("adminId") Long adminId, @RequestParam("roleIds") List<Long> roleIds)
{
int count = adminService.updateRole(adminId, roleIds);
if(count >= 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("获取指定用户的角色")
@RequestMapping(value = "/role/{adminId}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<UmsRole>> getRoleList(@PathVariable Long adminId)
{
List<UmsRole> roleList = adminService.getRoleList(adminId);
return CommonResult.success(roleList);
}
}
UmsAdminService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* 后台用户管理Service
*/
public interface UmsAdminService
{
/**
* 根据用户名获取后台管理员
*/
UmsAdmin getAdminByUsername(String username);

/**
* 注册功能
*/
UmsAdmin register(UmsAdminParam umsAdminParam);

/**
* 登录功能
* @param username 用户名
* @param password 密码
* @return 生成的JWT的token
*/
String login(String username, String password);

/**
* 刷新token的功能
* @param oldToken 旧的token
*/
String refreshToken(String oldToken);

/**
* 根据用户id获取用户
*/
UmsAdmin getItem(Long id);

/**
* 根据用户名或昵称分页查询用户
*/
List<UmsAdmin> list(String keyword, Integer pageSize, Integer pageNum);

/**
* 修改指定用户信息
*/
int update(Long id, UmsAdmin admin);

/**
* 删除指定用户
*/
int delete(Long id);

/**
* 修改用户角色关系
*/
@Transactional
int updateRole(Long adminId, List<Long> roleIds);

/**
* 获取用户对应角色
*/
List<UmsRole> getRoleList(Long adminId);

/**
* 获取指定用户的可访问资源
*/
List<UmsResource> getResourceList(Long adminId);

/**
* 修改密码
*/
int updatePassword(UpdateAdminPasswordParam updatePasswordParam);

/**
* 获取用户信息
*/
UserDetails loadUserByUsername(String username);

/**
* 获取缓存服务
*/
UmsAdminCacheService getCacheService();
}
UmsAdminServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/**
* 后台用户管理Service实现类
*/
@Service
public class UmsAdminServiceImpl implements UmsAdminService
{
private static final Logger LOGGER = LoggerFactory.getLogger(UmsAdminServiceImpl.class);
@Resource
private JwtTokenUtil jwtTokenUtil;
@Resource
private PasswordEncoder passwordEncoder;
@Resource
private UmsAdminMapper adminMapper;
@Resource
private UmsAdminRoleRelationMapper adminRoleRelationMapper;
@Resource
private UmsAdminRoleRelationDao adminRoleRelationDao;
@Resource
private UmsAdminLoginLogMapper loginLogMapper;

@Override
public UmsAdmin getAdminByUsername(String username)
{
// 获取缓存中的后台用户信息
UmsAdmin admin = getCacheService().getAdmin(username);
if(admin != null) return admin;
// 从数据库中获取用户信息
UmsAdminExample example = new UmsAdminExample();
example.createCriteria().andUsernameEqualTo(username);
List<UmsAdmin> adminList = adminMapper.selectByExample(example);
if(CollUtil.isNotEmpty(adminList)){
// 获取用户信息并存入缓存
admin = adminList.get(0);
getCacheService().setAdmin(admin);
return admin;
}
return null;
}

@Override
public UmsAdmin register(UmsAdminParam umsAdminParam)
{
UmsAdmin umsAdmin = new UmsAdmin();
// 将给定源umsAdminParam的属性值复制到目标Bean umsAdmin中
BeanUtils.copyProperties(umsAdminParam, umsAdmin);
// 启用账户
umsAdmin.setCreateTime(new Date());
umsAdmin.setStatus(1);
//查询是否有相同用户名的用户
UmsAdminExample example = new UmsAdminExample();
example.createCriteria().andUsernameEqualTo(umsAdmin.getUsername());
List<UmsAdmin> umsAdminList = adminMapper.selectByExample(example);
// 数据库中有相同用户名的用户
if(umsAdminList.size() > 0){
return null;
}
//将密码进行加密操作
String encodePassword = passwordEncoder.encode(umsAdmin.getPassword());
umsAdmin.setPassword(encodePassword);
adminMapper.insert(umsAdmin);
return umsAdmin;
}

@Override
public String login(String username, String password)
{
String token = null;
//密码需要客户端加密后传递
try{
UserDetails userDetails = loadUserByUsername(username);
// 抛出异常后,全局异常处理类GlobalExceptionHandler中处理
if(!passwordEncoder.matches(password, userDetails.getPassword())){
Asserts.fail("密码不正确");
}
if(!userDetails.isEnabled()){
Asserts.fail("帐号已被禁用");
}
// 构造authentication,并且该构造函数自动将该用户设为已验证
UsernamePasswordAuthenticationToken authentication =
new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
// 将authentication存入SecurityContextHolder,方便后续调用
SecurityContextHolder.getContext().setAuthentication(authentication);
// 生成token
token = jwtTokenUtil.generateToken(userDetails);
// updateLoginTimeByUsername(username);
// 添加登录记录
insertLoginLog(username);
} catch(AuthenticationException e){
LOGGER.warn("登录异常:{}", e.getMessage());
}
return token;
}

/**
* 添加登录记录
* @param username 用户名
*/
private void insertLoginLog(String username)
{
UmsAdmin admin = getAdminByUsername(username);
if(admin == null) return;
UmsAdminLoginLog loginLog = new UmsAdminLoginLog();
loginLog.setAdminId(admin.getId());
loginLog.setCreateTime(new Date());
// 获取登录ip
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = Objects.requireNonNull(attributes).getRequest();
loginLog.setIp(RequestUtil.getRequestIp(request));
loginLogMapper.insert(loginLog);
}

/**
* 根据用户名修改登录时间
*/
private void updateLoginTimeByUsername(String username)
{
UmsAdmin record = new UmsAdmin();
record.setLoginTime(new Date());
UmsAdminExample example = new UmsAdminExample();
example.createCriteria().andUsernameEqualTo(username);
adminMapper.updateByExampleSelective(record, example);
}

@Override
public String refreshToken(String oldToken)
{
return jwtTokenUtil.refreshHeadToken(oldToken);
}

@Override
public UmsAdmin getItem(Long id)
{
return adminMapper.selectByPrimaryKey(id);
}

@Override
public List<UmsAdmin> list(String keyword, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
UmsAdminExample example = new UmsAdminExample();
UmsAdminExample.Criteria criteria = example.createCriteria();
if(!StrUtil.isEmpty(keyword)){
// 如果关键字不为空,则模糊查询用户名或昵称
criteria.andUsernameLike("%" + keyword + "%");
example.or(example.createCriteria().andNickNameLike("%" + keyword + "%"));
}
// 如果关键字为空,则查询所有
return adminMapper.selectByExample(example);
}

@Override
public int update(Long id, UmsAdmin admin)
{
admin.setId(id);
// 根据id获取数据库中的用户信息
UmsAdmin rawAdmin = adminMapper.selectByPrimaryKey(id);
if(rawAdmin.getPassword().equals(admin.getPassword()) || StrUtil.isEmpty(admin.getPassword())){
//与原加密密码相同的不需要修改
admin.setPassword(null);
} else{
//与原加密密码不同的需要加密修改
admin.setPassword(passwordEncoder.encode(admin.getPassword()));
}
int count = adminMapper.updateByPrimaryKeySelective(admin);
// 用户信息已修改,删除缓存中的该id用户信息
getCacheService().delAdmin(id);
return count;
}

@Override
public int delete(Long id)
{
// 删除缓存中的用户信息
getCacheService().delAdmin(id);
int count = adminMapper.deleteByPrimaryKey(id);
// 删除用户资源列表缓存
getCacheService().delResourceList(id);
return count;
}

@Override
public int updateRole(Long adminId, List<Long> roleIds)
{
int count = roleIds == null ? 0 : roleIds.size();
// 当count等于0有两种情况,一是什么都不添加,而是取消原来所有权限
// 先删除原来的关系
UmsAdminRoleRelationExample adminRoleRelationExample = new UmsAdminRoleRelationExample();
adminRoleRelationExample.createCriteria().andAdminIdEqualTo(adminId);
adminRoleRelationMapper.deleteByExample(adminRoleRelationExample);
//建立新关系
if(!CollectionUtils.isEmpty(roleIds)){
List<UmsAdminRoleRelation> list = new ArrayList<>();
roleIds.forEach(roleId -> {
UmsAdminRoleRelation roleRelation = new UmsAdminRoleRelation();
roleRelation.setAdminId(adminId);
roleRelation.setRoleId(roleId);
list.add(roleRelation);
});
adminRoleRelationDao.insertList(list);
}
// 删除旧用户资源列表缓存
getCacheService().delResourceList(adminId);
return count;
}

@Override
public List<UmsRole> getRoleList(Long adminId)
{
return adminRoleRelationDao.getRoleList(adminId);
}

@Override
public List<UmsResource> getResourceList(Long adminId)
{
List<UmsResource> resourceList = getCacheService().getResourceList(adminId);
if(CollUtil.isNotEmpty(resourceList)){
return resourceList;
}
resourceList = adminRoleRelationDao.getResourceList(adminId);
if(CollUtil.isNotEmpty(resourceList)){
getCacheService().setResourceList(adminId, resourceList);
}
return resourceList;
}

@Override
public int updatePassword(UpdateAdminPasswordParam param)
{
// 虽然接口参数加上了@Validated,但是这@NotNull只能检验参数不为null
if(StrUtil.isEmpty(param.getUsername()) || StrUtil.isEmpty(param.getOldPassword()) || StrUtil
.isEmpty(param.getNewPassword())){
return -1;
}
// 根据用户名获取用户信息
UmsAdminExample example = new UmsAdminExample();
example.createCriteria().andUsernameEqualTo(param.getUsername());
List<UmsAdmin> adminList = adminMapper.selectByExample(example);
if(CollUtil.isEmpty(adminList)){
return -2;
}
UmsAdmin umsAdmin = adminList.get(0);
// 如果旧密码不匹配
if(!passwordEncoder.matches(param.getOldPassword(), umsAdmin.getPassword())){
return -3;
}
// 设置新密码
umsAdmin.setPassword(passwordEncoder.encode(param.getNewPassword()));
adminMapper.updateByPrimaryKey(umsAdmin);
// 删除缓存中的旧用户信息
getCacheService().delAdmin(umsAdmin.getId());
return 1;
}

@Override
public UserDetails loadUserByUsername(String username)
{
//获取用户信息
UmsAdmin admin = getAdminByUsername(username);
if(admin != null){
List<UmsResource> resourceList = getResourceList(admin.getId());
return new AdminUserDetails(admin, resourceList);
}
throw new UsernameNotFoundException("用户名或密码错误");
}

@Override
public UmsAdminCacheService getCacheService()
{
return SpringUtil.getBean(UmsAdminCacheService.class);
}
}
UmsRoleController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* 后台用户角色管理Controller
*/
@Controller
@Api(tags = "UmsRoleController")
@Tag(name = "UmsRoleController", description = "后台用户角色管理")
@RequestMapping("/role")
public class UmsRoleController
{
@Resource
private UmsRoleService roleService;

@ApiOperation("添加角色")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody UmsRole role)
{
int count = roleService.create(role);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改角色")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody UmsRole role)
{
int count = roleService.update(id, role);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("批量删除角色")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("ids") List<Long> ids)
{
int count = roleService.delete(ids);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("获取所有角色")
@RequestMapping(value = "/listAll", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<UmsRole>> listAll()
{
List<UmsRole> roleList = roleService.list();
return CommonResult.success(roleList);
}

@ApiOperation("根据角色名称分页获取角色列表")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<UmsRole>> list(@RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<UmsRole> roleList = roleService.list(keyword, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(roleList));
}

@ApiOperation("修改角色状态")
@RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateStatus(@PathVariable Long id, @RequestParam(value = "status") Integer status)
{
UmsRole umsRole = new UmsRole();
umsRole.setStatus(status);
int count = roleService.update(id, umsRole);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("获取角色相关菜单")
@RequestMapping(value = "/listMenu/{roleId}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<UmsMenu>> listMenu(@PathVariable Long roleId)
{
List<UmsMenu> roleList = roleService.listMenu(roleId);
return CommonResult.success(roleList);
}

@ApiOperation("获取角色相关资源")
@RequestMapping(value = "/listResource/{roleId}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<UmsResource>> listResource(@PathVariable Long roleId)
{
List<UmsResource> roleList = roleService.listResource(roleId);
return CommonResult.success(roleList);
}

@ApiOperation("给角色分配菜单")
@RequestMapping(value = "/allocMenu", method = RequestMethod.POST)
@ResponseBody
public CommonResult allocMenu(@RequestParam Long roleId, @RequestParam List<Long> menuIds)
{
int count = roleService.allocMenu(roleId, menuIds);
return CommonResult.success(count);
}

@ApiOperation("给角色分配资源")
@RequestMapping(value = "/allocResource", method = RequestMethod.POST)
@ResponseBody
public CommonResult allocResource(@RequestParam Long roleId, @RequestParam List<Long> resourceIds)
{
int count = roleService.allocResource(roleId, resourceIds);
return CommonResult.success(count);
}
}
UmsRoleService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* 后台角色管理Service
*/
public interface UmsRoleService
{
/**
* 添加角色
*/
int create(UmsRole role);

/**
* 修改角色信息
*/
int update(Long id, UmsRole role);

/**
* 批量删除角色
*/
int delete(List<Long> ids);

/**
* 获取所有角色列表
*/
List<UmsRole> list();

/**
* 分页获取角色列表
*/
List<UmsRole> list(String keyword, Integer pageSize, Integer pageNum);

/**
* 根据管理员ID获取对应菜单
*/
List<UmsMenu> getMenuList(Long adminId);

/**
* 获取角色相关菜单
*/
List<UmsMenu> listMenu(Long roleId);

/**
* 获取角色相关资源
*/
List<UmsResource> listResource(Long roleId);

/**
* 给角色分配菜单
*/
@Transactional
int allocMenu(Long roleId, List<Long> menuIds);

/**
* 给角色分配资源
*/
@Transactional
int allocResource(Long roleId, List<Long> resourceIds);
}
UmsRoleServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* 后台角色管理Service实现类
*/
@Service
public class UmsRoleServiceImpl implements UmsRoleService
{
@Resource
private UmsRoleMapper roleMapper;
@Resource
private UmsRoleMenuRelationMapper roleMenuRelationMapper;
@Resource
private UmsRoleResourceRelationMapper roleResourceRelationMapper;
@Resource
private UmsRoleDao roleDao;
@Resource
private UmsAdminCacheService adminCacheService;

@Override
public int create(UmsRole role)
{
role.setCreateTime(new Date());
role.setAdminCount(0);
role.setSort(0);
return roleMapper.insert(role);
}

@Override
public int update(Long id, UmsRole role)
{
role.setId(id);
return roleMapper.updateByPrimaryKeySelective(role);
}

@Override
public int delete(List<Long> ids)
{
// 没有校验参数ids,但是andIdIn(ids)内部会判断value为空会抛出异常
UmsRoleExample example = new UmsRoleExample();
example.createCriteria().andIdIn(ids);
int count = roleMapper.deleteByExample(example);
adminCacheService.delResourceListByRoleIds(ids);
return count;
}

@Override
public List<UmsRole> list()
{
return roleMapper.selectByExample(new UmsRoleExample());
}

@Override
public List<UmsRole> list(String keyword, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
UmsRoleExample example = new UmsRoleExample();
if(!StrUtil.isEmpty(keyword)){
example.createCriteria().andNameLike("%" + keyword + "%");
}
return roleMapper.selectByExample(example);
}

@Override
public List<UmsMenu> getMenuList(Long adminId)
{
return roleDao.getMenuList(adminId);
}

@Override
public List<UmsMenu> listMenu(Long roleId)
{
return roleDao.getMenuListByRoleId(roleId);
}

@Override
public List<UmsResource> listResource(Long roleId)
{
return roleDao.getResourceListByRoleId(roleId);
}

@Override
public int allocMenu(Long roleId, List<Long> menuIds)
{
//先删除原有关系
UmsRoleMenuRelationExample example = new UmsRoleMenuRelationExample();
example.createCriteria().andRoleIdEqualTo(roleId);
roleMenuRelationMapper.deleteByExample(example);
//批量插入新关系
menuIds.forEach(menuId -> {
UmsRoleMenuRelation relation = new UmsRoleMenuRelation();
relation.setRoleId(roleId);
relation.setMenuId(menuId);
roleMenuRelationMapper.insert(relation);
});
return menuIds.size();
}

@Override
public int allocResource(Long roleId, List<Long> resourceIds)
{
//先删除原有关系
UmsRoleResourceRelationExample example = new UmsRoleResourceRelationExample();
example.createCriteria().andRoleIdEqualTo(roleId);
roleResourceRelationMapper.deleteByExample(example);
//批量插入新关系
resourceIds.forEach(resourceId -> {
UmsRoleResourceRelation relation = new UmsRoleResourceRelation();
relation.setRoleId(roleId);
relation.setResourceId(resourceId);
roleResourceRelationMapper.insert(relation);
});
// 当角色相关资源信息改变时删除相关后台用户缓存
adminCacheService.delResourceListByRole(roleId);
return resourceIds.size();
}
}
UmsResourceController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* 后台资源管理Controller
*/
@Controller
@Api(tags = "UmsResourceController")
@Tag(name = "UmsResourceController", description = "后台资源管理")
@RequestMapping("/resource")
public class UmsResourceController
{
@Resource
private UmsResourceService resourceService;
@Resource
private DynamicSecurityMetadataSource dynamicSecurityMetadataSource;

@ApiOperation("添加后台资源")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody UmsResource umsResource)
{
int count = resourceService.create(umsResource);
// 清空资源Map
dynamicSecurityMetadataSource.clearDataSource();
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("修改后台资源")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody UmsResource umsResource)
{
int count = resourceService.update(id, umsResource);
dynamicSecurityMetadataSource.clearDataSource();
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("根据ID获取资源详情")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<UmsResource> getItem(@PathVariable Long id)
{
UmsResource umsResource = resourceService.getItem(id);
return CommonResult.success(umsResource);
}

@ApiOperation("根据ID删除后台资源")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id)
{
int count = resourceService.delete(id);
dynamicSecurityMetadataSource.clearDataSource();
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("分页模糊查询后台资源")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<UmsResource>> list(@RequestParam(required = false) Long categoryId,
@RequestParam(required = false) String nameKeyword,
@RequestParam(required = false) String urlKeyword,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<UmsResource> resourceList = resourceService.list(categoryId, nameKeyword, urlKeyword, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(resourceList));
}

@ApiOperation("查询所有后台资源")
@RequestMapping(value = "/listAll", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<UmsResource>> listAll()
{
List<UmsResource> resourceList = resourceService.listAll();
return CommonResult.success(resourceList);
}
}
UmsResourceService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* 后台资源管理Service
*/
public interface UmsResourceService
{
/**
* 添加资源
*/
int create(UmsResource umsResource);

/**
* 修改资源
*/
int update(Long id, UmsResource umsResource);

/**
* 获取资源详情
*/
UmsResource getItem(Long id);

/**
* 删除资源
*/
int delete(Long id);

/**
* 分页查询资源
*/
List<UmsResource> list(Long categoryId, String nameKeyword, String urlKeyword, Integer pageSize, Integer pageNum);

/**
* 查询全部资源
*/
List<UmsResource> listAll();
}
UmsResourceServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* 后台资源管理Service实现类
*/
@Service
public class UmsResourceServiceImpl implements UmsResourceService
{
@Resource
private UmsResourceMapper resourceMapper;
@Resource
private UmsAdminCacheService adminCacheService;

@Override
public int create(UmsResource umsResource)
{
umsResource.setCreateTime(new Date());
return resourceMapper.insert(umsResource);
}

@Override
public int update(Long id, UmsResource umsResource)
{
umsResource.setId(id);
int count = resourceMapper.updateByPrimaryKeySelective(umsResource);
adminCacheService.delResourceListByResource(id);
return count;
}

@Override
public UmsResource getItem(Long id)
{
return resourceMapper.selectByPrimaryKey(id);
}

@Override
public int delete(Long id)
{
int count = resourceMapper.deleteByPrimaryKey(id);
adminCacheService.delResourceListByResource(id);
return count;
}

@Override
public List<UmsResource> list(Long categoryId, String nameKeyword, String urlKeyword, Integer pageSize,
Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
UmsResourceExample example = new UmsResourceExample();
UmsResourceExample.Criteria criteria = example.createCriteria();
if(categoryId != null){
criteria.andCategoryIdEqualTo(categoryId);
}
if(StrUtil.isNotEmpty(nameKeyword)){
criteria.andNameLike('%' + nameKeyword + '%');
}
if(StrUtil.isNotEmpty(urlKeyword)){
criteria.andUrlLike('%' + urlKeyword + '%');
}
return resourceMapper.selectByExample(example);
}

@Override
public List<UmsResource> listAll()
{
return resourceMapper.selectByExample(new UmsResourceExample());
}
}
DynamicSecurityMetadataSource
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* 动态权限数据源,用于获取动态权限规则
*/
public class DynamicSecurityMetadataSource implements FilterInvocationSecurityMetadataSource
{
private static final Logger LOGGER = LoggerFactory.getLogger(DynamicSecurityMetadataSource.class);
private static Map<String, ConfigAttribute> configAttributeMap = null;
@Autowired
private DynamicSecurityService dynamicSecurityService;

// 被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器执行一次
// 加载用户权限
@PostConstruct
public void loadDataSource()
{
configAttributeMap = dynamicSecurityService.loadDataSource();
}

public void clearDataSource()
{
configAttributeMap.clear();
configAttributeMap = null;
}

@Override
public Collection<ConfigAttribute> getAttributes(Object o) throws IllegalArgumentException
{
// 加载资源ANT通配符和资源对应MAP
if(configAttributeMap == null) this.loadDataSource();
//获取当前访问的路径
String url = ((FilterInvocation) o).getRequestUrl();
String path = URLUtil.getPath(url);
PathMatcher pathMatcher = new AntPathMatcher();
//获取访问该路径所需资源
List<ConfigAttribute> configAttributes = configAttributeMap
.keySet()
.stream()
.filter(pattern -> pathMatcher.match(pattern, path))
.map(pattern -> configAttributeMap.get(pattern))
.collect(Collectors.toList());

// TODO 打印configAttributes日志
LOGGER.info("DynamicSecurityMetadataSource configAttributes = {}, url = {}", configAttributes, url);
// 未设置操作请求权限,返回空集合
return configAttributes;
}

@Override
public Collection<ConfigAttribute> getAllConfigAttributes()
{
return null;
}

@Override
public boolean supports(Class<?> aClass)
{
return true;
}
}
UmsResourceCategoryController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* 后台资源分类管理Controller
*/
@Controller
@Api(tags = "UmsResourceCategoryController")
@Tag(name = "UmsResourceCategoryController", description = "后台资源分类管理")
@RequestMapping("/resourceCategory")
public class UmsResourceCategoryController
{
@Resource
private UmsResourceCategoryService resourceCategoryService;

@ApiOperation("查询所有后台资源分类")
@RequestMapping(value = "/listAll", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<UmsResourceCategory>> listAll()
{
List<UmsResourceCategory> resourceList = resourceCategoryService.listAll();
return CommonResult.success(resourceList);
}

@ApiOperation("添加后台资源分类")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody UmsResourceCategory umsResourceCategory)
{
int count = resourceCategoryService.create(umsResourceCategory);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("修改后台资源分类")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody UmsResourceCategory umsResourceCategory)
{
int count = resourceCategoryService.update(id, umsResourceCategory);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("根据ID删除后台资源")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id)
{
int count = resourceCategoryService.delete(id);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}
}
UmsResourceCategoryService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**
* 后台资源分类管理Service
*/
public interface UmsResourceCategoryService
{

/**
* 获取所有资源分类
*/
List<UmsResourceCategory> listAll();

/**
* 创建资源分类
*/
int create(UmsResourceCategory umsResourceCategory);

/**
* 修改资源分类
*/
int update(Long id, UmsResourceCategory umsResourceCategory);

/**
* 删除资源分类
*/
int delete(Long id);
}
UmsResourceCategoryServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* 后台资源分类管理Service实现类
*/
@Service
public class UmsResourceCategoryServiceImpl implements UmsResourceCategoryService
{
@Resource
private UmsResourceCategoryMapper resourceCategoryMapper;

@Override
public List<UmsResourceCategory> listAll()
{
UmsResourceCategoryExample example = new UmsResourceCategoryExample();
example.setOrderByClause("sort desc");
return resourceCategoryMapper.selectByExample(example);
}

@Override
public int create(UmsResourceCategory umsResourceCategory)
{
umsResourceCategory.setCreateTime(new Date());
return resourceCategoryMapper.insert(umsResourceCategory);
}

@Override
public int update(Long id, UmsResourceCategory umsResourceCategory)
{
umsResourceCategory.setId(id);
return resourceCategoryMapper.updateByPrimaryKeySelective(umsResourceCategory);
}

@Override
public int delete(Long id)
{
return resourceCategoryMapper.deleteByPrimaryKey(id);
}
}
UmsMenuController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* 后台菜单管理Controller
*/
@Controller
@Api(tags = "UmsMenuController")
@Tag(name = "UmsMenuController", description = "后台菜单管理")
@RequestMapping("/menu")
public class UmsMenuController
{
@Resource
private UmsMenuService menuService;

@ApiOperation("添加后台菜单")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody UmsMenu umsMenu)
{
int count = menuService.create(umsMenu);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("修改后台菜单")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody UmsMenu umsMenu)
{
int count = menuService.update(id, umsMenu);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("根据ID获取菜单详情")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<UmsMenu> getItem(@PathVariable Long id)
{
UmsMenu umsMenu = menuService.getItem(id);
return CommonResult.success(umsMenu);
}

@ApiOperation("根据ID删除后台菜单")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id)
{
int count = menuService.delete(id);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("分页查询后台菜单")
@RequestMapping(value = "/list/{parentId}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<UmsMenu>> list(@PathVariable Long parentId,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<UmsMenu> menuList = menuService.list(parentId, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(menuList));
}

@ApiOperation("树形结构返回所有菜单列表")
@RequestMapping(value = "/treeList", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<UmsMenuNode>> treeList()
{
List<UmsMenuNode> list = menuService.treeList();
return CommonResult.success(list);
}

@ApiOperation("修改菜单显示状态")
@RequestMapping(value = "/updateHidden/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateHidden(@PathVariable Long id, @RequestParam("hidden") Integer hidden)
{
int count = menuService.updateHidden(id, hidden);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}
}
UmsMenuService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* 后台菜单管理Service
*/
public interface UmsMenuService
{
/**
* 创建后台菜单
*/
int create(UmsMenu umsMenu);

/**
* 修改后台菜单
*/
int update(Long id, UmsMenu umsMenu);

/**
* 根据ID获取菜单详情
*/
UmsMenu getItem(Long id);

/**
* 根据ID删除菜单
*/
int delete(Long id);

/**
* 分页查询后台菜单
*/
List<UmsMenu> list(Long parentId, Integer pageSize, Integer pageNum);

/**
* 树形结构返回所有菜单列表
*/
List<UmsMenuNode> treeList();

/**
* 修改菜单显示状态
*/
int updateHidden(Long id, Integer hidden);
}
UmsMenuServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* 后台菜单管理Service实现类
*/
@Service
public class UmsMenuServiceImpl implements UmsMenuService
{
@Resource
private UmsMenuMapper menuMapper;

@Override
public int create(UmsMenu umsMenu)
{
umsMenu.setCreateTime(new Date());
updateLevel(umsMenu);
return menuMapper.insert(umsMenu);
}

/**
* 修改菜单层级
*/
private void updateLevel(UmsMenu umsMenu)
{
if(umsMenu.getParentId() == 0){
//没有父菜单时为一级菜单
umsMenu.setLevel(0);
} else{
//有父菜单时选择根据父菜单level设置
UmsMenu parentMenu = menuMapper.selectByPrimaryKey(umsMenu.getParentId());
if(parentMenu != null){
umsMenu.setLevel(parentMenu.getLevel() + 1);
} else{
umsMenu.setLevel(0);
}
}
}

@Override
public int update(Long id, UmsMenu umsMenu)
{
umsMenu.setId(id);
updateLevel(umsMenu);
return menuMapper.updateByPrimaryKeySelective(umsMenu);
}

@Override
public UmsMenu getItem(Long id)
{
return menuMapper.selectByPrimaryKey(id);
}

@Override
public int delete(Long id)
{
return menuMapper.deleteByPrimaryKey(id);
}

@Override
public List<UmsMenu> list(Long parentId, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
UmsMenuExample example = new UmsMenuExample();
example.setOrderByClause("sort desc");
example.createCriteria().andParentIdEqualTo(parentId);
return menuMapper.selectByExample(example);
}

@Override
public List<UmsMenuNode> treeList()
{
// 先查询所有菜单
List<UmsMenu> menuList = menuMapper.selectByExample(new UmsMenuExample());
List<UmsMenuNode> result = menuList.stream()
// 过滤出父级菜单为0的,即为一级菜单
.filter(menu -> menu.getParentId().equals(0L))
.map(menu -> UmsMenuServiceImpl.this.covertMenuNode(menu, menuList))
.collect(Collectors.toList());
return result;
}

@Override
public int updateHidden(Long id, Integer hidden)
{
UmsMenu umsMenu = new UmsMenu();
umsMenu.setId(id);
umsMenu.setHidden(hidden);
return menuMapper.updateByPrimaryKeySelective(umsMenu);
}

/**
* 将UmsMenu转化为UmsMenuNode并设置children属性
*/
private UmsMenuNode covertMenuNode(UmsMenu menu, List<UmsMenu> menuList)
{
UmsMenuNode node = new UmsMenuNode();
BeanUtils.copyProperties(menu, node);
List<UmsMenuNode> children = menuList.stream()
// TODO 过滤出该一级菜单的子级菜单,数据库中最多只有二级菜单
// 如果有多级菜单,下面再次递归调用,就能解决
// 如果过滤条件不满足就结束了
.filter(subMenu -> subMenu.getParentId().equals(menu.getId()))
// 将过滤出来的子级菜单转换为UmsMenuNode
.map(subMenu -> UmsMenuServiceImpl.this.covertMenuNode(subMenu, menuList))
.collect(Collectors.toList());
node.setChildren(children);
return node;
}
}

会员模块相关表分析,ums_member*

my_ums_member
ums_member相关表分析
  • ums_member表为会员表,其中member_level_id字段为表ums_member_level的外键
  • ums_member_level表为会员等级表
  • ums_member_login_log表为会员登录记录表,其中member_id字段为表ums_member的外键
  • ums_member_product_category_relation表为会员与产品分类关系表(用户喜欢的分类),其中member_id字段为表ums_member的外键
  • ums_member_tag表为用户标签表
  • ums_member_member_tag_relation表为用户和标签关系表,其中tag_id字段为ums_member_tag的外键,member_id字段为表ums_member的外键
  • ums_member_statistics_info表为会员统计信息表,其中member_id字段为表ums_member的外键
  • ums_growth_change_history表为成长值变化历史记录表,其中member_id字段为表ums_member的外键
  • ums_integration_change_history表为积分变化历史记录表,其中member_id字段为表ums_member的外键
  • ums_member_task表为会员任务表
  • ums_member_rule_setting表为会员积分成长规则表
  • ums_integration_consume_setting表为积分消费设置表

会员相关接口设计(设计不完整)

UmsMemberLevelController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* 会员等级管理Controller
*/
@Controller
@Api(tags = "UmsMemberLevelController")
@Tag(name = "UmsMemberLevelController", description = "会员等级管理")
@RequestMapping("/memberLevel")
public class UmsMemberLevelController
{
@Resource
private UmsMemberLevelService memberLevelService;

@ApiOperation("查询所有会员等级")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<UmsMemberLevel>> list(@RequestParam("defaultStatus") Integer defaultStatus)
{
List<UmsMemberLevel> memberLevelList = memberLevelService.list(defaultStatus);
return CommonResult.success(memberLevelList);
}
}
UmsMemberLevelService
1
2
3
4
5
6
7
8
9
10
11
12
/**
* 会员等级管理Service
*/
public interface UmsMemberLevelService
{
/**
* 获取所有会员等级
*
* @param defaultStatus 是否为默认会员
*/
List<UmsMemberLevel> list(Integer defaultStatus);
}
UmsMemberLevelServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
* 会员等级管理Service实现类
*/
@Service
public class UmsMemberLevelServiceImpl implements UmsMemberLevelService
{
@Resource
private UmsMemberLevelMapper memberLevelMapper;

@Override
public List<UmsMemberLevel> list(Integer defaultStatus)
{
UmsMemberLevelExample example = new UmsMemberLevelExample();
example.createCriteria().andDefaultStatusEqualTo(defaultStatus);
return memberLevelMapper.selectByExample(example);
}
}

商品模块相关表分析,pms_*

my_ums_pms
pms_*相关表分析
  • pms_product表为商品信息表,其中brand_id字段为表pms_brand的外键、product_category_id字段为表pms_product_category的外键、feight_template_id字段为表pms_feight_template的外键、product_attribute_category_id为表pms_product_attribute_category的外键
  • pms_brand表为品牌表
  • pms_product_category表为产品分类表,其中parent_id字段为自身的外键,表示父级id
  • pms_product_attribute_category表为产品属性分类表
  • pms_feight_template表为运费模版表
  • pms_product_attribute表为商品属性参数表,其中product_attribute_category_id字段为表pms_product_attribute_category的外键
  • pms_product_attribute_value表为存储产品参数信息的表,其中product_id字段为表pms_product的外键、product_attribute_id字段为表pms_product_attribute的外键
  • pms_product_category_attribute_relation表为产品的分类和属性的关系表,用于设置分类筛选条件(只支持一级分类),其中product_category_id为表pms_product_category的外键、product_attribute_id字段为表pms_product_attribute的外键
  • pms_sku_stock表为sku的库存表,其中product_id字段为表pms_product的外键
  • pms_comment表为商品评价表,其中product_id字段为表pms_product的外键
  • pms_comment_replay表为产品评价回复表,其中comment_id字段为表pms_comment的外键
  • pms_product_operate_log表为商品操作日志表,其中product_id字段为表pms_product的外键
  • pms_product_vertify_record表为商品审核记录表,其中product_id字段为表pms_product的外键
  • pms_product_full_reduction表为产品满减表(只针对同商品),其中product_id字段为表pms_product的外键
  • pms_product_ladder表为产品阶梯价格表(只针对同商品),其中product_id字段为表pms_product的外键
  • pms_member_price表为商品会员价格表,其中product_id字段为表pms_product的外键
  • pms_album表为相册表
  • pms_album_pic表为画册图片表,其中album_id字段为表pms_album的外键

商品相关接口设计

PmsProductController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* 商品管理Controller
*/
@Controller
@Api(tags = "PmsProductController")
@Tag(name = "PmsProductController", description = "商品管理")
@RequestMapping("/product")
public class PmsProductController
{
@Resource
private PmsProductService productService;

@ApiOperation("创建商品")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody PmsProductParam productParam)
{
int count = productService.create(productParam);
if(count == 1){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("根据商品id获取商品编辑信息")
@RequestMapping(value = "/updateInfo/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<PmsProductResult> getUpdateInfo(@PathVariable Long id)
{
PmsProductResult productResult = productService.getUpdateInfo(id);
return CommonResult.success(productResult);
}

@ApiOperation("更新商品")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody PmsProductParam productParam)
{
int count = productService.update(id, productParam);
if(count == 1){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("查询商品")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<PmsProduct>> getList(PmsProductQueryParam productQueryParam,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<PmsProduct> productList = productService.list(productQueryParam, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(productList));
}

@ApiOperation("根据商品名称或货号模糊查询")
@RequestMapping(value = "/simpleList", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<PmsProduct>> getList(String keyword)
{
List<PmsProduct> productList = productService.list(keyword);
return CommonResult.success(productList);
}

// TODO 未开发完全
@ApiOperation("批量修改审核状态")
@RequestMapping(value = "/update/verifyStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateVerifyStatus(@RequestParam("ids") List<Long> ids,
@RequestParam("verifyStatus") Integer verifyStatus,
@RequestParam("detail") String detail)
{
int count = productService.updateVerifyStatus(ids, verifyStatus, detail);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("批量上下架商品")
@RequestMapping(value = "/update/publishStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updatePublishStatus(@RequestParam("ids") List<Long> ids,
@RequestParam("publishStatus") Integer publishStatus)
{
int count = productService.updatePublishStatus(ids, publishStatus);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("批量推荐商品")
@RequestMapping(value = "/update/recommendStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateRecommendStatus(@RequestParam("ids") List<Long> ids,
@RequestParam("recommendStatus") Integer recommendStatus)
{
int count = productService.updateRecommendStatus(ids, recommendStatus);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("批量设为新品")
@RequestMapping(value = "/update/newStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateNewStatus(@RequestParam("ids") List<Long> ids,
@RequestParam("newStatus") Integer newStatus)
{
int count = productService.updateNewStatus(ids, newStatus);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("批量修改删除状态")
@RequestMapping(value = "/update/deleteStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateDeleteStatus(@RequestParam("ids") List<Long> ids,
@RequestParam("deleteStatus") Integer deleteStatus)
{
int count = productService.updateDeleteStatus(ids, deleteStatus);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}
}
PmsProductService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* 商品管理Service
*/
public interface PmsProductService
{
/**
* 创建商品
*/
@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
int create(PmsProductParam productParam);

/**
* 根据商品编号获取更新信息
*/
PmsProductResult getUpdateInfo(Long id);

/**
* 更新商品
*/
@Transactional
int update(Long id, PmsProductParam productParam);

/**
* 分页查询商品
*/
List<PmsProduct> list(PmsProductQueryParam productQueryParam, Integer pageSize, Integer pageNum);

/**
* 批量修改审核状态
* @param ids 产品id
* @param verifyStatus 审核状态
* @param detail 审核详情
*/
@Transactional
int updateVerifyStatus(List<Long> ids, Integer verifyStatus, String detail);

/**
* 批量修改商品上架状态
*/
int updatePublishStatus(List<Long> ids, Integer publishStatus);

/**
* 批量修改商品推荐状态
*/
int updateRecommendStatus(List<Long> ids, Integer recommendStatus);

/**
* 批量修改新品状态
*/
int updateNewStatus(List<Long> ids, Integer newStatus);

/**
* 批量删除商品
*/
int updateDeleteStatus(List<Long> ids, Integer deleteStatus);

/**
* 根据商品名称或者货号模糊查询
*/
List<PmsProduct> list(String keyword);
}
PmsProductServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/**
* 商品管理Service实现类
*/
@Service
public class PmsProductServiceImpl implements PmsProductService
{
private static final Logger LOGGER = LoggerFactory.getLogger(PmsProductServiceImpl.class);
@Resource
private PmsProductMapper productMapper;
@Resource
private PmsMemberPriceDao memberPriceDao;
@Resource
private PmsMemberPriceMapper memberPriceMapper;
@Resource
private PmsProductLadderDao productLadderDao;
@Resource
private PmsProductLadderMapper productLadderMapper;
@Resource
private PmsProductFullReductionDao productFullReductionDao;
@Resource
private PmsProductFullReductionMapper productFullReductionMapper;
@Resource
private PmsSkuStockDao skuStockDao;
@Resource
private PmsSkuStockMapper skuStockMapper;
@Resource
private PmsProductAttributeValueDao productAttributeValueDao;
@Resource
private PmsProductAttributeValueMapper productAttributeValueMapper;
@Resource
private CmsSubjectProductRelationDao subjectProductRelationDao;
@Resource
private CmsSubjectProductRelationMapper subjectProductRelationMapper;
@Resource
private CmsPrefrenceAreaProductRelationDao prefrenceAreaProductRelationDao;
@Resource
private CmsPrefrenceAreaProductRelationMapper prefrenceAreaProductRelationMapper;
@Resource
private PmsProductDao productDao;
@Resource
private PmsProductVertifyRecordDao productVertifyRecordDao;

@Override
public int create(PmsProductParam productParam)
{
int count;
//创建商品
PmsProduct product = productParam;
product.setId(null);
productMapper.insertSelective(product);
//根据促销类型设置价格:会员价格、阶梯价格、满减价格
Long productId = product.getId();
//会员价格
relateAndInsertList(memberPriceDao, productParam.getMemberPriceList(), productId);
//阶梯价格
relateAndInsertList(productLadderDao, productParam.getProductLadderList(), productId);
//满减价格
relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), productId);

//处理sku的编码
handleSkuStockCode(productParam.getSkuStockList(), productId);

//添加sku库存信息
relateAndInsertList(skuStockDao, productParam.getSkuStockList(), productId);
//添加商品参数,添加自定义商品规格
relateAndInsertList(productAttributeValueDao, productParam.getProductAttributeValueList(), productId);
//关联专题
relateAndInsertList(subjectProductRelationDao, productParam.getSubjectProductRelationList(), productId);
//关联优选
relateAndInsertList(prefrenceAreaProductRelationDao, productParam.getPrefrenceAreaProductRelationList(), productId);
// 中间如果出错会抛出异常
count = 1;
return count;
}

private void handleSkuStockCode(List<PmsSkuStock> skuStockList, Long productId)
{
if(CollectionUtils.isEmpty(skuStockList)) return;
for(int i = 0; i < skuStockList.size(); i++){
PmsSkuStock skuStock = skuStockList.get(i);
if(StrUtil.isEmpty(skuStock.getSkuCode())){
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
StringBuilder sb = new StringBuilder();
//日期
sb.append(sdf.format(new Date()));
//四位商品id
sb.append(String.format("%04d", productId));
// TODO 三位索引id,索引id有什么用?
sb.append(String.format("%03d", i + 1));
skuStock.setSkuCode(sb.toString());
}
}
}

@Override
public PmsProductResult getUpdateInfo(Long id)
{
return productDao.getUpdateInfo(id);
}

@Override
public int update(Long id, PmsProductParam productParam)
{
int count;
//更新商品信息
PmsProduct product = productParam;
product.setId(id);
productMapper.updateByPrimaryKeySelective(product);
//会员价格
PmsMemberPriceExample pmsMemberPriceExample = new PmsMemberPriceExample();
pmsMemberPriceExample.createCriteria().andProductIdEqualTo(id);
memberPriceMapper.deleteByExample(pmsMemberPriceExample);
relateAndInsertList(memberPriceDao, productParam.getMemberPriceList(), id);
//阶梯价格
PmsProductLadderExample ladderExample = new PmsProductLadderExample();
ladderExample.createCriteria().andProductIdEqualTo(id);
productLadderMapper.deleteByExample(ladderExample);
relateAndInsertList(productLadderDao, productParam.getProductLadderList(), id);
//满减价格
PmsProductFullReductionExample fullReductionExample = new PmsProductFullReductionExample();
fullReductionExample.createCriteria().andProductIdEqualTo(id);
productFullReductionMapper.deleteByExample(fullReductionExample);
relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), id);
//修改sku库存信息
handleUpdateSkuStockList(id, productParam);
//修改商品参数,添加自定义商品规格
PmsProductAttributeValueExample productAttributeValueExample = new PmsProductAttributeValueExample();
productAttributeValueExample.createCriteria().andProductIdEqualTo(id);
productAttributeValueMapper.deleteByExample(productAttributeValueExample);
relateAndInsertList(productAttributeValueDao, productParam.getProductAttributeValueList(), id);
//关联专题
CmsSubjectProductRelationExample subjectProductRelationExample = new CmsSubjectProductRelationExample();
subjectProductRelationExample.createCriteria().andProductIdEqualTo(id);
subjectProductRelationMapper.deleteByExample(subjectProductRelationExample);
relateAndInsertList(subjectProductRelationDao, productParam.getSubjectProductRelationList(), id);
//关联优选
CmsPrefrenceAreaProductRelationExample prefrenceAreaExample = new CmsPrefrenceAreaProductRelationExample();
prefrenceAreaExample.createCriteria().andProductIdEqualTo(id);
prefrenceAreaProductRelationMapper.deleteByExample(prefrenceAreaExample);
relateAndInsertList(prefrenceAreaProductRelationDao, productParam.getPrefrenceAreaProductRelationList(), id);
count = 1;
return count;
}

private void handleUpdateSkuStockList(Long id, PmsProductParam productParam)
{
//当前的sku信息
List<PmsSkuStock> currSkuList = productParam.getSkuStockList();
//当前没有sku直接删除
if(CollUtil.isEmpty(currSkuList)){
PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
skuStockExample.createCriteria().andProductIdEqualTo(id);
skuStockMapper.deleteByExample(skuStockExample);
return;
}
//获取初始sku信息
PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
skuStockExample.createCriteria().andProductIdEqualTo(id);
List<PmsSkuStock> oriStuList = skuStockMapper.selectByExample(skuStockExample);
//获取新增sku信息,如果id为null则为新增的sku
List<PmsSkuStock> insertSkuList =
currSkuList.stream()
.filter(item -> item.getId() == null)
.collect(Collectors.toList());
//获取需要更新的sku信息,如果id不为null则为要更新的sku
List<PmsSkuStock> updateSkuList =
currSkuList.stream()
.filter(item -> item.getId() != null)
.collect(Collectors.toList());
List<Long> updateSkuIds = updateSkuList.stream()
.map(PmsSkuStock::getId)
.collect(Collectors.toList());
//获取需要删除的sku信息,如果id不在要更新的sku的id列表中,则为要删除的sku
// 这是初始的sku信息
List<PmsSkuStock> removeSkuList =
oriStuList.stream()
.filter(item -> !updateSkuIds.contains(item.getId()))
.collect(Collectors.toList());
// 处理sku编码
handleSkuStockCode(insertSkuList, id);
handleSkuStockCode(updateSkuList, id);
//新增sku
if(CollUtil.isNotEmpty(insertSkuList)){
relateAndInsertList(skuStockDao, insertSkuList, id);
}
//删除sku
if(CollUtil.isNotEmpty(removeSkuList)){
List<Long> removeSkuIds = removeSkuList.stream().map(PmsSkuStock::getId).collect(Collectors.toList());
PmsSkuStockExample removeExample = new PmsSkuStockExample();
removeExample.createCriteria().andIdIn(removeSkuIds);
skuStockMapper.deleteByExample(removeExample);
}
//修改sku
if(CollUtil.isNotEmpty(updateSkuList)){
for(PmsSkuStock pmsSkuStock : updateSkuList){
skuStockMapper.updateByPrimaryKeySelective(pmsSkuStock);
}
}
}

@Override
public List<PmsProduct> list(PmsProductQueryParam productQueryParam, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
PmsProductExample productExample = new PmsProductExample();
PmsProductExample.Criteria criteria = productExample.createCriteria();
// 没有删除的商品
criteria.andDeleteStatusEqualTo(0);
// 拼接查询条件
if(productQueryParam.getPublishStatus() != null){
criteria.andPublishStatusEqualTo(productQueryParam.getPublishStatus());
}
if(productQueryParam.getVerifyStatus() != null){
criteria.andVerifyStatusEqualTo(productQueryParam.getVerifyStatus());
}
if(!StrUtil.isEmpty(productQueryParam.getKeyword())){
criteria.andNameLike("%" + productQueryParam.getKeyword() + "%");
}
if(!StrUtil.isEmpty(productQueryParam.getProductSn())){
criteria.andProductSnEqualTo(productQueryParam.getProductSn());
}
if(productQueryParam.getBrandId() != null){
criteria.andBrandIdEqualTo(productQueryParam.getBrandId());
}
if(productQueryParam.getProductCategoryId() != null){
criteria.andProductCategoryIdEqualTo(productQueryParam.getProductCategoryId());
}
return productMapper.selectByExample(productExample);
}

@Override
public int updateVerifyStatus(List<Long> ids, Integer verifyStatus, String detail)
{
PmsProduct product = new PmsProduct();
product.setVerifyStatus(verifyStatus);
PmsProductExample example = new PmsProductExample();
example.createCriteria().andIdIn(ids);
List<PmsProductVertifyRecord> list = new ArrayList<>();
int count = productMapper.updateByExampleSelective(product, example);
//修改完审核状态后插入审核记录
// TODO 获取登录之后存储的 authentication,打印日志
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String username = authentication.getName();
UmsAdmin details = (UmsAdmin) authentication.getDetails();
LOGGER.info("PmsProductServiceImpl username = {}, details = {}", username, details);
for(Long id : ids){
PmsProductVertifyRecord record = new PmsProductVertifyRecord();
record.setProductId(id);
record.setCreateTime(new Date());
record.setDetail(detail);
record.setStatus(verifyStatus);
// TODO 审核人固定为test?
// 需要将token传回来?
record.setVertifyMan("test");
list.add(record);
}
productVertifyRecordDao.insertList(list);
return count;
}

@Override
public int updatePublishStatus(List<Long> ids, Integer publishStatus)
{
PmsProduct record = new PmsProduct();
record.setPublishStatus(publishStatus);
PmsProductExample example = new PmsProductExample();
example.createCriteria().andIdIn(ids);
return productMapper.updateByExampleSelective(record, example);
}

@Override
public int updateRecommendStatus(List<Long> ids, Integer recommendStatus)
{
PmsProduct record = new PmsProduct();
record.setRecommandStatus(recommendStatus);
PmsProductExample example = new PmsProductExample();
example.createCriteria().andIdIn(ids);
return productMapper.updateByExampleSelective(record, example);
}

@Override
public int updateNewStatus(List<Long> ids, Integer newStatus)
{
PmsProduct record = new PmsProduct();
record.setNewStatus(newStatus);
PmsProductExample example = new PmsProductExample();
example.createCriteria().andIdIn(ids);
return productMapper.updateByExampleSelective(record, example);
}

@Override
public int updateDeleteStatus(List<Long> ids, Integer deleteStatus)
{
PmsProduct record = new PmsProduct();
record.setDeleteStatus(deleteStatus);
PmsProductExample example = new PmsProductExample();
example.createCriteria().andIdIn(ids);
return productMapper.updateByExampleSelective(record, example);
}

@Override
public List<PmsProduct> list(String keyword)
{
PmsProductExample productExample = new PmsProductExample();
PmsProductExample.Criteria criteria = productExample.createCriteria();
criteria.andDeleteStatusEqualTo(0);
if(!StrUtil.isEmpty(keyword)){
criteria.andNameLike("%" + keyword + "%");
productExample.or().andDeleteStatusEqualTo(0).andProductSnLike("%" + keyword + "%");
}
return productMapper.selectByExample(productExample);
}

/**
* 建立和插入关系表操作
* @param dao 可以操作的dao
* @param dataList 要插入的数据
* @param productId 建立关系的id
*/
private void relateAndInsertList(Object dao, List dataList, Long productId)
{
try{
if(CollectionUtils.isEmpty(dataList)) return;
// 将给定的 dataList 中的每个对象都执行 setId 和 setProductId 这两个方法
for(Object item : dataList){
Method setId = item.getClass().getMethod("setId", Long.class);
setId.invoke(item, (Long) null);
Method setProductId = item.getClass().getMethod("setProductId", Long.class);
setProductId.invoke(item, productId);
}
// 将 dataList 插入对应的表
Method insertList = dao.getClass().getMethod("insertList", List.class);
insertList.invoke(dao, dataList);
} catch(Exception e){
LOGGER.warn("创建产品出错:{}", e.getMessage());
throw new RuntimeException(e.getMessage());
}
}
}
PmsBrandController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* 商品品牌管理Controller
*/
@Controller
@Api(tags = "PmsBrandController")
@Tag(name = "PmsBrandController", description = "商品品牌管理")
@RequestMapping("/brand")
public class PmsBrandController
{
@Resource
private PmsBrandService brandService;

@ApiOperation(value = "获取全部品牌列表")
@RequestMapping(value = "/listAll", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<PmsBrand>> getList()
{
return CommonResult.success(brandService.listAllBrand());
}

@ApiOperation(value = "添加品牌")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@Validated @RequestBody PmsBrandParam pmsBrand)
{
int count = brandService.createBrand(pmsBrand);
if(count == 1){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation(value = "更新品牌")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable("id") Long id, @Validated @RequestBody PmsBrandParam pmsBrandParam)
{
int count = brandService.updateBrand(id, pmsBrandParam);
if(count == 1){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation(value = "删除品牌")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult delete(@PathVariable("id") Long id)
{
int count = brandService.deleteBrand(id);
if(count == 1){
return CommonResult.success(null);
} else{
return CommonResult.failed();
}
}

@ApiOperation(value = "根据品牌名称分页获取品牌列表")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<PmsBrand>> getList(@RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "showStatus", required = false) Integer showStatus,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize)
{
List<PmsBrand> brandList = brandService.listBrand(keyword, showStatus, pageNum, pageSize);
return CommonResult.success(CommonPage.restPage(brandList));
}

@ApiOperation(value = "根据编号查询品牌信息")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<PmsBrand> getItem(@PathVariable("id") Long id)
{
return CommonResult.success(brandService.getBrand(id));
}

@ApiOperation(value = "批量删除品牌")
@RequestMapping(value = "/delete/batch", method = RequestMethod.POST)
@ResponseBody
public CommonResult deleteBatch(@RequestParam("ids") List<Long> ids)
{
int count = brandService.deleteBrand(ids);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation(value = "批量更新显示状态")
@RequestMapping(value = "/update/showStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateShowStatus(@RequestParam("ids") List<Long> ids,
@RequestParam("showStatus") Integer showStatus)
{
int count = brandService.updateShowStatus(ids, showStatus);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation(value = "批量更新厂家制造商状态")
@RequestMapping(value = "/update/factoryStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateFactoryStatus(@RequestParam("ids") List<Long> ids,
@RequestParam("factoryStatus") Integer factoryStatus)
{
int count = brandService.updateFactoryStatus(ids, factoryStatus);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}
}
PmsBrandService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* 商品品牌管理Service
*/
public interface PmsBrandService
{
/**
* 获取所有品牌
*/
List<PmsBrand> listAllBrand();

/**
* 创建品牌
*/
int createBrand(PmsBrandParam pmsBrandParam);

/**
* 修改品牌
*/
@Transactional
int updateBrand(Long id, PmsBrandParam pmsBrandParam);

/**
* 删除品牌
*/
int deleteBrand(Long id);

/**
* 批量删除品牌
*/
int deleteBrand(List<Long> ids);

/**
* 分页查询品牌
*/
List<PmsBrand> listBrand(String keyword, Integer showStatus, int pageNum, int pageSize);

/**
* 获取品牌详情
*/
PmsBrand getBrand(Long id);

/**
* 修改显示状态
*/
int updateShowStatus(List<Long> ids, Integer showStatus);

/**
* 修改厂家制造商状态
*/
int updateFactoryStatus(List<Long> ids, Integer factoryStatus);
}
PmsBrandServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* 商品品牌管理Service实现类
*/
@Service
public class PmsBrandServiceImpl implements PmsBrandService
{
@Resource
private PmsBrandMapper brandMapper;
@Resource
private PmsProductMapper productMapper;

@Override
public List<PmsBrand> listAllBrand()
{
return brandMapper.selectByExample(new PmsBrandExample());
}

@Override
public int createBrand(PmsBrandParam pmsBrandParam)
{
PmsBrand pmsBrand = new PmsBrand();
BeanUtils.copyProperties(pmsBrandParam, pmsBrand);
//如果创建时首字母为空,取名称的第一个为首字母
if(StrUtil.isEmpty(pmsBrand.getFirstLetter())){
pmsBrand.setFirstLetter(pmsBrand.getName().substring(0, 1));
}
return brandMapper.insertSelective(pmsBrand);
}

@Override
public int updateBrand(Long id, PmsBrandParam pmsBrandParam)
{
PmsBrand pmsBrand = new PmsBrand();
BeanUtils.copyProperties(pmsBrandParam, pmsBrand);
pmsBrand.setId(id);
//如果创建时首字母为空,取名称的第一个为首字母
if(StrUtil.isEmpty(pmsBrand.getFirstLetter())){
pmsBrand.setFirstLetter(pmsBrand.getName().substring(0, 1));
}
//更新品牌时要更新商品中的品牌名称
PmsProduct product = new PmsProduct();
product.setBrandName(pmsBrand.getName());
PmsProductExample example = new PmsProductExample();
example.createCriteria().andBrandIdEqualTo(id);
productMapper.updateByExampleSelective(product, example);
return brandMapper.updateByPrimaryKeySelective(pmsBrand);
}

@Override
public int deleteBrand(Long id)
{
return brandMapper.deleteByPrimaryKey(id);
}

@Override
public int deleteBrand(List<Long> ids)
{
PmsBrandExample pmsBrandExample = new PmsBrandExample();
pmsBrandExample.createCriteria().andIdIn(ids);
return brandMapper.deleteByExample(pmsBrandExample);
}

@Override
public List<PmsBrand> listBrand(String keyword, Integer showStatus, int pageNum, int pageSize)
{
PageHelper.startPage(pageNum, pageSize);
PmsBrandExample pmsBrandExample = new PmsBrandExample();
pmsBrandExample.setOrderByClause("sort desc");
PmsBrandExample.Criteria criteria = pmsBrandExample.createCriteria();
if(!StrUtil.isEmpty(keyword)){
criteria.andNameLike("%" + keyword + "%");
}
if(showStatus != null){
criteria.andShowStatusEqualTo(showStatus);
}
return brandMapper.selectByExample(pmsBrandExample);
}

@Override
public PmsBrand getBrand(Long id)
{
return brandMapper.selectByPrimaryKey(id);
}

@Override
public int updateShowStatus(List<Long> ids, Integer showStatus)
{
PmsBrand pmsBrand = new PmsBrand();
pmsBrand.setShowStatus(showStatus);
PmsBrandExample pmsBrandExample = new PmsBrandExample();
pmsBrandExample.createCriteria().andIdIn(ids);
return brandMapper.updateByExampleSelective(pmsBrand, pmsBrandExample);
}

@Override
public int updateFactoryStatus(List<Long> ids, Integer factoryStatus)
{
PmsBrand pmsBrand = new PmsBrand();
pmsBrand.setFactoryStatus(factoryStatus);
PmsBrandExample pmsBrandExample = new PmsBrandExample();
pmsBrandExample.createCriteria().andIdIn(ids);
return brandMapper.updateByExampleSelective(pmsBrand, pmsBrandExample);
}
}
PmsSkuStockController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* 商品SKU库存管理Controller
*/
@Controller
@Api(tags = "PmsSkuStockController")
@Tag(name = "PmsSkuStockController", description = "sku商品库存管理")
@RequestMapping("/sku")
public class PmsSkuStockController
{
@Resource
private PmsSkuStockService skuStockService;

@ApiOperation("根据商品ID及sku编码模糊搜索sku库存")
@RequestMapping(value = "/{pid}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<PmsSkuStock>> getList(@PathVariable Long pid,
@RequestParam(value = "keyword", required = false) String keyword)
{
List<PmsSkuStock> skuStockList = skuStockService.getList(pid, keyword);
return CommonResult.success(skuStockList);
}

@ApiOperation("批量更新sku库存信息")
@RequestMapping(value = "/update/{pid}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long pid, @RequestBody List<PmsSkuStock> skuStockList)
{
int count = skuStockService.update(pid, skuStockList);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}
}
PmsSkuStockService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
* 商品SKU库存管理Service
*/
public interface PmsSkuStockService
{
/**
* 根据产品id和skuCode关键字模糊搜索
*/
List<PmsSkuStock> getList(Long pid, String keyword);

/**
* 批量更新商品库存信息
*/
int update(Long pid, List<PmsSkuStock> skuStockList);
}
PmsSkuStockServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* 商品SKU库存管理Service实现类
*/
@Service
public class PmsSkuStockServiceImpl implements PmsSkuStockService
{
@Resource
private PmsSkuStockMapper skuStockMapper;
@Resource
private PmsSkuStockDao skuStockDao;

@Override
public List<PmsSkuStock> getList(Long pid, String keyword)
{
PmsSkuStockExample example = new PmsSkuStockExample();
PmsSkuStockExample.Criteria criteria = example.createCriteria().andProductIdEqualTo(pid);
if(!StrUtil.isEmpty(keyword)){
criteria.andSkuCodeLike("%" + keyword + "%");
}
return skuStockMapper.selectByExample(example);
}

@Override
public int update(Long pid, List<PmsSkuStock> skuStockList)
{
return skuStockDao.replaceList(skuStockList);
}
}
PmsProductCategoryController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* 商品分类管理Controller
*/
@Controller
@Api(tags = "PmsProductCategoryController")
@Tag(name = "PmsProductCategoryController", description = "商品分类管理")
@RequestMapping("/productCategory")
public class PmsProductCategoryController
{
@Resource
private PmsProductCategoryService productCategoryService;

@ApiOperation("添加商品分类")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@Validated @RequestBody PmsProductCategoryParam productCategoryParam)
{
int count = productCategoryService.create(productCategoryParam);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("修改商品分类")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id,
@Validated @RequestBody PmsProductCategoryParam productCategoryParam)
{
int count = productCategoryService.update(id, productCategoryParam);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("分页查询商品分类")
@RequestMapping(value = "/list/{parentId}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<PmsProductCategory>> getList(@PathVariable Long parentId,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<PmsProductCategory> productCategoryList = productCategoryService.getList(parentId, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(productCategoryList));
}

@ApiOperation("根据id获取商品分类")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<PmsProductCategory> getItem(@PathVariable Long id)
{
PmsProductCategory productCategory = productCategoryService.getItem(id);
return CommonResult.success(productCategory);
}

@ApiOperation("删除商品分类")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id)
{
int count = productCategoryService.delete(id);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("修改导航栏显示状态")
@RequestMapping(value = "/update/navStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateNavStatus(@RequestParam("ids") List<Long> ids,
@RequestParam("navStatus") Integer navStatus)
{
int count = productCategoryService.updateNavStatus(ids, navStatus);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("修改显示状态")
@RequestMapping(value = "/update/showStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateShowStatus(@RequestParam("ids") List<Long> ids,
@RequestParam("showStatus") Integer showStatus)
{
int count = productCategoryService.updateShowStatus(ids, showStatus);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("查询所有一级分类及子分类")
@RequestMapping(value = "/list/withChildren", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<PmsProductCategoryWithChildrenItem>> listWithChildren()
{
List<PmsProductCategoryWithChildrenItem> list = productCategoryService.listWithChildren();
return CommonResult.success(list);
}
}
PmsProductCategoryService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* 商品分类管理Service
*/
public interface PmsProductCategoryService
{
/**
* 创建商品分类
*/
@Transactional
int create(PmsProductCategoryParam pmsProductCategoryParam);

/**
* 修改商品分类
*/
@Transactional
int update(Long id, PmsProductCategoryParam pmsProductCategoryParam);

/**
* 分页获取商品分类
*/
List<PmsProductCategory> getList(Long parentId, Integer pageSize, Integer pageNum);

/**
* 删除商品分类
*/
int delete(Long id);

/**
* 根据ID获取商品分类
*/
PmsProductCategory getItem(Long id);

/**
* 批量修改导航状态
*/
int updateNavStatus(List<Long> ids, Integer navStatus);

/**
* 批量修改显示状态
*/
int updateShowStatus(List<Long> ids, Integer showStatus);

/**
* 以层级形式获取商品分类
*/
List<PmsProductCategoryWithChildrenItem> listWithChildren();
}
PmsProductCategoryServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* 商品分类管理Service实现类
*/
@Service
public class PmsProductCategoryServiceImpl implements PmsProductCategoryService
{
@Resource
private PmsProductCategoryMapper productCategoryMapper;
@Resource
private PmsProductMapper productMapper;
@Resource
private PmsProductCategoryAttributeRelationDao productCategoryAttributeRelationDao;
@Resource
private PmsProductCategoryAttributeRelationMapper productCategoryAttributeRelationMapper;
@Resource
private PmsProductCategoryDao productCategoryDao;

@Override
public int create(PmsProductCategoryParam pmsProductCategoryParam)
{
PmsProductCategory productCategory = new PmsProductCategory();
productCategory.setProductCount(0);
BeanUtils.copyProperties(pmsProductCategoryParam, productCategory);
//没有父分类时为一级分类
setCategoryLevel(productCategory);
int count = productCategoryMapper.insertSelective(productCategory);
//创建筛选属性关联
List<Long> productAttributeIdList = pmsProductCategoryParam.getProductAttributeIdList();
if(!CollectionUtils.isEmpty(productAttributeIdList)){
insertRelationList(productCategory.getId(), productAttributeIdList);
}
return count;
}

/**
* 批量插入商品分类与筛选属性关系表
* @param productCategoryId 商品分类id
* @param productAttributeIdList 相关商品筛选属性id集合
*/
private void insertRelationList(Long productCategoryId, List<Long> productAttributeIdList)
{
List<PmsProductCategoryAttributeRelation> relationList = new ArrayList<>();
productAttributeIdList.forEach(productAttrId -> {
PmsProductCategoryAttributeRelation relation = new PmsProductCategoryAttributeRelation();
relation.setProductAttributeId(productAttrId);
relation.setProductCategoryId(productCategoryId);
relationList.add(relation);
});
productCategoryAttributeRelationDao.insertList(relationList);
}

@Override
public int update(Long id, PmsProductCategoryParam pmsProductCategoryParam)
{
PmsProductCategory productCategory = new PmsProductCategory();
productCategory.setId(id);
BeanUtils.copyProperties(pmsProductCategoryParam, productCategory);
setCategoryLevel(productCategory);
//更新商品分类时要更新商品中的名称
PmsProduct product = new PmsProduct();
product.setProductCategoryName(productCategory.getName());
PmsProductExample example = new PmsProductExample();
example.createCriteria().andProductCategoryIdEqualTo(id);
productMapper.updateByExampleSelective(product, example);
//同时更新筛选属性的信息
if(!CollectionUtils.isEmpty(pmsProductCategoryParam.getProductAttributeIdList())){
PmsProductCategoryAttributeRelationExample relationExample =
new PmsProductCategoryAttributeRelationExample();
relationExample.createCriteria().andProductCategoryIdEqualTo(id);
productCategoryAttributeRelationMapper.deleteByExample(relationExample);
insertRelationList(id, pmsProductCategoryParam.getProductAttributeIdList());
} else{
PmsProductCategoryAttributeRelationExample relationExample =
new PmsProductCategoryAttributeRelationExample();
relationExample.createCriteria().andProductCategoryIdEqualTo(id);
productCategoryAttributeRelationMapper.deleteByExample(relationExample);
}
return productCategoryMapper.updateByPrimaryKeySelective(productCategory);
}

@Override
public List<PmsProductCategory> getList(Long parentId, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
PmsProductCategoryExample example = new PmsProductCategoryExample();
example.setOrderByClause("sort desc");
example.createCriteria().andParentIdEqualTo(parentId);
return productCategoryMapper.selectByExample(example);
}

@Override
public int delete(Long id)
{
return productCategoryMapper.deleteByPrimaryKey(id);
}

@Override
public PmsProductCategory getItem(Long id)
{
return productCategoryMapper.selectByPrimaryKey(id);
}

@Override
public int updateNavStatus(List<Long> ids, Integer navStatus)
{
PmsProductCategory productCategory = new PmsProductCategory();
productCategory.setNavStatus(navStatus);
PmsProductCategoryExample example = new PmsProductCategoryExample();
example.createCriteria().andIdIn(ids);
return productCategoryMapper.updateByExampleSelective(productCategory, example);
}

@Override
public int updateShowStatus(List<Long> ids, Integer showStatus)
{
PmsProductCategory productCategory = new PmsProductCategory();
productCategory.setShowStatus(showStatus);
PmsProductCategoryExample example = new PmsProductCategoryExample();
example.createCriteria().andIdIn(ids);
return productCategoryMapper.updateByExampleSelective(productCategory, example);
}

@Override
public List<PmsProductCategoryWithChildrenItem> listWithChildren()
{
return productCategoryDao.listWithChildren();
}

/**
* 根据分类的parentId设置分类的level
*/
private void setCategoryLevel(PmsProductCategory productCategory)
{
//没有父分类时为一级分类
if(productCategory.getParentId() == 0){
productCategory.setLevel(0);
} else{
//有父分类时选择根据父分类level设置
PmsProductCategory parentCategory = productCategoryMapper.selectByPrimaryKey(productCategory.getParentId());
if(parentCategory != null){
productCategory.setLevel(parentCategory.getLevel() + 1);
} else{
productCategory.setLevel(0);
}
}
}
}
PmsProductAttributeController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
@Controller
@Api(tags = "PmsProductAttributeController")
@Tag(name = "PmsProductAttributeController", description = "商品属性管理")
@RequestMapping("/productAttribute")
public class PmsProductAttributeController
{
@Resource
private PmsProductAttributeService productAttributeService;

@ApiOperation("根据分类查询属性列表或参数列表")
@ApiImplicitParams(
{@ApiImplicitParam(name = "type", value = "0表示属性,1表示参数", required = true, paramType = "query",
dataType = "integer")})
@RequestMapping(value = "/list/{cid}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<PmsProductAttribute>> getList(@PathVariable Long cid,
@RequestParam(value = "type") Integer type,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<PmsProductAttribute> productAttributeList = productAttributeService.getList(cid, type, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(productAttributeList));
}

@ApiOperation("添加商品属性信息")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody PmsProductAttributeParam productAttributeParam)
{
int count = productAttributeService.create(productAttributeParam);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("修改商品属性信息")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody PmsProductAttributeParam productAttributeParam)
{
int count = productAttributeService.update(id, productAttributeParam);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("查询单个商品属性")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<PmsProductAttribute> getItem(@PathVariable Long id)
{
PmsProductAttribute productAttribute = productAttributeService.getItem(id);
return CommonResult.success(productAttribute);
}

@ApiOperation("批量删除商品属性")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("ids") List<Long> ids)
{
int count = productAttributeService.delete(ids);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("根据商品分类的id获取商品属性及属性分类")
@RequestMapping(value = "/attrInfo/{productCategoryId}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<ProductAttrInfo>> getAttrInfo(@PathVariable Long productCategoryId)
{
List<ProductAttrInfo> productAttrInfoList = productAttributeService.getProductAttrInfo(productCategoryId);
return CommonResult.success(productAttrInfoList);
}
}
PmsProductAttributeService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* 商品属性管理Service
*/
public interface PmsProductAttributeService
{
/**
* 根据分类分页获取商品属性
* @param cid 分类id
* @param type 0->规格;1->参数
*/
List<PmsProductAttribute> getList(Long cid, Integer type, Integer pageSize, Integer pageNum);

/**
* 添加商品属性
*/
@Transactional
int create(PmsProductAttributeParam pmsProductAttributeParam);

/**
* 修改商品属性
*/
int update(Long id, PmsProductAttributeParam productAttributeParam);

/**
* 获取单个商品属性信息
*/
PmsProductAttribute getItem(Long id);

/**
* 批量删除商品属性
*/
@Transactional
int delete(List<Long> ids);

/**
* 获取商品分类对应属性列表
*/
List<ProductAttrInfo> getProductAttrInfo(Long productCategoryId);
}
PmsProductAttributeServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* 商品属性管理Service实现类
*/
@Service
public class PmsProductAttributeServiceImpl implements PmsProductAttributeService
{
@Resource
private PmsProductAttributeMapper productAttributeMapper;
@Resource
private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
@Resource
private PmsProductAttributeDao productAttributeDao;

@Override
public List<PmsProductAttribute> getList(Long cid, Integer type, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
PmsProductAttributeExample example = new PmsProductAttributeExample();
example.setOrderByClause("sort desc");
example.createCriteria().andProductAttributeCategoryIdEqualTo(cid).andTypeEqualTo(type);
return productAttributeMapper.selectByExample(example);
}

@Override
public int create(PmsProductAttributeParam pmsProductAttributeParam)
{
PmsProductAttribute pmsProductAttribute = new PmsProductAttribute();
BeanUtils.copyProperties(pmsProductAttributeParam, pmsProductAttribute);
int count = productAttributeMapper.insertSelective(pmsProductAttribute);
//新增商品属性以后需要更新商品属性分类数量
PmsProductAttributeCategory pmsProductAttributeCategory =
productAttributeCategoryMapper.selectByPrimaryKey(pmsProductAttribute.getProductAttributeCategoryId());
if(pmsProductAttribute.getType() == 0){
pmsProductAttributeCategory.setAttributeCount(pmsProductAttributeCategory.getAttributeCount() + 1);
} else if(pmsProductAttribute.getType() == 1){
pmsProductAttributeCategory.setParamCount(pmsProductAttributeCategory.getParamCount() + 1);
}
productAttributeCategoryMapper.updateByPrimaryKey(pmsProductAttributeCategory);
return count;
}

@Override
public int update(Long id, PmsProductAttributeParam productAttributeParam)
{
PmsProductAttribute pmsProductAttribute = new PmsProductAttribute();
pmsProductAttribute.setId(id);
BeanUtils.copyProperties(productAttributeParam, pmsProductAttribute);
return productAttributeMapper.updateByPrimaryKeySelective(pmsProductAttribute);
}

@Override
public PmsProductAttribute getItem(Long id)
{
return productAttributeMapper.selectByPrimaryKey(id);
}

@Override
public int delete(List<Long> ids)
{
//获取分类
PmsProductAttribute pmsProductAttribute = productAttributeMapper.selectByPrimaryKey(ids.get(0));
Integer type = pmsProductAttribute.getType();
PmsProductAttributeCategory pmsProductAttributeCategory =
productAttributeCategoryMapper.selectByPrimaryKey(pmsProductAttribute.getProductAttributeCategoryId());
PmsProductAttributeExample example = new PmsProductAttributeExample();
example.createCriteria().andIdIn(ids);
int count = productAttributeMapper.deleteByExample(example);
//删除完成后修改数量
if(type == 0){
if(pmsProductAttributeCategory.getAttributeCount() >= count){
pmsProductAttributeCategory.setAttributeCount(pmsProductAttributeCategory.getAttributeCount() - count);
} else{
pmsProductAttributeCategory.setAttributeCount(0);
}
} else if(type == 1){
if(pmsProductAttributeCategory.getParamCount() >= count){
pmsProductAttributeCategory.setParamCount(pmsProductAttributeCategory.getParamCount() - count);
} else{
pmsProductAttributeCategory.setParamCount(0);
}
}
productAttributeCategoryMapper.updateByPrimaryKey(pmsProductAttributeCategory);
return count;
}

@Override
public List<ProductAttrInfo> getProductAttrInfo(Long productCategoryId)
{
return productAttributeDao.getProductAttrInfo(productCategoryId);
}
}
PmsProductAttributeCategoryController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* 商品属性分类管理Controller
*/
@Controller
@Api(tags = "PmsProductAttributeCategoryController")
@Tag(name = "PmsProductAttributeCategoryController", description = "商品属性分类管理")
@RequestMapping("/productAttribute/category")
public class PmsProductAttributeCategoryController
{
@Resource
private PmsProductAttributeCategoryService productAttributeCategoryService;

@ApiOperation("添加商品属性分类")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestParam String name)
{
int count = productAttributeCategoryService.create(name);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("修改商品属性分类")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestParam String name)
{
int count = productAttributeCategoryService.update(id, name);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("删除单个商品属性分类")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult delete(@PathVariable Long id)
{
int count = productAttributeCategoryService.delete(id);
if(count > 0){
return CommonResult.success(count);
} else{
return CommonResult.failed();
}
}

@ApiOperation("获取单个商品属性分类信息")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<PmsProductAttributeCategory> getItem(@PathVariable Long id)
{
PmsProductAttributeCategory productAttributeCategory = productAttributeCategoryService.getItem(id);
return CommonResult.success(productAttributeCategory);
}

@ApiOperation("分页获取所有商品属性分类")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<PmsProductAttributeCategory>> getList(
@RequestParam(defaultValue = "5") Integer pageSize, @RequestParam(defaultValue = "1") Integer pageNum)
{
List<PmsProductAttributeCategory> productAttributeCategoryList =
productAttributeCategoryService.getList(pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(productAttributeCategoryList));
}

@ApiOperation("获取所有商品属性分类及其下属性")
@RequestMapping(value = "/list/withAttr", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<PmsProductAttributeCategoryItem>> getListWithAttr()
{
List<PmsProductAttributeCategoryItem> productAttributeCategoryResultList =
productAttributeCategoryService.getListWithAttr();
return CommonResult.success(productAttributeCategoryResultList);
}
}
PmsProductAttributeCategoryService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* 商品属性分类管理Service
*/
public interface PmsProductAttributeCategoryService
{
/**
* 创建属性分类
*/
int create(String name);

/**
* 修改属性分类
*/
int update(Long id, String name);

/**
* 删除属性分类
*/
int delete(Long id);

/**
* 获取属性分类详情
*/
PmsProductAttributeCategory getItem(Long id);

/**
* 分页查询属性分类
*/
List<PmsProductAttributeCategory> getList(Integer pageSize, Integer pageNum);

/**
* 获取包含属性的属性分类
*/
List<PmsProductAttributeCategoryItem> getListWithAttr();
}
PmsProductAttributeCategoryServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* 商品属性分类管理Service实现类
*/
@Service
public class PmsProductAttributeCategoryServiceImpl implements PmsProductAttributeCategoryService
{
@Resource
private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
@Resource
private PmsProductAttributeCategoryDao productAttributeCategoryDao;

@Override
public int create(String name)
{
PmsProductAttributeCategory productAttributeCategory = new PmsProductAttributeCategory();
productAttributeCategory.setName(name);
return productAttributeCategoryMapper.insertSelective(productAttributeCategory);
}

@Override
public int update(Long id, String name)
{
PmsProductAttributeCategory productAttributeCategory = new PmsProductAttributeCategory();
productAttributeCategory.setName(name);
productAttributeCategory.setId(id);
return productAttributeCategoryMapper.updateByPrimaryKeySelective(productAttributeCategory);
}

@Override
public int delete(Long id)
{
return productAttributeCategoryMapper.deleteByPrimaryKey(id);
}

@Override
public PmsProductAttributeCategory getItem(Long id)
{
return productAttributeCategoryMapper.selectByPrimaryKey(id);
}

@Override
public List<PmsProductAttributeCategory> getList(Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
return productAttributeCategoryMapper.selectByExample(new PmsProductAttributeCategoryExample());
}

@Override
public List<PmsProductAttributeCategoryItem> getListWithAttr()
{
return productAttributeCategoryDao.getListWithAttr();
}
}

内容管理模块相关表分析,cms_*

my_ums
cms_*相关表分析
  • cms_subject表为专题表,其中category_id字段为表cms_subject_category的外键
  • cms_subject_category表为专题分类表
  • cms_subject_comment表为专题评论表,其中subject_id字段为表cms_subject的外键
  • cms_subject_product_relation表为专题商品关系表,其中subject_id字段为表cms_subject的外键
  • cms_prefrence_area表为优选专区表
  • cms_prefrence_area_product_relation表为优选专区和产品关系表,其中prefrence_area_id字段为表cms_prefrence_area的外键
  • cms_topic表为话题表,其中category_id字段为表cms_topic_category的外键
  • cms_topic_category表为话题分类表
  • cms_topic_comment表为专题评论表,其中topic_id字段为表cms_topic的外键
  • cms_member_report表为用户举报表
  • cms_help表为帮助表,其中category_id字段为表cms_help_category的外键
  • cms_help_category表为帮助分类表

内容管理相关接口设计(设计不完整)

CmsSubjectController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* 商品专题管理Controller
*/
@Controller
@Api(tags = "CmsSubjectController")
@Tag(name = "CmsSubjectController", description = "商品专题管理")
@RequestMapping("/subject")
public class CmsSubjectController
{
@Resource
private CmsSubjectService subjectService;

@ApiOperation("获取全部商品专题")
@RequestMapping(value = "/listAll", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<CmsSubject>> listAll()
{
List<CmsSubject> subjectList = subjectService.listAll();
return CommonResult.success(subjectList);
}

@ApiOperation(value = "根据专题名称分页获取商品专题")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<CmsSubject>> getList(
@RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize)
{
List<CmsSubject> subjectList = subjectService.list(keyword, pageNum, pageSize);
return CommonResult.success(CommonPage.restPage(subjectList));
}
}
CmsSubjectService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
* 商品专题管理Service
*/
public interface CmsSubjectService
{
/**
* 查询所有专题
*/
List<CmsSubject> listAll();

/**
* 分页查询专题
*/
List<CmsSubject> list(String keyword, Integer pageNum, Integer pageSize);
}
CmsSubjectServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* 商品专题管理Service实现类
*/
@Service
public class CmsSubjectServiceImpl implements CmsSubjectService
{
@Resource
private CmsSubjectMapper subjectMapper;

@Override
public List<CmsSubject> listAll()
{
return subjectMapper.selectByExample(new CmsSubjectExample());
}

@Override
public List<CmsSubject> list(String keyword, Integer pageNum, Integer pageSize)
{
PageHelper.startPage(pageNum, pageSize);
CmsSubjectExample example = new CmsSubjectExample();
CmsSubjectExample.Criteria criteria = example.createCriteria();
if(!StrUtil.isEmpty(keyword)){
criteria.andTitleLike("%" + keyword + "%");
}
return subjectMapper.selectByExample(example);
}
}
CmsPrefrenceAreaController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* 商品优选管理Controller
*/
@Controller
@Api(tags = "CmsPrefrenceAreaController")
@Tag(name = "CmsPrefrenceAreaController", description = "商品优选管理")
@RequestMapping("/prefrenceArea")
public class CmsPrefrenceAreaController
{
@Resource
private CmsPrefrenceAreaService prefrenceAreaService;

@ApiOperation("获取所有商品优选")
@RequestMapping(value = "/listAll", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<CmsPrefrenceArea>> listAll()
{
List<CmsPrefrenceArea> prefrenceAreaList = prefrenceAreaService.listAll();
return CommonResult.success(prefrenceAreaList);
}
}
CmsPrefrenceAreaService
1
2
3
4
5
6
7
8
9
10
/**
* 商品优选管理Service
*/
public interface CmsPrefrenceAreaService
{
/**
* 获取所有优选专区
*/
List<CmsPrefrenceArea> listAll();
}
CmsPrefrenceAreaServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
* 商品优选管理Service实现类
*/
@Service
public class CmsPrefrenceAreaServiceImpl implements CmsPrefrenceAreaService
{
@Resource
private CmsPrefrenceAreaMapper prefrenceAreaMapper;

@Override
public List<CmsPrefrenceArea> listAll()
{
return prefrenceAreaMapper.selectByExample(new CmsPrefrenceAreaExample());
}
}

订单管理模块相关表分析,oms_*

my_oms1
oms_*相关表分析
  • oms_order表为订单表
  • oms_order_item表为订单中所包含的商品,其中order_id字段为表oms_order的外键
  • oms_order_operate_history表为订单操作历史记录,其中order_id字段为表oms_order的外键
  • oms_order_return_apply表为订单退货申请表,其中order_id字段为表oms_order的外键、company_address_id为表oms_company_address的外键
  • oms_company_address表为公司收发货地址表
  • oms_cart_item表为购物车表
  • oms_order_return_reason表为退货原因表
  • oms_order_setting表为订单设置表

订单管理相关接口设计

OmsOrderController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* 订单管理Controller
*/
@Controller
@Api(tags = "OmsOrderController")
@Tag(name = "OmsOrderController", description = "订单管理")
@RequestMapping("/order")
public class OmsOrderController
{
@Resource
private OmsOrderService orderService;

@ApiOperation("查询订单")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<OmsOrder>> list(OmsOrderQueryParam queryParam,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<OmsOrder> orderList = orderService.list(queryParam, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(orderList));
}

@ApiOperation("批量发货")
@RequestMapping(value = "/update/delivery", method = RequestMethod.POST)
@ResponseBody
public CommonResult delivery(@RequestBody List<OmsOrderDeliveryParam> deliveryParamList)
{
int count = orderService.delivery(deliveryParamList);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("批量关闭订单")
@RequestMapping(value = "/update/close", method = RequestMethod.POST)
@ResponseBody
public CommonResult close(@RequestParam("ids") List<Long> ids, @RequestParam String note)
{
int count = orderService.close(ids, note);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("批量删除订单")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("ids") List<Long> ids)
{
int count = orderService.delete(ids);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("获取订单详情:订单信息、商品信息、操作记录")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<OmsOrderDetail> detail(@PathVariable Long id)
{
OmsOrderDetail orderDetailResult = orderService.detail(id);
return CommonResult.success(orderDetailResult);
}

@ApiOperation("修改收货人信息")
@RequestMapping(value = "/update/receiverInfo", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateReceiverInfo(@RequestBody OmsReceiverInfoParam receiverInfoParam)
{
int count = orderService.updateReceiverInfo(receiverInfoParam);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改订单费用信息")
@RequestMapping(value = "/update/moneyInfo", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateReceiverInfo(@RequestBody OmsMoneyInfoParam moneyInfoParam)
{
int count = orderService.updateMoneyInfo(moneyInfoParam);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("备注订单")
@RequestMapping(value = "/update/note", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateNote(@RequestParam("id") Long id, @RequestParam("note") String note,
@RequestParam("status") Integer status)
{
int count = orderService.updateNote(id, note, status);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}
}
OmsOrderService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* 订单管理Service
*/
public interface OmsOrderService
{
/**
* 订单查询
*/
List<OmsOrder> list(OmsOrderQueryParam queryParam, Integer pageSize, Integer pageNum);

/**
* 批量发货
*/
@Transactional
int delivery(List<OmsOrderDeliveryParam> deliveryParamList);

/**
* 批量关闭订单
*/
@Transactional
int close(List<Long> ids, String note);

/**
* 批量删除订单
*/
int delete(List<Long> ids);

/**
* 获取指定订单详情
*/
OmsOrderDetail detail(Long id);

/**
* 修改订单收货人信息
*/
@Transactional
int updateReceiverInfo(OmsReceiverInfoParam receiverInfoParam);

/**
* 修改订单费用信息
*/
@Transactional
int updateMoneyInfo(OmsMoneyInfoParam moneyInfoParam);

/**
* 修改订单备注
*/
@Transactional
int updateNote(Long id, String note, Integer status);
}
OmsOrderServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* 订单管理Service实现类
*/
@Service
public class OmsOrderServiceImpl implements OmsOrderService
{
@Resource
private OmsOrderMapper orderMapper;
@Resource
private OmsOrderDao orderDao;
@Resource
private OmsOrderOperateHistoryDao orderOperateHistoryDao;
@Resource
private OmsOrderOperateHistoryMapper orderOperateHistoryMapper;

@Override
public List<OmsOrder> list(OmsOrderQueryParam queryParam, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
return orderDao.getList(queryParam);
}

@Override
public int delivery(List<OmsOrderDeliveryParam> deliveryParamList)
{
//批量发货
int count = orderDao.delivery(deliveryParamList);
//添加操作记录
List<OmsOrderOperateHistory> operateHistoryList = deliveryParamList
.stream()
.map(omsOrderDeliveryParam -> {
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(omsOrderDeliveryParam.getOrderId());
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(2);
history.setNote("完成发货");
return history;
})
.collect(Collectors.toList());
orderOperateHistoryDao.insertList(operateHistoryList);
return count;
}

@Override
public int close(List<Long> ids, String note)
{
OmsOrder record = new OmsOrder();
record.setStatus(4);
OmsOrderExample example = new OmsOrderExample();
example.createCriteria().andDeleteStatusEqualTo(0).andIdIn(ids);
int count = orderMapper.updateByExampleSelective(record, example);
List<OmsOrderOperateHistory> historyList = ids
.stream()
.map(orderId -> {
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(orderId);
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(4);
history.setNote("订单关闭:" + note);
return history;})
.collect(Collectors.toList());
orderOperateHistoryDao.insertList(historyList);
return count;
}

@Override
public int delete(List<Long> ids)
{
OmsOrder record = new OmsOrder();
record.setDeleteStatus(1);
OmsOrderExample example = new OmsOrderExample();
example.createCriteria().andDeleteStatusEqualTo(0).andIdIn(ids);
return orderMapper.updateByExampleSelective(record, example);
}

@Override
public OmsOrderDetail detail(Long id)
{
return orderDao.getDetail(id);
}

@Override
public int updateReceiverInfo(OmsReceiverInfoParam receiverInfoParam)
{
OmsOrder order = new OmsOrder();
order.setId(receiverInfoParam.getOrderId());
order.setReceiverName(receiverInfoParam.getReceiverName());
order.setReceiverPhone(receiverInfoParam.getReceiverPhone());
order.setReceiverPostCode(receiverInfoParam.getReceiverPostCode());
order.setReceiverDetailAddress(receiverInfoParam.getReceiverDetailAddress());
order.setReceiverProvince(receiverInfoParam.getReceiverProvince());
order.setReceiverCity(receiverInfoParam.getReceiverCity());
order.setReceiverRegion(receiverInfoParam.getReceiverRegion());
order.setModifyTime(new Date());
int count = orderMapper.updateByPrimaryKeySelective(order);
//插入操作记录
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(receiverInfoParam.getOrderId());
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(receiverInfoParam.getStatus());
history.setNote("修改收货人信息");
orderOperateHistoryMapper.insert(history);
return count;
}

@Override
public int updateMoneyInfo(OmsMoneyInfoParam moneyInfoParam)
{
OmsOrder order = new OmsOrder();
order.setId(moneyInfoParam.getOrderId());
order.setFreightAmount(moneyInfoParam.getFreightAmount());
order.setDiscountAmount(moneyInfoParam.getDiscountAmount());
order.setModifyTime(new Date());
int count = orderMapper.updateByPrimaryKeySelective(order);
//插入操作记录
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(moneyInfoParam.getOrderId());
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(moneyInfoParam.getStatus());
history.setNote("修改费用信息");
orderOperateHistoryMapper.insert(history);
return count;
}

@Override
public int updateNote(Long id, String note, Integer status)
{
OmsOrder order = new OmsOrder();
order.setId(id);
order.setNote(note);
order.setModifyTime(new Date());
int count = orderMapper.updateByPrimaryKeySelective(order);
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(id);
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(status);
history.setNote("修改备注信息:" + note);
orderOperateHistoryMapper.insert(history);
return count;
}
}
OmsCompanyAddressController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* 收货地址管理Controller
*/
@Controller
@Api(tags = "OmsCompanyAddressController")
@Tag(name = "OmsCompanyAddressController", description = "收货地址管理")
@RequestMapping("/companyAddress")
public class OmsCompanyAddressController
{
@Resource
private OmsCompanyAddressService companyAddressService;

@ApiOperation("获取所有收货地址")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<OmsCompanyAddress>> list()
{
List<OmsCompanyAddress> companyAddressList = companyAddressService.list();
return CommonResult.success(companyAddressList);
}
}
OmsCompanyAddressService
1
2
3
4
5
6
7
8
9
10
/**
* 收货地址管理Service
*/
public interface OmsCompanyAddressService
{
/**
* 获取全部收货地址
*/
List<OmsCompanyAddress> list();
}
OmsCompanyAddressServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
* 收货地址管理Service实现类
*/
@Service
public class OmsCompanyAddressServiceImpl implements OmsCompanyAddressService
{
@Resource
private OmsCompanyAddressMapper companyAddressMapper;

@Override
public List<OmsCompanyAddress> list()
{
return companyAddressMapper.selectByExample(new OmsCompanyAddressExample());
}
}
OmsOrderSettingController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* 订单设置管理Controller
*/
@Controller
@Api(tags = "OmsOrderSettingController")
@Tag(name = "OmsOrderSettingController", description = "订单设置管理")
@RequestMapping("/orderSetting")
public class OmsOrderSettingController
{
@Resource
private OmsOrderSettingService orderSettingService;

@ApiOperation("获取指定订单设置")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<OmsOrderSetting> getItem(@PathVariable Long id)
{
OmsOrderSetting orderSetting = orderSettingService.getItem(id);
return CommonResult.success(orderSetting);
}

@ApiOperation("修改指定订单设置")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody OmsOrderSetting orderSetting)
{
int count = orderSettingService.update(id, orderSetting);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}
}
OmsOrderSettingService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
* 订单设置管理Service
*/
public interface OmsOrderSettingService
{
/**
* 获取指定订单设置
*/
OmsOrderSetting getItem(Long id);

/**
* 修改指定订单设置
*/
int update(Long id, OmsOrderSetting orderSetting);
}
OmsOrderSettingServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* 订单设置管理Service实现类
*/
@Service
public class OmsOrderSettingServiceImpl implements OmsOrderSettingService
{
@Resource
private OmsOrderSettingMapper orderSettingMapper;

@Override
public OmsOrderSetting getItem(Long id)
{
return orderSettingMapper.selectByPrimaryKey(id);
}

@Override
public int update(Long id, OmsOrderSetting orderSetting)
{
orderSetting.setId(id);
return orderSettingMapper.updateByPrimaryKey(orderSetting);
}
}

OmsOrderReturnApplyController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* 订单退货申请管理Controller
*/
@Controller
@Api(tags = "OmsOrderReturnApplyController")
@Tag(name = "OmsOrderReturnApplyController", description = "订单退货申请管理")
@RequestMapping("/returnApply")
public class OmsOrderReturnApplyController
{
@Resource
private OmsOrderReturnApplyService returnApplyService;

@ApiOperation("分页查询退货申请")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<OmsOrderReturnApply>> list(OmsReturnApplyQueryParam queryParam,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<OmsOrderReturnApply> returnApplyList = returnApplyService.list(queryParam, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(returnApplyList));
}

@ApiOperation("批量删除退货申请")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("ids") List<Long> ids)
{
int count = returnApplyService.delete(ids);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("获取退货申请详情")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult getItem(@PathVariable Long id)
{
OmsOrderReturnApplyResult result = returnApplyService.getItem(id);
return CommonResult.success(result);
}

@ApiOperation("修改退货申请状态")
@RequestMapping(value = "/update/status/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateStatus(@PathVariable Long id, @RequestBody OmsUpdateStatusParam statusParam)
{
int count = returnApplyService.updateStatus(id, statusParam);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}
}
OmsOrderReturnApplyService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* 退货申请管理Service
*/
public interface OmsOrderReturnApplyService
{
/**
* 分页查询申请
*/
List<OmsOrderReturnApply> list(OmsReturnApplyQueryParam queryParam, Integer pageSize, Integer pageNum);

/**
* 批量删除申请
*/
int delete(List<Long> ids);

/**
* 修改指定申请状态
*/
int updateStatus(Long id, OmsUpdateStatusParam statusParam);

/**
* 获取指定申请详情
*/
OmsOrderReturnApplyResult getItem(Long id);
}
OmsOrderReturnApplyServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* 订单退货管理Service实现类
*/
@Service
public class OmsOrderReturnApplyServiceImpl implements OmsOrderReturnApplyService
{
private static final Logger LOGGER = LoggerFactory.getLogger(OmsOrderReturnApplyServiceImpl.class);
@Resource
private OmsOrderReturnApplyDao returnApplyDao;
@Resource
private OmsOrderReturnApplyMapper returnApplyMapper;

@Override
public List<OmsOrderReturnApply> list(OmsReturnApplyQueryParam queryParam, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
return returnApplyDao.getList(queryParam);
}

@Override
public int delete(List<Long> ids)
{
OmsOrderReturnApplyExample example = new OmsOrderReturnApplyExample();
// 3 表示订单已拒绝
example.createCriteria().andIdIn(ids).andStatusEqualTo(3);
return returnApplyMapper.deleteByExample(example);
}

@Override
public int updateStatus(Long id, OmsUpdateStatusParam statusParam)
{
Integer status = statusParam.getStatus();
OmsOrderReturnApply returnApply = new OmsOrderReturnApply();

// TODO 这里不能改为 BeanUtils.copyProperties(statusParam, returnApply);?
if(status.equals(1)){
//确认退货
returnApply.setId(id);
returnApply.setStatus(1);
returnApply.setReturnAmount(statusParam.getReturnAmount());
returnApply.setCompanyAddressId(statusParam.getCompanyAddressId());
returnApply.setHandleTime(new Date());
returnApply.setHandleMan(statusParam.getHandleMan());
returnApply.setHandleNote(statusParam.getHandleNote());
} else if(status.equals(2)){
//完成退货
returnApply.setId(id);
returnApply.setStatus(2);
returnApply.setReceiveTime(new Date());
returnApply.setReceiveMan(statusParam.getReceiveMan());
returnApply.setReceiveNote(statusParam.getReceiveNote());
} else if(status.equals(3)){
//拒绝退货
returnApply.setId(id);
returnApply.setStatus(3);
returnApply.setHandleTime(new Date());
returnApply.setHandleMan(statusParam.getHandleMan());
returnApply.setHandleNote(statusParam.getHandleNote());
} else{
return 0;
}
// TODO 打印日志,看两个对象内容是否一致
// 这里应该可以直接换成下面的写法,因为只要status不一样就行,虽然多了一些无关信息
// 需要处理一下处理时间和收货时间
OmsOrderReturnApply returnApply1 = new OmsOrderReturnApply();
BeanUtils.copyProperties(statusParam, returnApply1);
Date date = new Date();
returnApply1.setId(id);
if(status.equals(1) || status.equals(3)){
returnApply1.setHandleTime(date);
}
if(status.equals(2)){
returnApply1.setReceiveTime(date);
}
LOGGER.info("OmsOrderReturnApplyServiceImpl returnApply = {}", returnApply);
LOGGER.info("OmsOrderReturnApplyServiceImpl returnApply1 = {}", returnApply1);
return returnApplyMapper.updateByPrimaryKeySelective(returnApply);
}

@Override
public OmsOrderReturnApplyResult getItem(Long id)
{
return returnApplyDao.getDetail(id);
}
}
OmsOrderReturnReasonController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* 退货原因管理Controller
*/
@Controller
@Api(tags = "OmsOrderReturnReasonController")
@Tag(name = "OmsOrderReturnReasonController", description = "退货原因管理")
@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController
{
@Resource
private OmsOrderReturnReasonService orderReturnReasonService;

@ApiOperation("添加退货原因")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody OmsOrderReturnReason returnReason)
{
int count = orderReturnReasonService.create(returnReason);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改退货原因")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody OmsOrderReturnReason returnReason)
{
int count = orderReturnReasonService.update(id, returnReason);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("批量删除退货原因")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("ids") List<Long> ids)
{
int count = orderReturnReasonService.delete(ids);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("分页查询退货原因")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<OmsOrderReturnReason>> list(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<OmsOrderReturnReason> reasonList = orderReturnReasonService.list(pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(reasonList));
}

@ApiOperation("获取单个退货原因详情信息")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<OmsOrderReturnReason> getItem(@PathVariable Long id)
{
OmsOrderReturnReason reason = orderReturnReasonService.getItem(id);
return CommonResult.success(reason);
}

@ApiOperation("修改退货原因启用状态")
@RequestMapping(value = "/update/status", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateStatus(@RequestParam(value = "status") Integer status,
@RequestParam("ids") List<Long> ids)
{
int count = orderReturnReasonService.updateStatus(ids, status);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}
}
OmsOrderReturnReasonService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* 退货原因管理Service
*/
public interface OmsOrderReturnReasonService
{
/**
* 添加退货原因
*/
int create(OmsOrderReturnReason returnReason);

/**
* 修改退货原因
*/
int update(Long id, OmsOrderReturnReason returnReason);

/**
* 批量删除退货原因
*/
int delete(List<Long> ids);

/**
* 分页获取退货原因
*/
List<OmsOrderReturnReason> list(Integer pageSize, Integer pageNum);

/**
* 批量修改退货原因状态
*/
int updateStatus(List<Long> ids, Integer status);

/**
* 获取单个退货原因详情信息
*/
OmsOrderReturnReason getItem(Long id);
}
OmsOrderReturnReasonServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* 订单原因管理Service实现类
*/
@Service
public class OmsOrderReturnReasonServiceImpl implements OmsOrderReturnReasonService
{
@Resource
private OmsOrderReturnReasonMapper returnReasonMapper;

@Override
public int create(OmsOrderReturnReason returnReason)
{
returnReason.setCreateTime(new Date());
return returnReasonMapper.insert(returnReason);
}

@Override
public int update(Long id, OmsOrderReturnReason returnReason)
{
returnReason.setId(id);
return returnReasonMapper.updateByPrimaryKey(returnReason);
}

@Override
public int delete(List<Long> ids)
{
OmsOrderReturnReasonExample example = new OmsOrderReturnReasonExample();
example.createCriteria().andIdIn(ids);
return returnReasonMapper.deleteByExample(example);
}

@Override
public List<OmsOrderReturnReason> list(Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
OmsOrderReturnReasonExample example = new OmsOrderReturnReasonExample();
example.setOrderByClause("sort desc");
return returnReasonMapper.selectByExample(example);
}

@Override
public int updateStatus(List<Long> ids, Integer status)
{
if(!status.equals(0) && !status.equals(1)){
return 0;
}
OmsOrderReturnReason record = new OmsOrderReturnReason();
record.setStatus(status);
OmsOrderReturnReasonExample example = new OmsOrderReturnReasonExample();
example.createCriteria().andIdIn(ids);
return returnReasonMapper.updateByExampleSelective(record, example);
}

@Override
public OmsOrderReturnReason getItem(Long id)
{
return returnReasonMapper.selectByPrimaryKey(id);
}
}

营销模块相关表分析,sms_*

my_sms
sms_*相关表分析
  • sms_coupon表为优惠券表
  • sms_coupon_history表为优惠券使用、领取历史表,其中coupon_id字段为表sms_coupon的字段
  • sms_coupon_product_relation表为优惠券和产品的关系表,其中coupon_id字段为表sms_coupon的字段
  • sms_coupon_product_category_relation表为优惠券和产品分类关系表,其中coupon_id字段为表sms_coupon的字段
  • sms_flash_promotion_product_relation表为商品限时购与商品关系表,其中flash_promotion_id字段为表sms_flash_promotion的外键、flash_promotion_session_id字段为表sms_flash_promotion_session的外键
  • sms_flash_promotion表为限时购表
  • sms_flash_promotion_session表为限时购场次表
  • sms_flash_promotion_log表为限时购通知记录
  • sms_home_recommend_product表为人气推荐商品表
  • sms_home_brand表为首页推荐品牌表
  • sms_home_recommend_subject表为首页推荐专题表
  • sms_home_new_product表为新鲜好物表
  • sms_home_advertise表为首页轮播广告表

营销相关接口设计

SmsCouponController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* 优惠券管理Controller
*/
@Controller
@Api(tags = "SmsCouponController")
@Tag(name = "SmsCouponController", description = "优惠券管理")
@RequestMapping("/coupon")
public class SmsCouponController
{
@Resource
private SmsCouponService couponService;

@ApiOperation("添加优惠券")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult add(@RequestBody SmsCouponParam couponParam)
{
int count = couponService.create(couponParam);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("删除优惠券")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id)
{
int count = couponService.delete(id);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改优惠券")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody SmsCouponParam couponParam)
{
int count = couponService.update(id, couponParam);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("根据优惠券名称和类型分页获取优惠券列表")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<SmsCoupon>> list(@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "type", required = false) Integer type,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<SmsCoupon> couponList = couponService.list(name, type, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(couponList));
}

@ApiOperation("获取单个优惠券的详细信息")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<SmsCouponParam> getItem(@PathVariable Long id)
{
SmsCouponParam couponParam = couponService.getItem(id);
return CommonResult.success(couponParam);
}
}
SmsCouponService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* 优惠券管理Service
*/
public interface SmsCouponService
{
/**
* 添加优惠券
*/
@Transactional
int create(SmsCouponParam couponParam);

/**
* 根据优惠券id删除优惠券
*/
@Transactional
int delete(Long id);

/**
* 根据优惠券id更新优惠券信息
*/
@Transactional
int update(Long id, SmsCouponParam couponParam);

/**
* 分页获取优惠券列表
*/
List<SmsCoupon> list(String name, Integer type, Integer pageSize, Integer pageNum);

/**
* 获取优惠券详情
* @param id 优惠券表id
*/
SmsCouponParam getItem(Long id);
}
SmsCouponServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* 优惠券管理Service实现类
*/
@Service
public class SmsCouponServiceImpl implements SmsCouponService
{
@Resource
private SmsCouponMapper couponMapper;
@Resource
private SmsCouponProductRelationMapper productRelationMapper;
@Resource
private SmsCouponProductCategoryRelationMapper productCategoryRelationMapper;
@Resource
private SmsCouponProductRelationDao productRelationDao;
@Resource
private SmsCouponProductCategoryRelationDao productCategoryRelationDao;
@Resource
private SmsCouponDao couponDao;

@Override
public int create(SmsCouponParam couponParam)
{
// 创建优惠券时的发行数量和实际数量相等
couponParam.setCount(couponParam.getPublishCount());
couponParam.setUseCount(0);
couponParam.setReceiveCount(0);
//插入优惠券表
int count = couponMapper.insert(couponParam);
//插入优惠券和商品关系表
// 如果优惠券是指定商品的需要建立关系
if(couponParam.getUseType().equals(2)){
for(SmsCouponProductRelation productRelation : couponParam.getProductRelationList()){
productRelation.setCouponId(couponParam.getId());
}
productRelationDao.insertList(couponParam.getProductRelationList());
}
//插入优惠券和商品分类关系表
// 如果优惠券是指定分类商品
if(couponParam.getUseType().equals(1)){
for(SmsCouponProductCategoryRelation couponProductCategoryRelation : couponParam.getProductCategoryRelationList()){
couponProductCategoryRelation.setCouponId(couponParam.getId());
}
productCategoryRelationDao.insertList(couponParam.getProductCategoryRelationList());
}
return count;
}

@Override
public int delete(Long id)
{
//删除优惠券
int count = couponMapper.deleteByPrimaryKey(id);
//删除商品关联
deleteProductRelation(id);
//删除商品分类关联
deleteProductCategoryRelation(id);
return count;
}

private void deleteProductCategoryRelation(Long id)
{
SmsCouponProductCategoryRelationExample productCategoryRelationExample =
new SmsCouponProductCategoryRelationExample();
productCategoryRelationExample.createCriteria().andCouponIdEqualTo(id);
productCategoryRelationMapper.deleteByExample(productCategoryRelationExample);
}

private void deleteProductRelation(Long id)
{
SmsCouponProductRelationExample productRelationExample = new SmsCouponProductRelationExample();
productRelationExample.createCriteria().andCouponIdEqualTo(id);
productRelationMapper.deleteByExample(productRelationExample);
}

@Override
public int update(Long id, SmsCouponParam couponParam)
{
couponParam.setId(id);
int count = couponMapper.updateByPrimaryKey(couponParam);
//删除后原先的关系,插入新的优惠券和商品关系表
if(couponParam.getUseType().equals(2)){
for(SmsCouponProductRelation productRelation : couponParam.getProductRelationList()){
productRelation.setCouponId(couponParam.getId());
}
deleteProductRelation(id);
productRelationDao.insertList(couponParam.getProductRelationList());
}
//删除后插入优惠券和商品分类关系表
if(couponParam.getUseType().equals(1)){
for(SmsCouponProductCategoryRelation couponProductCategoryRelation : couponParam.getProductCategoryRelationList()){
couponProductCategoryRelation.setCouponId(couponParam.getId());
}
deleteProductCategoryRelation(id);
productCategoryRelationDao.insertList(couponParam.getProductCategoryRelationList());
}
return count;
}

@Override
public List<SmsCoupon> list(String name, Integer type, Integer pageSize, Integer pageNum)
{
SmsCouponExample example = new SmsCouponExample();
SmsCouponExample.Criteria criteria = example.createCriteria();
if(!StrUtil.isEmpty(name)){
criteria.andNameLike("%" + name + "%");
}
if(type != null){
criteria.andTypeEqualTo(type);
}
PageHelper.startPage(pageNum, pageSize);
return couponMapper.selectByExample(example);
}

@Override
public SmsCouponParam getItem(Long id)
{
return couponDao.getItem(id);
}
}
SmsCouponHistoryController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**
* 优惠券领取记录管理Controller
*/
@Controller
@Api(tags = "SmsCouponHistoryController")
@Tag(name = "SmsCouponHistoryController", description = "优惠券领取记录管理")
@RequestMapping("/couponHistory")
public class SmsCouponHistoryController
{
@Resource
private SmsCouponHistoryService historyService;

@ApiOperation("根据优惠券id,使用状态,订单编号分页获取领取记录")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<SmsCouponHistory>> list(
@RequestParam(value = "couponId", required = false) Long couponId,
@RequestParam(value = "useStatus", required = false) Integer useStatus,
@RequestParam(value = "orderSn", required = false) String orderSn,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<SmsCouponHistory> historyList = historyService.list(couponId, useStatus, orderSn, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(historyList));
}
}
SmsCouponHistoryService
1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* 优惠券领取记录管理Service
*/
public interface SmsCouponHistoryService
{
/**
* 分页查询优惠券领取记录
* @param couponId 优惠券id
* @param useStatus 使用状态
* @param orderSn 使用订单号码
*/
List<SmsCouponHistory> list(Long couponId, Integer useStatus, String orderSn, Integer pageSize, Integer pageNum);
}
SmsCouponHistoryServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* 优惠券领取记录管理Service实现类
*/
@Service
public class SmsCouponHistoryServiceImpl implements SmsCouponHistoryService
{
@Resource
private SmsCouponHistoryMapper historyMapper;

@Override
public List<SmsCouponHistory> list(Long couponId, Integer useStatus, String orderSn, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
SmsCouponHistoryExample example = new SmsCouponHistoryExample();
SmsCouponHistoryExample.Criteria criteria = example.createCriteria();
if(couponId != null){
criteria.andCouponIdEqualTo(couponId);
}
if(useStatus != null){
criteria.andUseStatusEqualTo(useStatus);
}
if(!StrUtil.isEmpty(orderSn)){
criteria.andOrderSnEqualTo(orderSn);
}
return historyMapper.selectByExample(example);
}
}
SmsFlashPromotionController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* 限时购活动管理Controller
*/
@Controller
@Api(tags = "SmsFlashPromotionController")
@Tag(name = "SmsFlashPromotionController", description = "限时购活动管理")
@RequestMapping("/flash")
public class SmsFlashPromotionController
{
@Resource
private SmsFlashPromotionService flashPromotionService;

@ApiOperation("添加活动")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody SmsFlashPromotion flashPromotion)
{
int count = flashPromotionService.create(flashPromotion);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("编辑活动")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public Object update(@PathVariable Long id, @RequestBody SmsFlashPromotion flashPromotion)
{
int count = flashPromotionService.update(id, flashPromotion);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("删除活动")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public Object delete(@PathVariable Long id)
{
int count = flashPromotionService.delete(id);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改上下线状态")
@RequestMapping(value = "/update/status/{id}", method = RequestMethod.POST)
@ResponseBody
public Object update(@PathVariable Long id, Integer status)
{
int count = flashPromotionService.updateStatus(id, status);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("获取活动详情")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public Object getItem(@PathVariable Long id)
{
SmsFlashPromotion flashPromotion = flashPromotionService.getItem(id);
return CommonResult.success(flashPromotion);
}

@ApiOperation("根据活动名称分页查询")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public Object getItem(@RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<SmsFlashPromotion> flashPromotionList = flashPromotionService.list(keyword, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(flashPromotionList));
}
}
SmsFlashPromotionService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* 限时购活动管理Service
*/
public interface SmsFlashPromotionService
{
/**
* 添加活动
*/
int create(SmsFlashPromotion flashPromotion);

/**
* 修改指定活动
*/
int update(Long id, SmsFlashPromotion flashPromotion);

/**
* 删除单个活动
*/
int delete(Long id);

/**
* 修改上下线状态
*/
int updateStatus(Long id, Integer status);

/**
* 获取活动详情
*/
SmsFlashPromotion getItem(Long id);

/**
* 分页查询活动
*/
List<SmsFlashPromotion> list(String keyword, Integer pageSize, Integer pageNum);
}
SmsFlashPromotionServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* 限时购活动管理Service实现类
*/
@Service
public class SmsFlashPromotionServiceImpl implements SmsFlashPromotionService
{
@Resource
private SmsFlashPromotionMapper flashPromotionMapper;

@Override
public int create(SmsFlashPromotion flashPromotion)
{
flashPromotion.setCreateTime(new Date());
return flashPromotionMapper.insert(flashPromotion);
}

@Override
public int update(Long id, SmsFlashPromotion flashPromotion)
{
flashPromotion.setId(id);
return flashPromotionMapper.updateByPrimaryKey(flashPromotion);
}

@Override
public int delete(Long id)
{
return flashPromotionMapper.deleteByPrimaryKey(id);
}

@Override
public int updateStatus(Long id, Integer status)
{
SmsFlashPromotion flashPromotion = new SmsFlashPromotion();
flashPromotion.setId(id);
flashPromotion.setStatus(status);
return flashPromotionMapper.updateByPrimaryKeySelective(flashPromotion);
}

@Override
public SmsFlashPromotion getItem(Long id)
{
return flashPromotionMapper.selectByPrimaryKey(id);
}

@Override
public List<SmsFlashPromotion> list(String keyword, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
SmsFlashPromotionExample example = new SmsFlashPromotionExample();
if(!StrUtil.isEmpty(keyword)){
example.createCriteria().andTitleLike("%" + keyword + "%");
}
return flashPromotionMapper.selectByExample(example);
}
}
SmsFlashPromotionProductRelationController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* 限时购和商品关系管理Controller
*/
@Controller
@Api(tags = "SmsFlashPromotionProductRelationController")
@Tag(name = "SmsFlashPromotionProductRelationController", description = "限时购和商品关系管理")
@RequestMapping("/flashProductRelation")
public class SmsFlashPromotionProductRelationController
{
@Resource
private SmsFlashPromotionProductRelationService relationService;

@ApiOperation("批量选择商品添加关联")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody List<SmsFlashPromotionProductRelation> relationList)
{
int count = relationService.create(relationList);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改关联信息")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody SmsFlashPromotionProductRelation relation)
{
int count = relationService.update(id, relation);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("删除关联")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id)
{
int count = relationService.delete(id);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("获取管理商品促销信息")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<SmsFlashPromotionProductRelation> getItem(@PathVariable Long id)
{
SmsFlashPromotionProductRelation relation = relationService.getItem(id);
return CommonResult.success(relation);
}

@ApiOperation("分页查询不同场次关联及商品信息")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<SmsFlashPromotionProduct>> list(
@RequestParam(value = "flashPromotionId") Long flashPromotionId,
@RequestParam(value = "flashPromotionSessionId") Long flashPromotionSessionId,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<SmsFlashPromotionProduct> flashPromotionProductList =
relationService.list(flashPromotionId, flashPromotionSessionId, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(flashPromotionProductList));
}
}
SmsFlashPromotionProductRelationService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* 限时购商品关联管理Service
*/
public interface SmsFlashPromotionProductRelationService
{
/**
* 批量添加关联
*/
@Transactional
int create(List<SmsFlashPromotionProductRelation> relationList);

/**
* 修改关联信息
*/
int update(Long id, SmsFlashPromotionProductRelation relation);

/**
* 删除关联
*/
int delete(Long id);

/**
* 获取关联详情
*/
SmsFlashPromotionProductRelation getItem(Long id);

/**
* 分页查询相关商品及限时购促销信息
* @param flashPromotionId 限时购id
* @param flashPromotionSessionId 限时购场次id
*/
List<SmsFlashPromotionProduct> list(Long flashPromotionId, Long flashPromotionSessionId, Integer pageSize, Integer pageNum);

/**
* 根据活动和场次id获取商品关系数量
* @param flashPromotionId 限时购id
* @param flashPromotionSessionId 限时购场次id
*/
long getCount(Long flashPromotionId, Long flashPromotionSessionId);
}
SmsFlashPromotionProductRelationServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* 限时购商品关联管理Service实现类
*/
@Service
public class SmsFlashPromotionProductRelationServiceImpl implements SmsFlashPromotionProductRelationService
{
@Resource
private SmsFlashPromotionProductRelationMapper relationMapper;
@Resource
private SmsFlashPromotionProductRelationDao relationDao;

@Override
public int create(List<SmsFlashPromotionProductRelation> relationList)
{
for(SmsFlashPromotionProductRelation relation : relationList){
relationMapper.insert(relation);
}
return relationList.size();
}

@Override
public int update(Long id, SmsFlashPromotionProductRelation relation)
{
relation.setId(id);
return relationMapper.updateByPrimaryKey(relation);
}

@Override
public int delete(Long id)
{
return relationMapper.deleteByPrimaryKey(id);
}

@Override
public SmsFlashPromotionProductRelation getItem(Long id)
{
return relationMapper.selectByPrimaryKey(id);
}

@Override
public List<SmsFlashPromotionProduct> list(Long flashPromotionId, Long flashPromotionSessionId, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
return relationDao.getList(flashPromotionId, flashPromotionSessionId);
}

@Override
public long getCount(Long flashPromotionId, Long flashPromotionSessionId)
{
SmsFlashPromotionProductRelationExample example = new SmsFlashPromotionProductRelationExample();
example.createCriteria().andFlashPromotionIdEqualTo(flashPromotionId)
.andFlashPromotionSessionIdEqualTo(flashPromotionSessionId);
return relationMapper.countByExample(example);
}
}
SmsFlashPromotionSessionController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* 限时购场次管理Controller
*/
@Controller
@Api(tags = "SmsFlashPromotionSessionController")
@Tag(name = "SmsFlashPromotionSessionController", description = "限时购场次管理")
@RequestMapping("/flashSession")
public class SmsFlashPromotionSessionController
{
@Resource
private SmsFlashPromotionSessionService flashPromotionSessionService;

@ApiOperation("添加场次")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody SmsFlashPromotionSession promotionSession)
{
int count = flashPromotionSessionService.create(promotionSession);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改场次")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody SmsFlashPromotionSession promotionSession)
{
int count = flashPromotionSessionService.update(id, promotionSession);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改启用状态")
@RequestMapping(value = "/update/status/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateStatus(@PathVariable Long id, Integer status)
{
int count = flashPromotionSessionService.updateStatus(id, status);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("删除场次")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id)
{
int count = flashPromotionSessionService.delete(id);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("获取场次详情")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<SmsFlashPromotionSession> getItem(@PathVariable Long id)
{
SmsFlashPromotionSession promotionSession = flashPromotionSessionService.getItem(id);
return CommonResult.success(promotionSession);
}

@ApiOperation("获取全部场次")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<SmsFlashPromotionSession>> list()
{
List<SmsFlashPromotionSession> promotionSessionList = flashPromotionSessionService.list();
return CommonResult.success(promotionSessionList);
}

@ApiOperation("获取全部可选场次及其数量")
@RequestMapping(value = "/selectList", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<SmsFlashPromotionSessionDetail>> selectList(Long flashPromotionId)
{
List<SmsFlashPromotionSessionDetail> promotionSessionList =
flashPromotionSessionService.selectList(flashPromotionId);
return CommonResult.success(promotionSessionList);
}
}
SmsFlashPromotionSessionService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* 限时购场次管理Service
*/
public interface SmsFlashPromotionSessionService
{
/**
* 添加场次
*/
int create(SmsFlashPromotionSession promotionSession);

/**
* 修改场次
*/
int update(Long id, SmsFlashPromotionSession promotionSession);

/**
* 修改场次启用状态
*/
int updateStatus(Long id, Integer status);

/**
* 删除场次
*/
int delete(Long id);

/**
* 获取详情
*/
SmsFlashPromotionSession getItem(Long id);

/**
* 根据启用状态获取场次列表
*/
List<SmsFlashPromotionSession> list();

/**
* 获取全部可选场次及其数量
*/
List<SmsFlashPromotionSessionDetail> selectList(Long flashPromotionId);
}
SmsFlashPromotionSessionServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* 限时购场次管理Service实现类
*/
@Service
public class SmsFlashPromotionSessionServiceImpl implements SmsFlashPromotionSessionService
{
@Resource
private SmsFlashPromotionSessionMapper promotionSessionMapper;
@Resource
private SmsFlashPromotionProductRelationService relationService;

@Override
public int create(SmsFlashPromotionSession promotionSession)
{
promotionSession.setCreateTime(new Date());
return promotionSessionMapper.insert(promotionSession);
}

@Override
public int update(Long id, SmsFlashPromotionSession promotionSession)
{
promotionSession.setId(id);
return promotionSessionMapper.updateByPrimaryKey(promotionSession);
}

@Override
public int updateStatus(Long id, Integer status)
{
SmsFlashPromotionSession promotionSession = new SmsFlashPromotionSession();
promotionSession.setId(id);
promotionSession.setStatus(status);
return promotionSessionMapper.updateByPrimaryKeySelective(promotionSession);
}

@Override
public int delete(Long id)
{
return promotionSessionMapper.deleteByPrimaryKey(id);
}

@Override
public SmsFlashPromotionSession getItem(Long id)
{
return promotionSessionMapper.selectByPrimaryKey(id);
}

@Override
public List<SmsFlashPromotionSession> list()
{
SmsFlashPromotionSessionExample example = new SmsFlashPromotionSessionExample();
return promotionSessionMapper.selectByExample(example);
}

private static final Logger LOGGER = LoggerFactory.getLogger(SmsFlashPromotionSessionServiceImpl.class);

@Override
public List<SmsFlashPromotionSessionDetail> selectList(Long flashPromotionId)
{
SmsFlashPromotionSessionExample example = new SmsFlashPromotionSessionExample();
// 查询出启用的场次
example.createCriteria().andStatusEqualTo(1);
List<SmsFlashPromotionSession> list = promotionSessionMapper.selectByExample(example);

// 原始写法
// List<SmsFlashPromotionSessionDetail> result = new ArrayList<>();
// list.forEach(promotionSession -> {
// SmsFlashPromotionSessionDetail detail = new SmsFlashPromotionSessionDetail();
// BeanUtils.copyProperties(promotionSession, detail);
// // 查询商品数量
// long count = relationService.getCount(flashPromotionId, promotionSession.getId());
// detail.setProductCount(count);
// result.add(detail);
// });

List<SmsFlashPromotionSessionDetail> result =
list.stream()
.map(smsFlashPromotionSession -> {
SmsFlashPromotionSessionDetail detail = new SmsFlashPromotionSessionDetail();
BeanUtils.copyProperties(smsFlashPromotionSession, detail);
// 查询商品数量
long count = relationService.getCount(flashPromotionId, smsFlashPromotionSession.getId());
detail.setProductCount(count);
return detail;
})
.collect(Collectors.toList());
// TODO 打印日志,看list和list1是否一致
// LOGGER.info("SmsFlashPromotionSessionServiceImpl list = {}", result);
// LOGGER.info("SmsFlashPromotionSessionServiceImpl list1 = {}", result1);
return result;
}
}
SmsHomeAdvertiseController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* 首页轮播广告管理Controller
*/
@Controller
@Api(tags = "SmsHomeAdvertiseController")
@Tag(name = "SmsHomeAdvertiseController", description = "首页轮播广告管理")
@RequestMapping("/home/advertise")
public class SmsHomeAdvertiseController
{
@Resource
private SmsHomeAdvertiseService advertiseService;

@ApiOperation("添加广告")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody SmsHomeAdvertise advertise)
{
int count = advertiseService.create(advertise);
if(count > 0) return CommonResult.success(count);
return CommonResult.failed();
}

@ApiOperation("删除广告")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("ids") List<Long> ids)
{
int count = advertiseService.delete(ids);
if(count > 0) return CommonResult.success(count);
return CommonResult.failed();
}

@ApiOperation("修改上下线状态")
@RequestMapping(value = "/update/status/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateStatus(@PathVariable Long id, Integer status)
{
int count = advertiseService.updateStatus(id, status);
if(count > 0) return CommonResult.success(count);
return CommonResult.failed();
}

@ApiOperation("获取广告详情")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<SmsHomeAdvertise> getItem(@PathVariable Long id)
{
SmsHomeAdvertise advertise = advertiseService.getItem(id);
return CommonResult.success(advertise);
}

@ApiOperation("修改广告")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(@PathVariable Long id, @RequestBody SmsHomeAdvertise advertise)
{
int count = advertiseService.update(id, advertise);
if(count > 0) return CommonResult.success(count);
return CommonResult.failed();
}

@ApiOperation("分页查询广告")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<SmsHomeAdvertise>> list(@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "type", required = false) Integer type,
@RequestParam(value = "endTime", required = false) String endTime,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<SmsHomeAdvertise> advertiseList = advertiseService.list(name, type, endTime, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(advertiseList));
}
}
SmsHomeAdvertiseService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* 首页广告管理Service
*/
public interface SmsHomeAdvertiseService
{
/**
* 添加广告
*/
int create(SmsHomeAdvertise advertise);

/**
* 批量删除广告
*/
int delete(List<Long> ids);

/**
* 修改上、下线状态
*/
int updateStatus(Long id, Integer status);

/**
* 获取广告详情
*/
SmsHomeAdvertise getItem(Long id);

/**
* 更新广告
*/
int update(Long id, SmsHomeAdvertise advertise);

/**
* 分页查询广告
*/
List<SmsHomeAdvertise> list(String name, Integer type, String endTime, Integer pageSize, Integer pageNum);
}
SmsHomeAdvertiseServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* 首页广告管理Service实现类
*/
@Service
public class SmsHomeAdvertiseServiceImpl implements SmsHomeAdvertiseService
{
@Resource
private SmsHomeAdvertiseMapper advertiseMapper;

@Override
public int create(SmsHomeAdvertise advertise)
{
advertise.setClickCount(0);
advertise.setOrderCount(0);
return advertiseMapper.insert(advertise);
}

@Override
public int delete(List<Long> ids)
{
SmsHomeAdvertiseExample example = new SmsHomeAdvertiseExample();
example.createCriteria().andIdIn(ids);
return advertiseMapper.deleteByExample(example);
}

@Override
public int updateStatus(Long id, Integer status)
{
SmsHomeAdvertise record = new SmsHomeAdvertise();
record.setId(id);
record.setStatus(status);
return advertiseMapper.updateByPrimaryKeySelective(record);
}

@Override
public SmsHomeAdvertise getItem(Long id)
{
return advertiseMapper.selectByPrimaryKey(id);
}

@Override
public int update(Long id, SmsHomeAdvertise advertise)
{
advertise.setId(id);
return advertiseMapper.updateByPrimaryKeySelective(advertise);
}

@Override
public List<SmsHomeAdvertise> list(String name, Integer type, String endTime, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
SmsHomeAdvertiseExample example = new SmsHomeAdvertiseExample();
SmsHomeAdvertiseExample.Criteria criteria = example.createCriteria();
if(!StrUtil.isEmpty(name)){
criteria.andNameLike("%" + name + "%");
}
if(type != null){
criteria.andTypeEqualTo(type);
}
if(!StrUtil.isEmpty(endTime)){
// TODO 这里可以优化吗?
String startStr = endTime + " 00:00:00";
String endStr = endTime + " 23:59:59";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date start = null;
try{
start = sdf.parse(startStr);
} catch(ParseException e){
e.printStackTrace();
}
Date end = null;
try{
end = sdf.parse(endStr);
} catch(ParseException e){
e.printStackTrace();
}
if(start != null && end != null){
criteria.andEndTimeBetween(start, end);
}
}
example.setOrderByClause("sort desc");
return advertiseMapper.selectByExample(example);
}
}
SmsHomeBrandController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* 首页品牌管理Controller
*/
@Controller
@Api(tags = "SmsHomeBrandController")
@Tag(name = "SmsHomeBrandController", description = "首页品牌管理")
@RequestMapping("/home/brand")
public class SmsHomeBrandController
{
@Resource
private SmsHomeBrandService homeBrandService;

@ApiOperation("添加首页推荐品牌")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody List<SmsHomeBrand> homeBrandList)
{
int count = homeBrandService.create(homeBrandList);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改推荐品牌排序")
@RequestMapping(value = "/update/sort/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateSort(@PathVariable Long id, Integer sort)
{
int count = homeBrandService.updateSort(id, sort);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("批量删除推荐品牌")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("ids") List<Long> ids)
{
int count = homeBrandService.delete(ids);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("批量修改推荐品牌状态")
@RequestMapping(value = "/update/recommendStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateRecommendStatus(@RequestParam("ids") List<Long> ids,
@RequestParam Integer recommendStatus)
{
int count = homeBrandService.updateRecommendStatus(ids, recommendStatus);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("分页查询推荐品牌")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<SmsHomeBrand>> list(
@RequestParam(value = "brandName", required = false) String brandName,
@RequestParam(value = "recommendStatus", required = false) Integer recommendStatus,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<SmsHomeBrand> homeBrandList = homeBrandService.list(brandName, recommendStatus, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(homeBrandList));
}
}
SmsHomeBrandService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* 首页品牌管理Service
*/
public interface SmsHomeBrandService
{
/**
* 添加首页品牌推荐
*/
@Transactional
int create(List<SmsHomeBrand> homeBrandList);

/**
* 修改品牌推荐排序
*/
int updateSort(Long id, Integer sort);

/**
* 批量删除品牌推荐
*/
int delete(List<Long> ids);

/**
* 批量更新推荐状态
*/
int updateRecommendStatus(List<Long> ids, Integer recommendStatus);

/**
* 分页查询品牌推荐
*/
List<SmsHomeBrand> list(String brandName, Integer recommendStatus, Integer pageSize, Integer pageNum);
}
SmsHomeBrandServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* 首页品牌管理Service实现类
*/
@Service
public class SmsHomeBrandServiceImpl implements SmsHomeBrandService
{
@Resource
private SmsHomeBrandMapper homeBrandMapper;

@Override
public int create(List<SmsHomeBrand> homeBrandList)
{
for(SmsHomeBrand smsHomeBrand : homeBrandList){
smsHomeBrand.setRecommendStatus(1);
smsHomeBrand.setSort(0);
homeBrandMapper.insert(smsHomeBrand);
}
return homeBrandList.size();
}

@Override
public int updateSort(Long id, Integer sort)
{
SmsHomeBrand homeBrand = new SmsHomeBrand();
homeBrand.setId(id);
homeBrand.setSort(sort);
return homeBrandMapper.updateByPrimaryKeySelective(homeBrand);
}

@Override
public int delete(List<Long> ids)
{
SmsHomeBrandExample example = new SmsHomeBrandExample();
example.createCriteria().andIdIn(ids);
return homeBrandMapper.deleteByExample(example);
}

@Override
public int updateRecommendStatus(List<Long> ids, Integer recommendStatus)
{
SmsHomeBrandExample example = new SmsHomeBrandExample();
example.createCriteria().andIdIn(ids);
SmsHomeBrand record = new SmsHomeBrand();
record.setRecommendStatus(recommendStatus);
return homeBrandMapper.updateByExampleSelective(record, example);
}

@Override
public List<SmsHomeBrand> list(String brandName, Integer recommendStatus, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
SmsHomeBrandExample example = new SmsHomeBrandExample();
SmsHomeBrandExample.Criteria criteria = example.createCriteria();
if(!StrUtil.isEmpty(brandName)){
criteria.andBrandNameLike("%" + brandName + "%");
}
if(recommendStatus != null){
criteria.andRecommendStatusEqualTo(recommendStatus);
}
example.setOrderByClause("sort desc");
return homeBrandMapper.selectByExample(example);
}
}
SmsHomeNewProductController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* 首页新品管理Controller
*/
@Controller
@Api(tags = "SmsHomeNewProductController")
@Tag(name = "SmsHomeNewProductController", description = "首页新品管理")
@RequestMapping("/home/newProduct")
public class SmsHomeNewProductController
{
@Resource
private SmsHomeNewProductService homeNewProductService;

@ApiOperation("添加首页新品")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody List<SmsHomeNewProduct> homeNewProductList)
{
int count = homeNewProductService.create(homeNewProductList);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改首页新品排序")
@RequestMapping(value = "/update/sort/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateSort(@PathVariable Long id, Integer sort)
{
int count = homeNewProductService.updateSort(id, sort);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("批量删除首页新品")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("ids") List<Long> ids)
{
int count = homeNewProductService.delete(ids);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("批量修改首页新品状态")
@RequestMapping(value = "/update/recommendStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateRecommendStatus(@RequestParam("ids") List<Long> ids,
@RequestParam Integer recommendStatus)
{
int count = homeNewProductService.updateRecommendStatus(ids, recommendStatus);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("分页查询首页新品")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<SmsHomeNewProduct>> list(
@RequestParam(value = "productName", required = false) String productName,
@RequestParam(value = "recommendStatus", required = false) Integer recommendStatus,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<SmsHomeNewProduct> homeNewProductList =
homeNewProductService.list(productName, recommendStatus, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(homeNewProductList));
}
}
SmsHomeNewProductService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* 首页新品推荐管理Service
*/
public interface SmsHomeNewProductService
{
/**
* 添加首页推荐
*/
@Transactional
int create(List<SmsHomeNewProduct> homeNewProductList);

/**
* 修改推荐排序
*/
int updateSort(Long id, Integer sort);

/**
* 批量删除推荐
*/
int delete(List<Long> ids);

/**
* 批量更新推荐状态
*/
int updateRecommendStatus(List<Long> ids, Integer recommendStatus);

/**
* 分页查询推荐
*/
List<SmsHomeNewProduct> list(String productName, Integer recommendStatus, Integer pageSize, Integer pageNum);
}
SmsHomeNewProductServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* 首页新品推荐管理Service实现类
*/
@Service
public class SmsHomeNewProductServiceImpl implements SmsHomeNewProductService
{
@Resource
private SmsHomeNewProductMapper homeNewProductMapper;

@Override
public int create(List<SmsHomeNewProduct> homeNewProductList)
{
for(SmsHomeNewProduct SmsHomeNewProduct : homeNewProductList){
SmsHomeNewProduct.setRecommendStatus(1);
SmsHomeNewProduct.setSort(0);
homeNewProductMapper.insert(SmsHomeNewProduct);
}
return homeNewProductList.size();
}

@Override
public int updateSort(Long id, Integer sort)
{
SmsHomeNewProduct homeNewProduct = new SmsHomeNewProduct();
homeNewProduct.setId(id);
homeNewProduct.setSort(sort);
return homeNewProductMapper.updateByPrimaryKeySelective(homeNewProduct);
}

@Override
public int delete(List<Long> ids)
{
SmsHomeNewProductExample example = new SmsHomeNewProductExample();
example.createCriteria().andIdIn(ids);
return homeNewProductMapper.deleteByExample(example);
}

@Override
public int updateRecommendStatus(List<Long> ids, Integer recommendStatus)
{
SmsHomeNewProductExample example = new SmsHomeNewProductExample();
example.createCriteria().andIdIn(ids);
SmsHomeNewProduct record = new SmsHomeNewProduct();
record.setRecommendStatus(recommendStatus);
return homeNewProductMapper.updateByExampleSelective(record, example);
}

@Override
public List<SmsHomeNewProduct> list(String productName, Integer recommendStatus, Integer pageSize, Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
SmsHomeNewProductExample example = new SmsHomeNewProductExample();
SmsHomeNewProductExample.Criteria criteria = example.createCriteria();
if(!StrUtil.isEmpty(productName)){
criteria.andProductNameLike("%" + productName + "%");
}
if(recommendStatus != null){
criteria.andRecommendStatusEqualTo(recommendStatus);
}
example.setOrderByClause("sort desc");
return homeNewProductMapper.selectByExample(example);
}
}
SmsHomeRecommendProductController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* 首页人气推荐管理Controller
*/
@Controller
@Api(tags = "SmsHomeRecommendProductController")
@Tag(name = "SmsHomeRecommendProductController", description = "首页人气推荐管理")
@RequestMapping("/home/recommendProduct")
public class SmsHomeRecommendProductController
{
@Resource
private SmsHomeRecommendProductService recommendProductService;

@ApiOperation("添加首页推荐")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody List<SmsHomeRecommendProduct> homeRecommendProductList)
{
int count = recommendProductService.create(homeRecommendProductList);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改推荐排序")
@RequestMapping(value = "/update/sort/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateSort(@PathVariable Long id, Integer sort)
{
int count = recommendProductService.updateSort(id, sort);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("批量删除推荐")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("ids") List<Long> ids)
{
int count = recommendProductService.delete(ids);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("批量修改推荐状态")
@RequestMapping(value = "/update/recommendStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateRecommendStatus(@RequestParam("ids") List<Long> ids,
@RequestParam Integer recommendStatus)
{
int count = recommendProductService.updateRecommendStatus(ids, recommendStatus);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("分页查询推荐")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<SmsHomeRecommendProduct>> list(
@RequestParam(value = "productName", required = false) String productName,
@RequestParam(value = "recommendStatus", required = false) Integer recommendStatus,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<SmsHomeRecommendProduct> homeRecommendProductList =
recommendProductService.list(productName, recommendStatus, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(homeRecommendProductList));
}
}
SmsHomeRecommendProductService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* 首页人气推荐管理Service
*/
public interface SmsHomeRecommendProductService
{
/**
* 添加首页推荐
*/
@Transactional
int create(List<SmsHomeRecommendProduct> homeRecommendProductList);

/**
* 修改推荐排序
*/
int updateSort(Long id, Integer sort);

/**
* 批量删除推荐
*/
int delete(List<Long> ids);

/**
* 批量更新推荐状态
*/
int updateRecommendStatus(List<Long> ids, Integer recommendStatus);

/**
* 分页查询推荐
*/
List<SmsHomeRecommendProduct> list(String productName, Integer recommendStatus, Integer pageSize, Integer pageNum);
}
SmsHomeRecommendProductServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* 首页人气推荐管理Service实现类
*/
@Service
public class SmsHomeRecommendProductServiceImpl implements SmsHomeRecommendProductService
{
@Resource
private SmsHomeRecommendProductMapper recommendProductMapper;

@Override
public int create(List<SmsHomeRecommendProduct> homeRecommendProductList)
{
for(SmsHomeRecommendProduct recommendProduct : homeRecommendProductList){
recommendProduct.setRecommendStatus(1);
recommendProduct.setSort(0);
recommendProductMapper.insert(recommendProduct);
}
return homeRecommendProductList.size();
}

@Override
public int updateSort(Long id, Integer sort)
{
SmsHomeRecommendProduct recommendProduct = new SmsHomeRecommendProduct();
recommendProduct.setId(id);
recommendProduct.setSort(sort);
return recommendProductMapper.updateByPrimaryKeySelective(recommendProduct);
}

@Override
public int delete(List<Long> ids)
{
SmsHomeRecommendProductExample example = new SmsHomeRecommendProductExample();
example.createCriteria().andIdIn(ids);
return recommendProductMapper.deleteByExample(example);
}

@Override
public int updateRecommendStatus(List<Long> ids, Integer recommendStatus)
{
SmsHomeRecommendProductExample example = new SmsHomeRecommendProductExample();
example.createCriteria().andIdIn(ids);
SmsHomeRecommendProduct record = new SmsHomeRecommendProduct();
record.setRecommendStatus(recommendStatus);
return recommendProductMapper.updateByExampleSelective(record, example);
}

@Override
public List<SmsHomeRecommendProduct> list(String productName, Integer recommendStatus, Integer pageSize,
Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
SmsHomeRecommendProductExample example = new SmsHomeRecommendProductExample();
SmsHomeRecommendProductExample.Criteria criteria = example.createCriteria();
if(!StrUtil.isEmpty(productName)){
criteria.andProductNameLike("%" + productName + "%");
}
if(recommendStatus != null){
criteria.andRecommendStatusEqualTo(recommendStatus);
}
example.setOrderByClause("sort desc");
return recommendProductMapper.selectByExample(example);
}
}
SmsHomeRecommendSubjectController相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* 首页专题推荐管理Controller
*/
@Controller
@Api(tags = "SmsHomeRecommendSubjectController")
@Tag(name = "SmsHomeRecommendSubjectController", description = "首页专题推荐管理")
@RequestMapping("/home/recommendSubject")
public class SmsHomeRecommendSubjectController
{
@Resource
private SmsHomeRecommendSubjectService recommendSubjectService;

@ApiOperation("添加首页推荐专题")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody List<SmsHomeRecommendSubject> homeRecommendSubjectList)
{
int count = recommendSubjectService.create(homeRecommendSubjectList);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("修改推荐排序")
@RequestMapping(value = "/update/sort/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateSort(@PathVariable Long id, Integer sort)
{
int count = recommendSubjectService.updateSort(id, sort);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("批量删除推荐")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("ids") List<Long> ids)
{
int count = recommendSubjectService.delete(ids);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("批量修改推荐状态")
@RequestMapping(value = "/update/recommendStatus", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateRecommendStatus(@RequestParam("ids") List<Long> ids,
@RequestParam Integer recommendStatus)
{
int count = recommendSubjectService.updateRecommendStatus(ids, recommendStatus);
if(count > 0){
return CommonResult.success(count);
}
return CommonResult.failed();
}

@ApiOperation("分页查询推荐")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<SmsHomeRecommendSubject>> list(
@RequestParam(value = "subjectName", required = false) String subjectName,
@RequestParam(value = "recommendStatus", required = false) Integer recommendStatus,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
{
List<SmsHomeRecommendSubject> homeRecommendSubjectList =
recommendSubjectService.list(subjectName, recommendStatus, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(homeRecommendSubjectList));
}
}
SmsHomeRecommendSubjectService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* 首页专题推荐管理Service
*/
public interface SmsHomeRecommendSubjectService
{
/**
* 添加首页推荐
*/
@Transactional
int create(List<SmsHomeRecommendSubject> recommendSubjectList);

/**
* 修改推荐排序
*/
int updateSort(Long id, Integer sort);

/**
* 批量删除推荐
*/
int delete(List<Long> ids);

/**
* 批量更新推荐状态
*/
int updateRecommendStatus(List<Long> ids, Integer recommendStatus);

/**
* 分页查询推荐
*/
List<SmsHomeRecommendSubject> list(String subjectName, Integer recommendStatus, Integer pageSize, Integer pageNum);
}
SmsHomeRecommendSubjectServiceImpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* 首页专题推荐管理Service实现类
*/
@Service
public class SmsHomeRecommendSubjectServiceImpl implements SmsHomeRecommendSubjectService
{
@Resource
private SmsHomeRecommendSubjectMapper recommendProductMapper;

@Override
public int create(List<SmsHomeRecommendSubject> recommendSubjectList)
{
for(SmsHomeRecommendSubject recommendProduct : recommendSubjectList){
recommendProduct.setRecommendStatus(1);
recommendProduct.setSort(0);
recommendProductMapper.insert(recommendProduct);
}
return recommendSubjectList.size();
}

@Override
public int updateSort(Long id, Integer sort)
{
SmsHomeRecommendSubject recommendProduct = new SmsHomeRecommendSubject();
recommendProduct.setId(id);
recommendProduct.setSort(sort);
return recommendProductMapper.updateByPrimaryKeySelective(recommendProduct);
}

@Override
public int delete(List<Long> ids)
{
SmsHomeRecommendSubjectExample example = new SmsHomeRecommendSubjectExample();
example.createCriteria().andIdIn(ids);
return recommendProductMapper.deleteByExample(example);
}

@Override
public int updateRecommendStatus(List<Long> ids, Integer recommendStatus)
{
SmsHomeRecommendSubjectExample example = new SmsHomeRecommendSubjectExample();
example.createCriteria().andIdIn(ids);
SmsHomeRecommendSubject record = new SmsHomeRecommendSubject();
record.setRecommendStatus(recommendStatus);
return recommendProductMapper.updateByExampleSelective(record, example);
}

@Override
public List<SmsHomeRecommendSubject> list(String subjectName, Integer recommendStatus, Integer pageSize,
Integer pageNum)
{
PageHelper.startPage(pageNum, pageSize);
SmsHomeRecommendSubjectExample example = new SmsHomeRecommendSubjectExample();
SmsHomeRecommendSubjectExample.Criteria criteria = example.createCriteria();
if(!StrUtil.isEmpty(subjectName)){
criteria.andSubjectNameLike("%" + subjectName + "%");
}
if(recommendStatus != null){
criteria.andRecommendStatusEqualTo(recommendStatus);
}
example.setOrderByClause("sort desc");
return recommendProductMapper.selectByExample(example);
}
}

mall-portal模块

pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<dependencies>
<!--mall中MBG生成模块-->
<dependency>
<groupId>com.macro.mall</groupId>
<artifactId>mall-mbg</artifactId>
</dependency>
<!--mall安全模块-->
<dependency>
<groupId>com.macro.mall</groupId>
<artifactId>mall-security</artifactId>
</dependency>
<!--mongodb依赖配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<!--redis依赖配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--集成消息队列-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>

包结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
mall-portal
├─java
│ └─com
│ └─macro
│ └─mall
│ └─portal
│ ├─component
│ ├─config
│ ├─controller
│ ├─dao
│ ├─domain
│ ├─repository
│ ├─service
│ │ └─impl
│ └─util
└─resources
└─dao

mall-portal模块的包都统一放在com.macro.mall.portal包下

  • component包中存放的是订单消息相关的RabbitMQ操作类
  • config包中存放的是一些配置类
  • controller包中存放的是前台商城相关接口类
  • dao包中存放的是前台商城相关DAO
  • domain包中存放的是前台商城相关信息实体类
  • repository包中存放的是MongoDB相关操作接口
  • service包中存放的是前台商城相关业务类
  • util包中存放的是一些工具类