新增链接管理功能

This commit is contained in:
gxwebsoft
2024-01-15 13:43:09 +08:00
parent 2c76b8cee0
commit a64e9cbe05
14 changed files with 473 additions and 15 deletions
@@ -1,18 +1,12 @@
package com.gxwebsoft.cms.controller;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.cms.service.ArticleCategoryService;
import com.gxwebsoft.cms.entity.ArticleCategory;
import com.gxwebsoft.cms.param.ArticleCategoryParam;
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 com.gxwebsoft.cms.service.ArticleCategoryService;
import com.gxwebsoft.common.core.web.*;
import com.gxwebsoft.common.system.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -35,17 +29,16 @@ public class ArticleCategoryController extends BaseController {
@GetMapping("/page")
public ApiResult<PageResult<ArticleCategory>> page(ArticleCategoryParam param) {
PageParam<ArticleCategory, ArticleCategoryParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
page.setDefaultOrder("sort_number asc,create_time desc");
return success(articleCategoryService.page(page, page.getWrapper()));
// 使用关联查询
//return success(articleCategoryService.pageRel(param));
}
@ApiOperation("查询全部文章分类表")
@GetMapping()
public ApiResult<List<ArticleCategory>> list(ArticleCategoryParam param) {
PageParam<ArticleCategory, ArticleCategoryParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
page.setDefaultOrder("sort_number asc,create_time desc");
return success(articleCategoryService.list(page.getOrderWrapper()));
// 使用关联查询
//return success(articleCategoryService.listRel(param));
@@ -2,6 +2,7 @@ package com.gxwebsoft.oa.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gxwebsoft.common.core.utils.CommonUtil;
import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController;
@@ -73,6 +74,13 @@ public class AppController extends BaseController {
@ApiOperation("根据id查询应用管理记录表")
@GetMapping("/{id}")
public ApiResult<App> get(@PathVariable("id") Integer id) {
final User loginUser = getLoginUser();
if (!CommonUtil.hasRole(loginUser.getRoles(),"superAdmin") || !CommonUtil.hasRole(loginUser.getRoles(),"admin")) {
// 查询权限
if (appUserService.count(new LambdaQueryWrapper<AppUser>().eq(AppUser::getUserId, getLoginUserId()).eq(AppUser::getAppId,id)) == 0) {
return fail("无查看权限",null);
}
}
// 使用关联查询
return success(appService.getByIdRel(id));
}
@@ -0,0 +1,115 @@
package com.gxwebsoft.oa.controller;
import com.gxwebsoft.common.core.web.*;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.oa.entity.Link;
import com.gxwebsoft.oa.param.LinkParam;
import com.gxwebsoft.oa.service.LinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 常用链接控制器
*
* @author 科技小王子
* @since 2024-01-14 11:50:39
*/
@Api(tags = "常用链接管理")
@RestController
@RequestMapping("/api/oa/link")
public class LinkController extends BaseController {
@Resource
private LinkService linkService;
@ApiOperation("分页查询常用链接")
@GetMapping("/page")
public ApiResult<PageResult<Link>> page(LinkParam param) {
PageParam<Link, LinkParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc,create_time desc");
return success(linkService.page(page, page.getWrapper()));
// 使用关联查询
//return success(linkService.pageRel(param));
}
@ApiOperation("查询全部常用链接")
@GetMapping()
public ApiResult<List<Link>> list(LinkParam param) {
PageParam<Link, LinkParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc,create_time desc");
return success(linkService.list(page.getOrderWrapper()));
// 使用关联查询
//return success(linkService.listRel(param));
}
@ApiOperation("根据id查询常用链接")
@GetMapping("/{id}")
public ApiResult<Link> get(@PathVariable("id") Integer id) {
return success(linkService.getById(id));
// 使用关联查询
//return success(linkService.getByIdRel(id));
}
@ApiOperation("添加常用链接")
@PostMapping()
public ApiResult<?> save(@RequestBody Link link) {
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
link.setUserId(loginUser.getUserId());
}
if (linkService.save(link)) {
return success("添加成功");
}
return fail("添加失败");
}
@ApiOperation("修改常用链接")
@PutMapping()
public ApiResult<?> update(@RequestBody Link link) {
if (linkService.updateById(link)) {
return success("修改成功");
}
return fail("修改失败");
}
@ApiOperation("删除常用链接")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
if (linkService.removeById(id)) {
return success("删除成功");
}
return fail("删除失败");
}
@ApiOperation("批量添加常用链接")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<Link> list) {
if (linkService.saveBatch(list)) {
return success("添加成功");
}
return fail("添加失败");
}
@ApiOperation("批量修改常用链接")
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<Link> batchParam) {
if (batchParam.update(linkService, "id")) {
return success("修改成功");
}
return fail("修改失败");
}
@ApiOperation("批量删除常用链接")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
if (linkService.removeByIds(ids)) {
return success("删除成功");
}
return fail("删除失败");
}
}
@@ -0,0 +1,72 @@
package com.gxwebsoft.oa.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.Date;
/**
* 常用链接
*
* @author 科技小王子
* @since 2024-01-14 11:50:39
*/
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "Link对象", description = "常用链接")
@TableName("oa_link")
public class Link implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "自增ID")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@ApiModelProperty(value = "链接名称")
private String name;
@ApiModelProperty(value = "图标")
private String icon;
@ApiModelProperty(value = "链接地址")
private String url;
@ApiModelProperty(value = "链接类型")
private String linkType;
@ApiModelProperty(value = "应用ID")
private Integer appId;
@ApiModelProperty(value = "用户ID")
private Integer userId;
@ApiModelProperty(value = "是否推荐")
private Integer recommend;
@ApiModelProperty(value = "备注")
private String comments;
@ApiModelProperty(value = "排序(数字越小越靠前)")
private Integer sortNumber;
@ApiModelProperty(value = "是否删除, 0否, 1是")
@TableLogic
private Integer deleted;
@ApiModelProperty(value = "状态, 0正常, 1待确认")
private Integer status;
@ApiModelProperty(value = "租户id")
private Integer tenantId;
@ApiModelProperty(value = "注册时间")
private Date createTime;
}
@@ -0,0 +1,37 @@
package com.gxwebsoft.oa.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxwebsoft.oa.entity.Link;
import com.gxwebsoft.oa.param.LinkParam;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 常用链接Mapper
*
* @author 科技小王子
* @since 2024-01-14 11:50:39
*/
public interface LinkMapper extends BaseMapper<Link> {
/**
* 分页查询
*
* @param page 分页对象
* @param param 查询参数
* @return List<Link>
*/
List<Link> selectPageRel(@Param("page") IPage<Link> page,
@Param("param") LinkParam param);
/**
* 查询全部
*
* @param param 查询参数
* @return List<User>
*/
List<Link> selectListRel(@Param("param") LinkParam param);
}
@@ -13,6 +13,9 @@
<if test="param.appId != null">
AND a.app_id = #{param.appId}
</if>
<if test="param.name != null">
AND a.name LIKE CONCAT('%', #{param.name}, '%')
</if>
<if test="param.comments != null">
AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
</if>
@@ -22,6 +25,9 @@
<if test="param.status != null">
AND a.status = #{param.status}
</if>
<if test="param.sortNumber != null">
AND a.sort_number = #{param.sortNumber}
</if>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gxwebsoft.oa.mapper.LinkMapper">
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
FROM oa_link a
<where>
<if test="param.id != null">
AND a.id = #{param.id}
</if>
<if test="param.name != null">
AND a.name LIKE CONCAT('%', #{param.name}, '%')
</if>
<if test="param.icon != null">
AND a.icon LIKE CONCAT('%', #{param.icon}, '%')
</if>
<if test="param.url != null">
AND a.url LIKE CONCAT('%', #{param.url}, '%')
</if>
<if test="param.linkType != null">
AND a.link_type LIKE CONCAT('%', #{param.linkType}, '%')
</if>
<if test="param.appId != null">
AND a.app_id = #{param.appId}
</if>
<if test="param.userId != null">
AND a.user_id = #{param.userId}
</if>
<if test="param.recommend != null">
AND a.recommend = #{param.recommend}
</if>
<if test="param.sortNumber != null">
AND a.sort_number = #{param.sortNumber}
</if>
<if test="param.deleted != null">
AND a.deleted = #{param.deleted}
</if>
<if test="param.deleted == null">
AND a.deleted = 0
</if>
<if test="param.status != null">
AND a.status = #{param.status}
</if>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
</where>
</sql>
<!-- 分页查询 -->
<select id="selectPageRel" resultType="com.gxwebsoft.oa.entity.Link">
<include refid="selectSql"></include>
</select>
<!-- 查询全部 -->
<select id="selectListRel" resultType="com.gxwebsoft.oa.entity.Link">
<include refid="selectSql"></include>
</select>
</mapper>
@@ -13,7 +13,7 @@ import lombok.EqualsAndHashCode;
* 应用参数查询参数
*
* @author 科技小王子
* @since 2024-01-12 20:08:35
* @since 2024-01-14 11:42:53
*/
@Data
@EqualsAndHashCode(callSuper = false)
@@ -30,6 +30,9 @@ public class AppFieldParam extends BaseParam {
@QueryField(type = QueryType.EQ)
private Integer appId;
@ApiModelProperty(value = "名称")
private String name;
@ApiModelProperty(value = "备注")
private String comments;
@@ -41,4 +44,8 @@ public class AppFieldParam extends BaseParam {
@QueryField(type = QueryType.EQ)
private Integer status;
@ApiModelProperty(value = "排序(数字越小越靠前)")
@QueryField(type = QueryType.EQ)
private Integer sortNumber;
}
@@ -0,0 +1,65 @@
package com.gxwebsoft.oa.param;
import com.gxwebsoft.common.core.annotation.QueryField;
import com.gxwebsoft.common.core.annotation.QueryType;
import com.gxwebsoft.common.core.web.BaseParam;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 常用链接查询参数
*
* @author 科技小王子
* @since 2024-01-14 11:50:39
*/
@Data
@EqualsAndHashCode(callSuper = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel(value = "LinkParam对象", description = "常用链接查询参数")
public class LinkParam extends BaseParam {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "自增ID")
@QueryField(type = QueryType.EQ)
private Integer id;
@ApiModelProperty(value = "链接名称")
private String name;
@ApiModelProperty(value = "图标")
private String icon;
@ApiModelProperty(value = "链接地址")
private String url;
@ApiModelProperty(value = "链接类型")
private String linkType;
@ApiModelProperty(value = "应用ID")
@QueryField(type = QueryType.EQ)
private Integer appId;
@ApiModelProperty(value = "用户ID")
@QueryField(type = QueryType.EQ)
private Integer userId;
@ApiModelProperty(value = "是否推荐")
@QueryField(type = QueryType.EQ)
private Integer recommend;
@ApiModelProperty(value = "排序(数字越小越靠前)")
@QueryField(type = QueryType.EQ)
private Integer sortNumber;
@ApiModelProperty(value = "是否删除, 0否, 1是")
@QueryField(type = QueryType.EQ)
private Integer deleted;
@ApiModelProperty(value = "状态, 0正常, 1待确认")
@QueryField(type = QueryType.EQ)
private Integer status;
}
@@ -11,7 +11,7 @@ import java.util.List;
* 应用参数Service
*
* @author 科技小王子
* @since 2024-01-12 20:08:35
* @since 2024-01-14 11:42:53
*/
public interface AppFieldService extends IService<AppField> {
@@ -0,0 +1,42 @@
package com.gxwebsoft.oa.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.oa.entity.Link;
import com.gxwebsoft.oa.param.LinkParam;
import java.util.List;
/**
* 常用链接Service
*
* @author 科技小王子
* @since 2024-01-14 11:50:39
*/
public interface LinkService extends IService<Link> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<Link>
*/
PageResult<Link> pageRel(LinkParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<Link>
*/
List<Link> listRel(LinkParam param);
/**
* 根据id查询
*
* @param id 自增ID
* @return Link
*/
Link getByIdRel(Integer id);
}
@@ -15,7 +15,7 @@ import java.util.List;
* 应用参数Service实现
*
* @author 科技小王子
* @since 2024-01-12 20:08:35
* @since 2024-01-14 11:42:53
*/
@Service
public class AppFieldServiceImpl extends ServiceImpl<AppFieldMapper, AppField> implements AppFieldService {
@@ -0,0 +1,47 @@
package com.gxwebsoft.oa.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.LinkMapper;
import com.gxwebsoft.oa.service.LinkService;
import com.gxwebsoft.oa.entity.Link;
import com.gxwebsoft.oa.param.LinkParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 常用链接Service实现
*
* @author 科技小王子
* @since 2024-01-14 11:50:39
*/
@Service
public class LinkServiceImpl extends ServiceImpl<LinkMapper, Link> implements LinkService {
@Override
public PageResult<Link> pageRel(LinkParam param) {
PageParam<Link, LinkParam> page = new PageParam<>(param);
//page.setDefaultOrder("create_time desc");
List<Link> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<Link> listRel(LinkParam param) {
List<Link> list = baseMapper.selectListRel(param);
// 排序
PageParam<Link, LinkParam> page = new PageParam<>();
//page.setDefaultOrder("create_time desc");
return page.sortRecords(list);
}
@Override
public Link getByIdRel(Integer id) {
LinkParam param = new LinkParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}