修复已知问题

This commit is contained in:
2024-09-25 19:11:39 +08:00
parent 0e0dd59963
commit 8b362f8616
9 changed files with 119 additions and 41 deletions

View File

@@ -41,21 +41,15 @@ public class CmsArticleCategoryController extends BaseController {
@ApiOperation("查询全部文章分类表")
@GetMapping()
public ApiResult<List<CmsArticleCategory>> list(CmsArticleCategoryParam param) {
PageParam<CmsArticleCategory, CmsArticleCategoryParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(cmsArticleCategoryService.list(page.getOrderWrapper()));
// 使用关联查询
//return success(cmsArticleCategoryService.listRel(param));
return success(cmsArticleCategoryService.listRel(param));
}
@PreAuthorize("hasAuthority('cms:articleCategory:list')")
@OperationLog
@ApiOperation("根据id查询文章分类表")
@GetMapping("/{id}")
public ApiResult<CmsArticleCategory> get(@PathVariable("id") Integer id) {
return success(cmsArticleCategoryService.getById(id));
// 使用关联查询
//return success(cmsArticleCategoryService.getByIdRel(id));
return success(cmsArticleCategoryService.getByIdRel(id));
}
@ApiOperation("添加文章分类表")

View File

@@ -64,14 +64,17 @@ public class CmsNavigationController extends BaseController {
@ApiOperation("添加网站导航记录表")
@PostMapping()
public ApiResult<?> save(@RequestBody CmsNavigation cmsNavigation) {
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
cmsNavigation.setUserId(loginUser.getUserId());
}
if (cmsNavigationService.save(cmsNavigation)) {
return success("添加成功");
}
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
cmsNavigation.setUserId(loginUser.getUserId());
cmsNavigation.setTenantId(loginUser.getTenantId());
}
if (cmsNavigationService.save(cmsNavigation)) {
// 添加成功事务处理
cmsNavigationService.saveAsync(cmsNavigation);
return success("添加成功");
}
return fail("添加失败");
}

View File

@@ -1,6 +1,7 @@
package com.gxwebsoft.cms.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableLogic;
@@ -40,6 +41,14 @@ public class CmsDesign implements Serializable {
@ApiModelProperty(value = "页面描述")
private String description;
@ApiModelProperty(value = "路由地址")
@TableField(exist = false)
private String path;
@ApiModelProperty(value = "组件路径")
@TableField(exist = false)
private String component;
@ApiModelProperty(value = "缩列图")
private String photo;

View File

@@ -39,4 +39,5 @@ public interface CmsNavigationService extends IService<CmsNavigation> {
*/
CmsNavigation getByIdRel(Integer navigationId);
void saveAsync(CmsNavigation cmsNavigation);
}

View File

@@ -1,14 +1,22 @@
package com.gxwebsoft.cms.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.entity.CmsDesign;
import com.gxwebsoft.cms.mapper.CmsNavigationMapper;
import com.gxwebsoft.cms.service.CmsDesignService;
import com.gxwebsoft.cms.service.CmsNavigationService;
import com.gxwebsoft.cms.entity.CmsNavigation;
import com.gxwebsoft.cms.param.CmsNavigationParam;
import com.gxwebsoft.common.core.exception.BusinessException;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.MessageFormat;
import java.util.List;
/**
@@ -19,7 +27,10 @@ import java.util.List;
*/
@Service
public class CmsNavigationServiceImpl extends ServiceImpl<CmsNavigationMapper, CmsNavigation> implements CmsNavigationService {
@Resource
private CmsDesignService cmsDesignService;
@Resource
private CmsNavigationMapper cmsNavigationMapper;
@Override
public PageResult<CmsNavigation> pageRel(CmsNavigationParam param) {
PageParam<CmsNavigation, CmsNavigationParam> page = new PageParam<>(param);
@@ -44,4 +55,80 @@ public class CmsNavigationServiceImpl extends ServiceImpl<CmsNavigationMapper, C
return param.getOne(baseMapper.selectListRel(param));
}
/**
* 配置路由生成规则
* path/模型/导航ID
* component: /pages/模型/index.vue
*/
@Override
public void saveAsync(CmsNavigation navigation) {
// TODO 1.设计path和component生产规则
String path = "";
String component = "";
// 1.手动配置优先
if (StrUtil.isNotBlank(navigation.getPath())) {
component = navigation.getComponent();
path = navigation.getPath();
path = StrUtil.trimStart(path); //去除字符串前面的空格
path = path.replace(" ", "-"); //把空格转为横杆
if (!navigation.getModel().equals("links")) {
final char charAt = path.charAt(0);
if (charAt != '/' && charAt != '#') {
path = "/".concat(path);
}
}
if (path.equals("/")) {
component = "/pages/index.vue"; // 指定首页组件路径
navigation.setHome(1);
}
}
// 2.自动配置
if (StrUtil.isBlank(navigation.getPath())) {
path = MessageFormat.format("/{0}/{1}", navigation.getModel() , navigation.getNavigationId());
component = MessageFormat.format("/pages/{0}/{1}", navigation.getModel(), "index.vue");
// 通用模型
if (navigation.getModel().equals("custom")) {
path = MessageFormat.format("/{0}-{1}",navigation.getModel(), navigation.getNavigationId());
component = "/pages/[custom]/index.vue";
}
}
// 更新
navigation.setPath(path);
navigation.setComponent(component);
updateById(navigation);
// 查重
// final int count = count(new LambdaQueryWrapper<CmsNavigation>().eq(CmsNavigation::getPath, path));
// if(count > 1){
// throw new BusinessException("路由地址(" + path + ")已存在!");
// }
// TODO 2.同步添加页面
final CmsDesign one = cmsDesignService.getOne(new LambdaQueryWrapper<CmsDesign>().eq(CmsDesign::getCategoryId, navigation.getNavigationId()).eq(CmsDesign::getDeleted, 0).last("limit 1"));
if (ObjectUtil.isEmpty(one)) {
final CmsDesign design = new CmsDesign();
design.setName(navigation.getTitle());
design.setCategoryId(navigation.getNavigationId());
design.setKeywords(navigation.getTitle());
design.setDescription(navigation.getComments());
design.setPath(navigation.getPath());
design.setComponent(navigation.getComponent());
design.setTenantId(navigation.getTenantId());
cmsDesignService.save(design);
}
// 面包屑
final CmsNavigation parent = getById(navigation.getParentId());
if (ObjectUtil.isNotEmpty(parent) && navigation.getParentId() > 0) {
navigation.setParentName(parent.getTitle());
navigation.setParentPath(parent.getPath());
navigation.setParentId(parent.getNavigationId());
updateById(parent);
}
}
}

View File

@@ -7,7 +7,6 @@ import com.gxwebsoft.common.system.entity.Plug;
import com.gxwebsoft.common.system.param.PlugParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import io.swagger.annotations.Api;
@@ -36,11 +35,8 @@ public class PlugController extends BaseController {
@ApiOperation("分页查询插件扩展")
@GetMapping("/page")
public ApiResult<PageResult<Plug>> page(PlugParam param) {
PageParam<Plug, PlugParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(plugService.page(page, page.getWrapper()));
// 使用关联查询
//return success(plugService.pageRel(param));
return success(plugService.pageRel(param));
}
@PreAuthorize("hasAuthority('sys:plug:list')")
@@ -48,11 +44,8 @@ public class PlugController extends BaseController {
@ApiOperation("查询全部插件扩展")
@GetMapping()
public ApiResult<List<Plug>> list(PlugParam param) {
PageParam<Plug, PlugParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(plugService.list(page.getOrderWrapper()));
// 使用关联查询
//return success(plugService.listRel(param));
return success(plugService.listRel(param));
}
@PreAuthorize("hasAuthority('sys:plug:list')")
@@ -60,9 +53,8 @@ public class PlugController extends BaseController {
@ApiOperation("根据id查询插件扩展")
@GetMapping("/{id}")
public ApiResult<Plug> get(@PathVariable("id") Integer id) {
return success(plugService.getById(id));
// 使用关联查询
//return success(plugService.getByIdRel(id));
return success(plugService.getByIdRel(id));
}
@PreAuthorize("hasAuthority('sys:plug:save')")

View File

@@ -41,11 +41,8 @@ public class ShopGoodsController extends BaseController {
@ApiOperation("查询全部商品记录表")
@GetMapping()
public ApiResult<List<ShopGoods>> list(ShopGoodsParam param) {
PageParam<ShopGoods, ShopGoodsParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(shopGoodsService.list(page.getOrderWrapper()));
// 使用关联查询
//return success(shopGoodsService.listRel(param));
return success(shopGoodsService.listRel(param));
}
@PreAuthorize("hasAuthority('shop:shopGoods:list')")
@@ -53,9 +50,8 @@ public class ShopGoodsController extends BaseController {
@ApiOperation("根据id查询商品记录表")
@GetMapping("/{id}")
public ApiResult<ShopGoods> get(@PathVariable("id") Integer id) {
return success(shopGoodsService.getById(id));
// 使用关联查询
//return success(shopGoodsService.getByIdRel(id));
return success(shopGoodsService.getByIdRel(id));
}
@ApiOperation("添加商品记录表")

View File

@@ -20,7 +20,7 @@ import java.util.Map;
* @author WebSoft
* @since 2021-09-05 00:31:14
*/
public class ShopGenerator {
public class MallGenerator {
// 输出位置
private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径

View File

@@ -100,11 +100,8 @@ public class ${table.controllerName} {
<% } %>
@GetMapping()
public ApiResult<List<${entity}>> list(${entity}Param param) {
PageParam<${entity}, ${entity}Param> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(${serviceIns}.list(page.getOrderWrapper()));
// 使用关联查询
//return success(${serviceIns}.listRel(param));
return success(${serviceIns}.listRel(param));
}
<% if(!swagger2) { %>
@@ -117,9 +114,8 @@ public class ${table.controllerName} {
@ApiOperation("根据id查询${table.comment!}")
@GetMapping("/{id}")
public ApiResult<${entity}> get(@PathVariable("id") Integer id) {
return success(${serviceIns}.getById(id));
// 使用关联查询
//return success(${serviceIns}.getByIdRel(id));
return success(${serviceIns}.getByIdRel(id));
}
<% if(!swagger2) { %>