Commit 381454c13d069be9a92144f955e8678c0d53be34
1 parent
80d7907e
2022年7月26日11:43:46 项目优化
Showing
11 changed files
with
111 additions
and
64 deletions
fw-dalaran-server/src/main/java/cn/fw/dalaran/server/config/MyControllerAdvice.java
0 → 100644
1 | +package cn.fw.dalaran.server.config; | |
2 | + | |
3 | +import cn.fw.dalaran.common.exception.BusinessException; | |
4 | +import cn.fw.data.base.domain.common.Message; | |
5 | +import org.springframework.validation.BindException; | |
6 | +import org.springframework.validation.FieldError; | |
7 | +import org.springframework.validation.ObjectError; | |
8 | +import org.springframework.web.bind.MethodArgumentNotValidException; | |
9 | +import org.springframework.web.bind.annotation.ExceptionHandler; | |
10 | +import org.springframework.web.bind.annotation.RestControllerAdvice; | |
11 | + | |
12 | +import java.util.ArrayList; | |
13 | +import java.util.List; | |
14 | + | |
15 | +/** | |
16 | + * @author wmy3969 | |
17 | + * @version 1.0 | |
18 | + * @date 2022/7/26 10:39 | |
19 | + * @Description 异常拦截器 | |
20 | + */ | |
21 | +@RestControllerAdvice | |
22 | +public class MyControllerAdvice { | |
23 | + | |
24 | + /** | |
25 | + * BusinessException | |
26 | + */ | |
27 | + @ExceptionHandler(value = {BusinessException.class}) | |
28 | + public Message<String> handleException(BusinessException e) { | |
29 | + return Message.failure(50000, e.getMessage()); | |
30 | + } | |
31 | + | |
32 | + /** | |
33 | + * 参数校验未通过异常处理 | |
34 | + */ | |
35 | + @ExceptionHandler(value = {MethodArgumentNotValidException.class, BindException.class}) | |
36 | + public Message<String> exception(Exception e) { | |
37 | + List<ObjectError> allErrors = new ArrayList<>(); | |
38 | + if (e instanceof MethodArgumentNotValidException) | |
39 | + allErrors = ((MethodArgumentNotValidException) e).getBindingResult().getAllErrors(); | |
40 | + else if (e instanceof BindException) | |
41 | + allErrors = ((BindException) e).getBindingResult().getAllErrors(); | |
42 | + StringBuilder sb = new StringBuilder(); | |
43 | + int size = allErrors.size(); | |
44 | + if (size > 0) { | |
45 | + for (int i = 0; i < size; i++) { | |
46 | + FieldError error = (FieldError) allErrors.get(i); | |
47 | + sb.append("「"); | |
48 | + sb.append(error.getField()); | |
49 | + sb.append("」"); | |
50 | + sb.append(error.getDefaultMessage()); | |
51 | + if (i < size - 1) | |
52 | + sb.append(","); | |
53 | + } | |
54 | + } | |
55 | + return Message.failure(sb.toString()); | |
56 | + } | |
57 | + | |
58 | +} | ... | ... |
fw-dalaran-server/src/main/java/cn/fw/dalaran/server/controller/app/OtherController.java
... | ... | @@ -21,7 +21,6 @@ import javax.validation.constraints.NotNull; |
21 | 21 | import java.io.File; |
22 | 22 | import java.util.Objects; |
23 | 23 | |
24 | -import static cn.fw.common.web.util.ResultBuilder.failure; | |
25 | 24 | import static cn.fw.common.web.util.ResultBuilder.success; |
26 | 25 | |
27 | 26 | /** |
... | ... | @@ -60,11 +59,8 @@ public class OtherController { |
60 | 59 | * @return |
61 | 60 | */ |
62 | 61 | @PostMapping("/saveCheckResult") |
63 | - public Message<String> saveCheckResult(@CurrentUser LoginAuthBean user, @RequestBody @Valid LiveCheckParams param) { | |
64 | - final String result = otherBizService.saveCheckResult(user.getUserId(), param); | |
65 | - if (result.contains("成功")) | |
66 | - return success(result); | |
67 | - return failure(-1, result, result); | |
62 | + public Message<Boolean> saveCheckResult(@CurrentUser LoginAuthBean user, @RequestBody @Valid LiveCheckParams param) { | |
63 | + return success(otherBizService.saveCheckResult(user.getUserId(), param)); | |
68 | 64 | } |
69 | 65 | |
70 | 66 | /** | ... | ... |
fw-dalaran-server/src/main/java/cn/fw/dalaran/server/controller/web/AccountController.java
... | ... | @@ -20,10 +20,8 @@ import org.springframework.validation.annotation.Validated; |
20 | 20 | import org.springframework.web.bind.annotation.*; |
21 | 21 | |
22 | 22 | import javax.validation.constraints.NotNull; |
23 | - | |
24 | 23 | import java.util.List; |
25 | 24 | |
26 | -import static cn.fw.common.web.util.ResultBuilder.failure; | |
27 | 25 | import static cn.fw.common.web.util.ResultBuilder.success; |
28 | 26 | |
29 | 27 | /** |
... | ... | @@ -43,12 +41,9 @@ public class AccountController { |
43 | 41 | private final AccountBizService accountBizService; |
44 | 42 | |
45 | 43 | @PostMapping("/add") |
46 | - public Message<String> add(@CurrentUser LoginAuthBean user, @RequestBody @Validated final AccountDTO accountDTO) { | |
44 | + public Message<Boolean> add(@CurrentUser LoginAuthBean user, @RequestBody @Validated final AccountDTO accountDTO) { | |
47 | 45 | accountDTO.setGroupId(user.getGroupId()); |
48 | - final String result = accountBizService.saveAccount(accountDTO); | |
49 | - if (result.contains("成功")) | |
50 | - return success(result); | |
51 | - return failure(-1, result, result); | |
46 | + return success(accountBizService.saveAccount(accountDTO)); | |
52 | 47 | } |
53 | 48 | |
54 | 49 | @PutMapping("/authorized/report") | ... | ... |
fw-dalaran-server/src/main/java/cn/fw/dalaran/server/controller/web/ActivityThemeController.java
... | ... | @@ -4,6 +4,7 @@ import cn.fw.common.page.AppPage; |
4 | 4 | import cn.fw.common.web.annotation.ControllerMethod; |
5 | 5 | import cn.fw.common.web.auth.LoginAuthBean; |
6 | 6 | import cn.fw.common.web.auth.annotation.CurrentUser; |
7 | +import cn.fw.dalaran.common.exception.BusinessException; | |
7 | 8 | import cn.fw.dalaran.domain.db.ActivityTheme; |
8 | 9 | import cn.fw.dalaran.domain.param.ActivityThemePageParams; |
9 | 10 | import cn.fw.dalaran.domain.param.AddThemeCoverParams; |
... | ... | @@ -24,7 +25,6 @@ import javax.validation.constraints.NotNull; |
24 | 25 | import java.util.Date; |
25 | 26 | import java.util.List; |
26 | 27 | |
27 | -import static cn.fw.common.web.util.ResultBuilder.failure; | |
28 | 28 | import static cn.fw.common.web.util.ResultBuilder.success; |
29 | 29 | |
30 | 30 | /** |
... | ... | @@ -50,11 +50,9 @@ public class ActivityThemeController { |
50 | 50 | * @return 操作结果 |
51 | 51 | */ |
52 | 52 | @PostMapping("/save") |
53 | - public Message<String> save(@RequestBody @Valid ActivityThemeVo themeVo) { | |
54 | - if (activityThemeService.validThemeDateDuplicate(themeVo)) { | |
55 | - final String failResult = "指定门店在指定时间段内正在参与其他活动, 添加失败"; | |
56 | - return failure(-1, failResult, failResult); | |
57 | - } | |
53 | + public Message<Boolean> save(@RequestBody @Valid ActivityThemeVo themeVo) { | |
54 | + if (activityThemeService.validThemeDateDuplicate(themeVo)) | |
55 | + throw new BusinessException("指定门店在指定时间段内正在参与其他活动, 添加失败"); | |
58 | 56 | return success(activityThemeService.save(themeVo)); |
59 | 57 | } |
60 | 58 | |
... | ... | @@ -65,11 +63,8 @@ public class ActivityThemeController { |
65 | 63 | * @return 操作结果 |
66 | 64 | */ |
67 | 65 | @PostMapping("/addTopic") |
68 | - public Message<String> addTopic(@RequestBody @Valid AddThemeTopicParams params) { | |
69 | - final String result = activityThemeService.addTopic(params); | |
70 | - if (result.contains("成功")) | |
71 | - return success(result); | |
72 | - return failure(-1, result, result); | |
66 | + public Message<Boolean> addTopic(@RequestBody @Valid AddThemeTopicParams params) { | |
67 | + return success(activityThemeService.addTopic(params)); | |
73 | 68 | } |
74 | 69 | |
75 | 70 | /** | ... | ... |
fw-dalaran-server/src/main/java/cn/fw/dalaran/server/controller/web/ConfigGroupController.java
... | ... | @@ -17,7 +17,6 @@ import org.springframework.web.bind.annotation.*; |
17 | 17 | import javax.validation.Valid; |
18 | 18 | import java.util.List; |
19 | 19 | |
20 | -import static cn.fw.common.web.util.ResultBuilder.failure; | |
21 | 20 | import static cn.fw.common.web.util.ResultBuilder.success; |
22 | 21 | |
23 | 22 | /** |
... | ... | @@ -56,11 +55,8 @@ public class ConfigGroupController { |
56 | 55 | * @return 操作结果 |
57 | 56 | */ |
58 | 57 | @PostMapping("/update") |
59 | - public Message<String> saveOrUpdate(@CurrentUser LoginAuthBean user, @RequestBody @Valid ConfigGroupVo param) { | |
60 | - final String result = configGroupService.update(user.getUserId(), param); | |
61 | - if (result.contains("成功")) | |
62 | - return success(result); | |
63 | - return failure(-1, result, result); | |
58 | + public Message<Boolean> saveOrUpdate(@CurrentUser LoginAuthBean user, @RequestBody @Valid ConfigGroupVo param) { | |
59 | + return success(configGroupService.update(user.getUserId(), param)); | |
64 | 60 | } |
65 | 61 | |
66 | 62 | /** | ... | ... |
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/biz/AccountBizService.java
... | ... | @@ -3,6 +3,7 @@ package cn.fw.dalaran.service.biz; |
3 | 3 | import cn.fw.common.page.AppPage; |
4 | 4 | import cn.fw.common.web.annotation.DisLock; |
5 | 5 | import cn.fw.dalaran.common.constants.DalaranConstants; |
6 | +import cn.fw.dalaran.common.exception.BusinessException; | |
6 | 7 | import cn.fw.dalaran.common.utils.DateUtil; |
7 | 8 | import cn.fw.dalaran.domain.db.Account; |
8 | 9 | import cn.fw.dalaran.domain.db.TodoHistory; |
... | ... | @@ -51,7 +52,7 @@ public class AccountBizService { |
51 | 52 | */ |
52 | 53 | @Transactional(rollbackFor = Exception.class) |
53 | 54 | @DisLock(prefix = "':' + #this.getClass().getSimpleName()", key = "#accountDTO.groupId + ':' + #accountDTO.account", message = "请勿重复提交") |
54 | - public String saveAccount(AccountDTO accountDTO) { | |
55 | + public boolean saveAccount(AccountDTO accountDTO) { | |
55 | 56 | checkExist(accountDTO); |
56 | 57 | Account db = new Account(); |
57 | 58 | BeanUtils.copyProperties(accountDTO, db); |
... | ... | @@ -67,7 +68,7 @@ public class AccountBizService { |
67 | 68 | Pattern p = Pattern.compile("^[0-9].*"); |
68 | 69 | Matcher m = p.matcher(accountDTO.getAccount()); |
69 | 70 | if (m.matches() && Objects.equals(accountDTO.getType(), PlatformEnum.KS)) |
70 | - return "添加快手账号失败, 必须指定直播搜索关键词"; | |
71 | + throw new BusinessException("添加快手账号失败, 必须指定直播搜索关键词"); | |
71 | 72 | } |
72 | 73 | } |
73 | 74 | db.setYn(Boolean.TRUE); |
... | ... | @@ -75,7 +76,7 @@ public class AccountBizService { |
75 | 76 | if (Objects.isNull(accountDTO.getId())) { |
76 | 77 | db.setCreateTime(DateUtil.localDateTime2Date(LocalDateTime.now().plusDays(-1))); |
77 | 78 | } |
78 | - return accountService.saveOrUpdate(db) ? "添加成功" : "添加失败"; | |
79 | + return accountService.saveOrUpdate(db); | |
79 | 80 | } |
80 | 81 | |
81 | 82 | /** | ... | ... |
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/biz/OtherBizService.java
1 | 1 | package cn.fw.dalaran.service.biz; |
2 | 2 | |
3 | 3 | import cn.fw.dalaran.common.constants.DalaranConstants; |
4 | +import cn.fw.dalaran.common.exception.BusinessException; | |
4 | 5 | import cn.fw.dalaran.common.utils.PublicUtil; |
5 | 6 | import cn.fw.dalaran.common.utils.StringUtils; |
6 | 7 | import cn.fw.dalaran.domain.db.*; |
... | ... | @@ -117,17 +118,17 @@ public class OtherBizService { |
117 | 118 | * @return 操作结果 |
118 | 119 | */ |
119 | 120 | @Transactional |
120 | - public String saveCheckResult(Long userId, LiveCheckParams param) { | |
121 | + public boolean saveCheckResult(Long userId, LiveCheckParams param) { | |
121 | 122 | final Integer type = param.getType(); |
122 | 123 | final Long dataId = param.getDataId(); |
123 | 124 | if (Objects.equals(type, 0)) { |
124 | 125 | final LiveCheckResult liveCheckResult = PublicUtil.copy(param.getCheckResult(), LiveCheckResult.class); |
125 | 126 | final Long liveCheckResultId = liveCheckResult.getId(); |
126 | 127 | if (Objects.equals(liveCheckResult.getCounterfeit(), -1)) |
127 | - return "请选择是否空挂"; | |
128 | + throw new BusinessException("请选择是否空挂"); | |
128 | 129 | if (Objects.equals(liveCheckResult.getCounterfeit(), 1) && |
129 | 130 | StringUtils.isEmpty(liveCheckResult.getOpinion())) |
130 | - return "判断空挂必须给出审核意见"; | |
131 | + throw new BusinessException("判断空挂必须给出审核意见"); | |
131 | 132 | final List<Long> oldFileIds = Optional.ofNullable(themeFileService.lambdaQuery() |
132 | 133 | .eq(ThemeFile::getType, FileTypeEnum.LIVE_CHECK.getValue()) |
133 | 134 | .eq(ThemeFile::getExtraId, liveCheckResultId) |
... | ... | @@ -163,11 +164,11 @@ public class OtherBizService { |
163 | 164 | ); |
164 | 165 | liveCheckResult.setStatus(type); |
165 | 166 | liveCheckResult.setValid(Objects.equals(liveCheckResult.getCounterfeit(), 0) && Objects.equals(liveCheckResult.getPay(), 0) ? 1 : 0); |
166 | - return liveCheckResultService.updateById(liveCheckResult) ? "保存成功" : "保存失败"; | |
167 | + return liveCheckResultService.updateById(liveCheckResult); | |
167 | 168 | } else if (Objects.equals(type, 1)) {// 完成待办 |
168 | 169 | final List<LiveCheckVo.liveSummary> summaries = this.getLiveCheck(userId, dataId).getLiveList(); |
169 | 170 | if (summaries.stream().anyMatch(item -> Objects.equals(item.getCounterfeit(), -1))) { |
170 | - return "还有未完成审核的直播, 请完成所有直播审核后重新提交"; | |
171 | + throw new BusinessException("还有未完成审核的直播, 请完成所有直播审核后重新提交"); | |
171 | 172 | } else { |
172 | 173 | if (!todoHistoryService.lambdaUpdate() |
173 | 174 | .set(TodoHistory::getDone, true) |
... | ... | @@ -175,7 +176,7 @@ public class OtherBizService { |
175 | 176 | .eq(TodoHistory::getDataId, dataId) |
176 | 177 | .eq(TodoHistory::getTodoCode, DalaranConstants.CHECK_LIVE) |
177 | 178 | .update()) |
178 | - return "完成待办失败"; | |
179 | + throw new BusinessException("完成待办失败"); | |
179 | 180 | final List<Long> invalidLiveIds = summaries.stream() |
180 | 181 | .filter(item -> Objects.equals(item.getValid(), 0)) |
181 | 182 | .map(LiveCheckVo.liveSummary::getLiveId) |
... | ... | @@ -206,10 +207,10 @@ public class OtherBizService { |
206 | 207 | .stream() |
207 | 208 | .map(LiveCheckVo.liveSummary::getId) |
208 | 209 | .collect(Collectors.toList()) |
209 | - ).update() ? "提交成功" : "提交失败"; | |
210 | + ).update(); | |
210 | 211 | } |
211 | 212 | } |
212 | - return "未知错误"; | |
213 | + return false; | |
213 | 214 | } |
214 | 215 | |
215 | 216 | /** | ... | ... |
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/data/ActivityThemeService.java
... | ... | @@ -44,7 +44,7 @@ public interface ActivityThemeService extends IService<ActivityTheme> { |
44 | 44 | * @param themeVo 参数 |
45 | 45 | * @return |
46 | 46 | */ |
47 | - String save(ActivityThemeVo themeVo); | |
47 | + boolean save(ActivityThemeVo themeVo); | |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * 增加话题 |
... | ... | @@ -52,7 +52,7 @@ public interface ActivityThemeService extends IService<ActivityTheme> { |
52 | 52 | * @param params 增加话题带参 |
53 | 53 | * @return |
54 | 54 | */ |
55 | - String addTopic(AddThemeTopicParams params); | |
55 | + boolean addTopic(AddThemeTopicParams params); | |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * 增加封面 | ... | ... |
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/data/ConfigGroupService.java
... | ... | @@ -29,7 +29,7 @@ public interface ConfigGroupService extends IService<ConfigGroup> { |
29 | 29 | * @param param 参数封装 |
30 | 30 | * @return |
31 | 31 | */ |
32 | - String update(Long userId, ConfigGroupVo param); | |
32 | + boolean update(Long userId, ConfigGroupVo param); | |
33 | 33 | |
34 | 34 | /** |
35 | 35 | * 查询本集团的配置组列表 | ... | ... |
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/data/impl/ActivityThemeServiceImpl.java
... | ... | @@ -113,9 +113,8 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
113 | 113 | * @return 两个时间区间是否有重叠 |
114 | 114 | */ |
115 | 115 | public boolean validDateOverlap(Date startDate1, Date endDate1, Date startDate2, Date endDate2) { |
116 | - if (startDate1.after(endDate1) || startDate2.after(endDate2)) { | |
116 | + if (startDate1.after(endDate1) || startDate2.after(endDate2)) | |
117 | 117 | throw new BusinessException("开始时间必须在结束时间之前"); |
118 | - } | |
119 | 118 | return !endDate2.before(startDate1) && !startDate2.after(endDate1) && !endDate1.before(startDate2) && !startDate1.after(endDate2); |
120 | 119 | } |
121 | 120 | |
... | ... | @@ -127,7 +126,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
127 | 126 | */ |
128 | 127 | @Override |
129 | 128 | @Transactional |
130 | - public String save(ActivityThemeVo themeVo) { | |
129 | + public boolean save(ActivityThemeVo themeVo) { | |
131 | 130 | ConfigGroup configGroup = configGroupService.getById(themeVo.getConfigGroupId()); |
132 | 131 | ActivityTheme activityTheme = ActivityThemeVo.toDB(themeVo); |
133 | 132 | this.assembleConfigJson(themeVo.getConfigGroupId(), activityTheme); |
... | ... | @@ -149,7 +148,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
149 | 148 | this.saveFiles(activityTheme.getId(), themeVo.getAllFileDesc()); |
150 | 149 | this.downloadAndConvertCover(activityTheme, themeVo.getAllFileDesc()); |
151 | 150 | } |
152 | - return result ? "添加活动主题成功" : "添加活动主题保存失败"; | |
151 | + return result; | |
153 | 152 | } |
154 | 153 | |
155 | 154 | /** |
... | ... | @@ -159,12 +158,12 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
159 | 158 | * @return |
160 | 159 | */ |
161 | 160 | @Override |
162 | - public String addTopic(AddThemeTopicParams params) { | |
161 | + public boolean addTopic(AddThemeTopicParams params) { | |
163 | 162 | final ActivityTheme activityTheme = AddThemeTopicParams.toDB(params); |
164 | 163 | final Long themeId = params.getThemeId(); |
165 | 164 | final ActivityTheme theme = this.getById(themeId); |
166 | 165 | if (Objects.isNull(theme)) |
167 | - return String.format("不存在id为: %s的活动主题", themeId); | |
166 | + throw new BusinessException(String.format("不存在id为: %s的活动主题", themeId)); | |
168 | 167 | List<String> newTopic = params.getTopic().stream() |
169 | 168 | .map(item -> { |
170 | 169 | String replace = item.replace("#", ""); |
... | ... | @@ -174,13 +173,14 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
174 | 173 | List<String> oldTopic = Arrays.asList(theme.getTopic().split(",").clone()); |
175 | 174 | ArrayList<String> result = new ArrayList<>(newTopic); |
176 | 175 | result.retainAll(oldTopic); |
177 | - if (new Date().compareTo(theme.getEndTime()) > 0) | |
178 | - return "已经结束的主题不允许修改话题"; | |
176 | + long timeSub = System.currentTimeMillis() - theme.getEndTime().getTime(); | |
177 | + if (timeSub > 24 * 3600 * 1000 + 1000) | |
178 | + throw new BusinessException("活动已经结束数据抓取, 不能再增加话题"); | |
179 | 179 | if (result.size() < oldTopic.size()) |
180 | - return "不允许删除原有话题"; | |
180 | + throw new BusinessException("不允许删除原有话题"); | |
181 | 181 | if (Objects.equals(newTopic.size(), oldTopic.size())) |
182 | - return "未进行任何添加操作"; | |
183 | - return this.updateById(activityTheme) ? "增加话题成功" : "增加话题失败"; | |
182 | + throw new BusinessException("未进行任何添加操作"); | |
183 | + return this.updateById(activityTheme); | |
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
... | ... | @@ -198,8 +198,12 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
198 | 198 | .filter(item -> Objects.isNull(item.getId())) |
199 | 199 | .peek(item -> item.setType(FileTypeEnum.THEME_COVER.getValue())) |
200 | 200 | .collect(Collectors.toList()); |
201 | + ActivityTheme theme = this.getById(themeId); | |
202 | + long timeSub = System.currentTimeMillis() - theme.getEndTime().getTime(); | |
203 | + if (timeSub > 24 * 3600 * 1000 + 1000) | |
204 | + throw new BusinessException("活动已经结束数据抓取, 不能再增加封面"); | |
201 | 205 | this.saveFiles(themeId, fileList); |
202 | - this.downloadAndConvertCover(this.getById(themeId), fileList); | |
206 | + this.downloadAndConvertCover(theme, fileList); | |
203 | 207 | return true; |
204 | 208 | } |
205 | 209 | ... | ... |
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/data/impl/ConfigGroupServiceImpl.java
1 | 1 | package cn.fw.dalaran.service.data.impl; |
2 | 2 | |
3 | 3 | import cn.fw.dalaran.common.constants.DalaranConstants; |
4 | +import cn.fw.dalaran.common.exception.BusinessException; | |
4 | 5 | import cn.fw.dalaran.dao.ConfigGroupDao; |
5 | 6 | import cn.fw.dalaran.domain.db.ActivityTheme; |
6 | 7 | import cn.fw.dalaran.domain.db.ConfigGroup; |
... | ... | @@ -72,7 +73,7 @@ public class ConfigGroupServiceImpl extends ServiceImpl<ConfigGroupDao, ConfigGr |
72 | 73 | .eq(ConfigGroup::getUserId, userId) |
73 | 74 | .eq(ConfigGroup::getAllShop, -2) |
74 | 75 | .list().size() > 0) |
75 | - throw new RuntimeException("该用户存在一个已初始化但未赋值修改的配置组"); | |
76 | + throw new BusinessException("该用户存在一个已初始化但未赋值修改的配置组"); | |
76 | 77 | ConfigGroup configGroup = new ConfigGroup(); |
77 | 78 | configGroup.setUserId(userId); |
78 | 79 | configGroup.setGroupId(groupId); |
... | ... | @@ -82,7 +83,7 @@ public class ConfigGroupServiceImpl extends ServiceImpl<ConfigGroupDao, ConfigGr |
82 | 83 | final boolean result = this.save(configGroup);// 初始化配置组 |
83 | 84 | if (result) |
84 | 85 | return this.processVo(configGroup, false); |
85 | - throw new RuntimeException("初始化配置组失败"); | |
86 | + throw new BusinessException("初始化配置组失败"); | |
86 | 87 | } |
87 | 88 | |
88 | 89 | /** |
... | ... | @@ -94,9 +95,9 @@ public class ConfigGroupServiceImpl extends ServiceImpl<ConfigGroupDao, ConfigGr |
94 | 95 | */ |
95 | 96 | @Override |
96 | 97 | @Transactional |
97 | - public String update(Long userId, ConfigGroupVo param) { | |
98 | + public boolean update(Long userId, ConfigGroupVo param) { | |
98 | 99 | if (!Objects.equals(userId, param.getUserId())) |
99 | - return "不允许修改别人的配置组"; | |
100 | + throw new BusinessException("不允许修改别人的配置组"); | |
100 | 101 | final Long configGroupId = param.getId(); |
101 | 102 | List<ConfigGroup> list = this.lambdaQuery() |
102 | 103 | .eq(ConfigGroup::getGroupId, param.getGroupId()) |
... | ... | @@ -104,9 +105,9 @@ public class ConfigGroupServiceImpl extends ServiceImpl<ConfigGroupDao, ConfigGr |
104 | 105 | .list();// 找到对应集团的所有生效的配置组 |
105 | 106 | Integer allShop = param.getAllShop(); |
106 | 107 | if (Objects.equals(allShop, 1)) {// 本次指定配置是否为全部门店 |
107 | - if (list.size() > 0) return "该集团已存在门店配置, 新配置不能设置为[全部门店]"; | |
108 | + if (list.size() > 0) throw new BusinessException("该集团已存在门店配置, 新配置不能设置为[全部门店]"); | |
108 | 109 | } else if (list.stream().anyMatch(item -> Objects.equals(item.getAllShop(), 1))) {// 已存在的配置组是否有全部门店的 |
109 | - return "该集团已存在[全部门店]配置, 新配置不能生效"; | |
110 | + throw new BusinessException("该集团已存在[全部门店]配置, 新配置不能生效"); | |
110 | 111 | } else { |
111 | 112 | List<Long> shopIds = param.getShopIds();// 本次配置指定生效门店 |
112 | 113 | List<String> shopNames = param.getShopNames();// 本次配置指定生效门店 |
... | ... | @@ -130,7 +131,7 @@ public class ConfigGroupServiceImpl extends ServiceImpl<ConfigGroupDao, ConfigGr |
130 | 131 | shopIds |
131 | 132 | )// 除开自己本身, 任何一个配置门店信息和本次指定的门店有重合, 本次修改都不能生效 |
132 | 133 | ) |
133 | - ) return "本次指定门店和集团已有配置门店重合, 修改失败"; | |
134 | + ) throw new BusinessException("本次指定门店和集团已有配置门店重合, 修改失败"); | |
134 | 135 | final Date yesterday = new Date(System.currentTimeMillis() - 24 * 3600 * 1000L); |
135 | 136 | final String validConfigJson = activityThemeService.getValidConfigJson(configGroupId); |
136 | 137 | activityThemeService.lambdaUpdate() |
... | ... | @@ -188,7 +189,7 @@ public class ConfigGroupServiceImpl extends ServiceImpl<ConfigGroupDao, ConfigGr |
188 | 189 | if (!CollectionUtils.isEmpty(globalConfigs)) { |
189 | 190 | globalConfigService.updateConfig(globalConfigs); |
190 | 191 | } |
191 | - return "修改配置组成功"; | |
192 | + return true; | |
192 | 193 | } |
193 | 194 | |
194 | 195 | /** | ... | ... |