|
|
@@ -1,6 +1,5 @@
|
|
|
package com.cyksj.web.controller.manage.mini;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.dto.Result;
|
|
|
@@ -9,7 +8,6 @@ import com.cyksj.mapper.mini.MiniPopularizeConfigCategoryMapper;
|
|
|
import com.cyksj.mapper.mini.MiniPopularizeConfigMapper;
|
|
|
import com.cyksj.model.entity.MiniPopularizeConfig;
|
|
|
import com.cyksj.model.entity.MiniPopularizeConfigCategory;
|
|
|
-import com.cyksj.model.request.MiniPopularizeCategoryUpdateReq;
|
|
|
import com.cyksj.model.request.MiniPopularizeConfigReq;
|
|
|
import com.cyksj.model.views.MiniPopularizeConfigView;
|
|
|
import com.cyksj.service.mini.MiniPopularizeService;
|
|
|
@@ -23,8 +21,6 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 项目名: yhlxj2
|
|
|
@@ -117,8 +113,6 @@ public class MiniPopularizeController {
|
|
|
public Result<String> saveCategory(@RequestBody MiniPopularizeConfigCategory configCategory) {
|
|
|
try {
|
|
|
miniPopularizeConfigCategoryMapper.insert(configCategory);
|
|
|
- configCategory.setSorted(configCategory.getId().intValue());
|
|
|
- miniPopularizeConfigCategoryMapper.updateById(configCategory);
|
|
|
} catch (DataAccessException e) {
|
|
|
throw BusinessRuntimeException.getInstance("重复分类");
|
|
|
}
|
|
|
@@ -129,26 +123,30 @@ public class MiniPopularizeController {
|
|
|
* 编辑分类
|
|
|
*/
|
|
|
@PutMapping("/category/save")
|
|
|
- public Result<String> saveCategory(@RequestBody MiniPopularizeCategoryUpdateReq req) {
|
|
|
- for (MiniPopularizeConfigCategory configCategory : req.getCategories()) {
|
|
|
- if (configCategory.getId() == null) {
|
|
|
- try {
|
|
|
- miniPopularizeConfigCategoryMapper.insert(configCategory);
|
|
|
- configCategory.setSorted(configCategory.getId().intValue());
|
|
|
- miniPopularizeConfigCategoryMapper.updateById(configCategory);
|
|
|
- } catch (DataAccessException e) {
|
|
|
-
|
|
|
- }
|
|
|
- } else miniPopularizeConfigCategoryMapper.updateById(configCategory);
|
|
|
- }
|
|
|
- List<Long> delIds = req.getDelIds();
|
|
|
- if (CollUtil.isNotEmpty(delIds)) {
|
|
|
- Set<Long> existsIds = miniPopularizeConfigMapper.selectList(Wrappers.lambdaQuery(MiniPopularizeConfig.class).in(MiniPopularizeConfig::getCid, delIds)).stream().map(MiniPopularizeConfig::getCid).collect(Collectors.toSet());
|
|
|
- if (CollUtil.isNotEmpty(existsIds)) {
|
|
|
- delIds.remove(existsIds);
|
|
|
- }
|
|
|
- miniPopularizeConfigCategoryMapper.deleteBatchIds(delIds);
|
|
|
+ public Result<String> updateCategory(@RequestBody MiniPopularizeConfigCategory configCategory) {
|
|
|
+ miniPopularizeConfigCategoryMapper.updateById(configCategory);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除分类
|
|
|
+ */
|
|
|
+ @DeleteMapping("/del/category/{id}")
|
|
|
+ public Result<String> delCategoryById(@PathVariable Long id) {
|
|
|
+ Integer selectCount = miniPopularizeConfigMapper.selectCount(Wrappers.lambdaQuery(MiniPopularizeConfig.class).eq(MiniPopularizeConfig::getCid, id));
|
|
|
+ if (selectCount > 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("该分类下存在数据");
|
|
|
}
|
|
|
+ miniPopularizeConfigCategoryMapper.deleteById(id);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分类排序
|
|
|
+ */
|
|
|
+ @PutMapping("/category/sorted")
|
|
|
+ public Result<String> sortedCategory(@RequestBody MiniPopularizeConfigCategory configCategory) {
|
|
|
+ miniPopularizeConfigCategoryMapper.updateById(configCategory);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
|