/
NewBeeMallGoodsIndexConfigController.java
137 lines (123 loc) · 4.93 KB
/
NewBeeMallGoodsIndexConfigController.java
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
/**
* 严肃声明:
* 开源版本请务必保留此注释头信息,若删除我方将保留所有法律责任追究!
* 本系统已申请软件著作权,受国家版权局知识产权以及国家计算机软件著作权保护!
* 可正常分享和学习源码,不得用于违法犯罪活动,违者必究!
* Copyright (c) 2019-2020 十三 all rights reserved.
* 版权所有,侵权必究!
*/
package ltd.newbee.mall.controller.admin;
import ltd.newbee.mall.common.IndexConfigTypeEnum;
import ltd.newbee.mall.common.ServiceResultEnum;
import ltd.newbee.mall.entity.GoodsCategory;
import ltd.newbee.mall.entity.IndexConfig;
import ltd.newbee.mall.service.NewBeeMallCategoryService;
import ltd.newbee.mall.service.NewBeeMallIndexConfigService;
import ltd.newbee.mall.util.PageQueryUtil;
import ltd.newbee.mall.util.Result;
import ltd.newbee.mall.util.ResultGenerator;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.Objects;
/**
* @author 13
* @qq交流群 796794009
* @email 2449207463@qq.com
* @link https://github.com/newbee-ltd
*/
@Controller
@RequestMapping("/admin")
public class NewBeeMallGoodsIndexConfigController {
@Resource
private NewBeeMallIndexConfigService newBeeMallIndexConfigService;
@GetMapping("/indexConfigs")
public String indexConfigsPage(HttpServletRequest request, @RequestParam("configType") int configType) {
IndexConfigTypeEnum indexConfigTypeEnum = IndexConfigTypeEnum.getIndexConfigTypeEnumByType(configType);
if (indexConfigTypeEnum.equals(IndexConfigTypeEnum.DEFAULT)) {
return "error/error_5xx";
}
request.setAttribute("path", indexConfigTypeEnum.getName());
request.setAttribute("configType", configType);
return "admin/newbee_mall_index_config";
}
/**
* 列表
*/
@RequestMapping(value = "/indexConfigs/list", method = RequestMethod.GET)
@ResponseBody
public Result list(@RequestParam Map<String, Object> params) {
if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {
return ResultGenerator.genFailResult("参数异常!");
}
PageQueryUtil pageUtil = new PageQueryUtil(params);
return ResultGenerator.genSuccessResult(newBeeMallIndexConfigService.getConfigsPage(pageUtil));
}
/**
* 添加
*/
@RequestMapping(value = "/indexConfigs/save", method = RequestMethod.POST)
@ResponseBody
public Result save(@RequestBody IndexConfig indexConfig) {
if (Objects.isNull(indexConfig.getConfigType())
|| StringUtils.isEmpty(indexConfig.getConfigName())
|| Objects.isNull(indexConfig.getConfigRank())) {
return ResultGenerator.genFailResult("参数异常!");
}
String result = newBeeMallIndexConfigService.saveIndexConfig(indexConfig);
if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult(result);
}
}
/**
* 修改
*/
@RequestMapping(value = "/indexConfigs/update", method = RequestMethod.POST)
@ResponseBody
public Result update(@RequestBody IndexConfig indexConfig) {
if (Objects.isNull(indexConfig.getConfigType())
|| Objects.isNull(indexConfig.getConfigId())
|| StringUtils.isEmpty(indexConfig.getConfigName())
|| Objects.isNull(indexConfig.getConfigRank())) {
return ResultGenerator.genFailResult("参数异常!");
}
String result = newBeeMallIndexConfigService.updateIndexConfig(indexConfig);
if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult(result);
}
}
/**
* 详情
*/
@GetMapping("/indexConfigs/info/{id}")
@ResponseBody
public Result info(@PathVariable("id") Long id) {
IndexConfig config = newBeeMallIndexConfigService.getIndexConfigById(id);
if (config == null) {
return ResultGenerator.genFailResult("未查询到数据");
}
return ResultGenerator.genSuccessResult(config);
}
/**
* 删除
*/
@RequestMapping(value = "/indexConfigs/delete", method = RequestMethod.POST)
@ResponseBody
public Result delete(@RequestBody Long[] ids) {
if (ids.length < 1) {
return ResultGenerator.genFailResult("参数异常!");
}
if (newBeeMallIndexConfigService.deleteBatch(ids)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult("删除失败");
}
}
}