diff --git a/src/main/java/com/isu/gaswellwatch/controller/BlockController.java b/src/main/java/com/isu/gaswellwatch/controller/BlockController.java index bb75d7e..0b094b7 100644 --- a/src/main/java/com/isu/gaswellwatch/controller/BlockController.java +++ b/src/main/java/com/isu/gaswellwatch/controller/BlockController.java @@ -43,23 +43,25 @@ public class BlockController { /** * 查询区块列表 */ - @GetMapping - public Response> page(BlockPageQuery query) { - return Response.succeed(blockService.pageForQuery(query)); + @GetMapping(value = "/page") + public Response> page(@RequestParam(defaultValue = "1") Integer currentPage, + @RequestParam(defaultValue = "10") Integer pageSize, + @RequestParam(required = false) String name) { + return Response.succeed(blockService.pageForQuery(currentPage, pageSize, name)); } /** * 获取区块详细信息 */ - @GetMapping(value = "/{id}") - public Response getInfo(@PathVariable("id") Long id) { + @GetMapping(value = "/getBlock") + public Response getInfo(@RequestParam Long id) { return Response.succeed(blockService.selectBlockById(id)); } /** * 新增区块 */ - @PostMapping + @PostMapping(value = "/add") @OperationLog(description = "新增区块", type = LogType.ADD) public Response add(@RequestBody @Valid BlockCreateRequest blockCreateRequest) { blockService.insertBlock(blockCreateRequest); @@ -69,7 +71,7 @@ public class BlockController { /** * 修改区块 */ - @PutMapping + @PostMapping(value = "/edit") @OperationLog(description = "修改区块", type = LogType.UPDATE) public Response edit(@RequestBody BlockEditRequest blockEditRequest) { blockService.updateBlock(blockEditRequest); @@ -79,11 +81,19 @@ public class BlockController { /** * 删除区块 */ - @DeleteMapping("/{ids}") + @GetMapping("/delete") @OperationLog(description = "删除区块", type = LogType.DELETE) - public Response delete(@PathVariable Collection ids) { - blockService.deleteBlockByIds(ids); + public Response delete(@RequestParam Long id) { + blockService.deleteBlockById(id); return Response.succeed(); } + /** + * 查询区块列表 + */ + @GetMapping("/list") + public Response> list() { + return Response.succeed(blockService.selectBlockList()); + } + } diff --git a/src/main/java/com/isu/gaswellwatch/dao/BlockDao.java b/src/main/java/com/isu/gaswellwatch/dao/BlockDao.java index 645c016..34e3ea2 100644 --- a/src/main/java/com/isu/gaswellwatch/dao/BlockDao.java +++ b/src/main/java/com/isu/gaswellwatch/dao/BlockDao.java @@ -4,11 +4,9 @@ import java.util.Collection; import java.util.List; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.isu.gaswellwatch.vo.BlockVO; -import com.isu.gaswellwatch.vo.BlockPageQuery; import com.isu.gaswellwatch.entity.Block; /** @@ -31,18 +29,17 @@ public interface BlockDao extends BaseMapper { /** * 查询区块列表 * - * @param block 区块 * @return 区块集合 */ - List selectBlockList(Block block); + List selectBlockList(Long departmentId); /** * 分页查询区块列表 - * - * @param query 查询条件 + * @param page 分页信息 + * @param name 区块名称 * @return 区块 */ - Page pageForQuery(Page page, @Param("query") BlockPageQuery query); + Page pageForQuery(Page page, String name); /** * 新增区块 diff --git a/src/main/java/com/isu/gaswellwatch/dao/BlockDepartmentDao.java b/src/main/java/com/isu/gaswellwatch/dao/BlockDepartmentDao.java new file mode 100644 index 0000000..fe39d61 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/dao/BlockDepartmentDao.java @@ -0,0 +1,13 @@ +package com.isu.gaswellwatch.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.isu.gaswellwatch.entity.BlockDepartment; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; + +@Mapper +@Repository +public interface BlockDepartmentDao extends BaseMapper { + +} + diff --git a/src/main/java/com/isu/gaswellwatch/dto/BlockCreateRequest.java b/src/main/java/com/isu/gaswellwatch/dto/BlockCreateRequest.java index 8438ccd..54cf36f 100644 --- a/src/main/java/com/isu/gaswellwatch/dto/BlockCreateRequest.java +++ b/src/main/java/com/isu/gaswellwatch/dto/BlockCreateRequest.java @@ -1,5 +1,6 @@ package com.isu.gaswellwatch.dto; +import jakarta.validation.constraints.NotBlank; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; @@ -28,14 +29,18 @@ public class BlockCreateRequest implements Serializable { @Serial private static final long serialVersionUID = 1L; - /** 上级标识 */ - private Long parentId; + /** id */ + private Long id; + @NotBlank(message = "名称不能为空!") /** 名称 */ private String name; /** 描述 */ private String details; + /** 部门id */ + private Long departmentId; + } diff --git a/src/main/java/com/isu/gaswellwatch/dto/BlockEditRequest.java b/src/main/java/com/isu/gaswellwatch/dto/BlockEditRequest.java index 5135950..f7d42ed 100644 --- a/src/main/java/com/isu/gaswellwatch/dto/BlockEditRequest.java +++ b/src/main/java/com/isu/gaswellwatch/dto/BlockEditRequest.java @@ -1,5 +1,7 @@ package com.isu.gaswellwatch.dto; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; @@ -29,15 +31,17 @@ public class BlockEditRequest implements Serializable { private static final long serialVersionUID = 1L; /** 主键 */ + @NotNull(message = "ID不能为空") private Long id; - /** 上级标识 */ - private Long parentId; /** 名称 */ + @NotBlank(message = "名称不能为空!") private String name; /** 描述 */ private String details; + /** 部门id */ + private Long departmentId; } diff --git a/src/main/java/com/isu/gaswellwatch/entity/Block.java b/src/main/java/com/isu/gaswellwatch/entity/Block.java index 171f950..26bcc6c 100644 --- a/src/main/java/com/isu/gaswellwatch/entity/Block.java +++ b/src/main/java/com/isu/gaswellwatch/entity/Block.java @@ -1,10 +1,7 @@ package com.isu.gaswellwatch.entity; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; +import com.isu.gaswellwatch.vo.DepartmentVO; +import lombok.*; import com.baomidou.mybatisplus.extension.activerecord.Model; import java.time.LocalDateTime; @@ -14,11 +11,10 @@ import java.time.LocalDateTime; * @author scwsl * @date 2024-11-17 */ -@Getter -@Setter +@Data +@Builder +@AllArgsConstructor @NoArgsConstructor -@ToString(callSuper = true) -@EqualsAndHashCode(callSuper = true) public class Block extends Model { private static final long serialVersionUID = 1L; @@ -26,29 +22,20 @@ public class Block extends Model { /** 主键 */ private Long id; - /** 上级标识 */ - private Long parentId; - /** 名称 */ private String name; /** 描述 */ private String details; - /** 是否已删除 */ - private Integer deleted; - - /** 创建人 */ - private Long createBy; - /** 创建时间 */ private LocalDateTime createTime; - /** 更新人 */ - private Long updateBy; - /** 更新时间 */ private LocalDateTime updateTime; + /** 关联部门 */ + private DepartmentVO department; + } diff --git a/src/main/java/com/isu/gaswellwatch/entity/BlockDepartment.java b/src/main/java/com/isu/gaswellwatch/entity/BlockDepartment.java new file mode 100644 index 0000000..a8a6349 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/entity/BlockDepartment.java @@ -0,0 +1,32 @@ +package com.isu.gaswellwatch.entity; + +import com.baomidou.mybatisplus.extension.activerecord.Model; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class BlockDepartment extends Model { + + private Long id; + //区块id + private Long blockId; + //角色id + private Long departmentId; + //创建时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + //更新时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date updateTime; + + +} + diff --git a/src/main/java/com/isu/gaswellwatch/mapper/BlockMapper.java b/src/main/java/com/isu/gaswellwatch/mapper/BlockMapper.java index 547d390..04431a2 100644 --- a/src/main/java/com/isu/gaswellwatch/mapper/BlockMapper.java +++ b/src/main/java/com/isu/gaswellwatch/mapper/BlockMapper.java @@ -36,26 +36,9 @@ public interface BlockMapper { List toPageVO(List entities); - default void copy(BlockEditRequest request, Block block) { - UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession() - .get(UserConstant.TOKEN_SESSION); - if (Objects.nonNull(userLoginInfoVO) && Objects.nonNull(userLoginInfoVO.getUserVO())) { - block.setUpdateBy(block.getCreateBy()); - } - block.setUpdateTime(LocalDateTime.now()); - copyToEntity(request, block); - } default Block create(BlockCreateRequest request) { - UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession() - .get(UserConstant.TOKEN_SESSION); - Block block =new Block(); - block.setCreateTime(LocalDateTime.now()); - block.setUpdateTime(block.getCreateTime()); - if (Objects.nonNull(userLoginInfoVO) && Objects.nonNull(userLoginInfoVO.getUserVO())) { - block.setCreateBy(userLoginInfoVO.getUserVO().getId()); - block.setUpdateBy(block.getCreateBy()); - } + Block block =Block.builder().build(); create(request, block); return block; } diff --git a/src/main/java/com/isu/gaswellwatch/service/BlockDepartmentService.java b/src/main/java/com/isu/gaswellwatch/service/BlockDepartmentService.java new file mode 100644 index 0000000..3c4ec7f --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/service/BlockDepartmentService.java @@ -0,0 +1,10 @@ +package com.isu.gaswellwatch.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.isu.gaswellwatch.entity.BlockDepartment; + + +public interface BlockDepartmentService extends IService { + +} + diff --git a/src/main/java/com/isu/gaswellwatch/service/BlockService.java b/src/main/java/com/isu/gaswellwatch/service/BlockService.java index f79201f..725db17 100644 --- a/src/main/java/com/isu/gaswellwatch/service/BlockService.java +++ b/src/main/java/com/isu/gaswellwatch/service/BlockService.java @@ -29,18 +29,16 @@ public interface BlockService extends IService { /** * 查询区块列表 * - * @param block 区块 * @return 区块集合 */ - List selectBlockList(Block block); + List selectBlockList(); /** * 分页查询区块列表 * - * @param query 查询条件 * @return 区块 */ - Page pageForQuery(BlockPageQuery query); + Page pageForQuery(Integer currentPage,Integer pageSize,String name); /** * 新增区块 @@ -48,7 +46,7 @@ public interface BlockService extends IService { * @param blockCreateRequest 区块 * @return 结果 */ - int insertBlock(BlockCreateRequest blockCreateRequest); + void insertBlock(BlockCreateRequest blockCreateRequest); /** * 修改区块 @@ -56,7 +54,7 @@ public interface BlockService extends IService { * @param blockEditRequest 区块 * @return 结果 */ - int updateBlock(BlockEditRequest blockEditRequest); + void updateBlock(BlockEditRequest blockEditRequest); /** * 删除区块信息 @@ -64,7 +62,7 @@ public interface BlockService extends IService { * @param id 区块主键 * @return 结果 */ - int deleteBlockById(Long id); + void deleteBlockById(Long id); /** * 批量删除区块 diff --git a/src/main/java/com/isu/gaswellwatch/service/UserService.java b/src/main/java/com/isu/gaswellwatch/service/UserService.java index 75145fb..85376a0 100644 --- a/src/main/java/com/isu/gaswellwatch/service/UserService.java +++ b/src/main/java/com/isu/gaswellwatch/service/UserService.java @@ -30,4 +30,6 @@ public interface UserService extends IService { void export(HttpServletResponse response, String username, String name, Long roleId, String isEnable); void setEnable(Long userId, String isEnable); List getMenuList(String username); + + UserVO selectUserInfo(String usernamee); } diff --git a/src/main/java/com/isu/gaswellwatch/service/impl/BlockDepartmentServiceImpl.java b/src/main/java/com/isu/gaswellwatch/service/impl/BlockDepartmentServiceImpl.java new file mode 100644 index 0000000..3b2ecae --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/service/impl/BlockDepartmentServiceImpl.java @@ -0,0 +1,15 @@ +package com.isu.gaswellwatch.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.isu.gaswellwatch.dao.BlockDepartmentDao; +import com.isu.gaswellwatch.entity.BlockDepartment; +import com.isu.gaswellwatch.service.BlockDepartmentService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service("blockDepartmentService") +@Transactional(rollbackFor = Exception.class) +public class BlockDepartmentServiceImpl extends ServiceImpl implements BlockDepartmentService { + +} + diff --git a/src/main/java/com/isu/gaswellwatch/service/impl/BlockServiceImpl.java b/src/main/java/com/isu/gaswellwatch/service/impl/BlockServiceImpl.java index 803b53f..8fe602f 100644 --- a/src/main/java/com/isu/gaswellwatch/service/impl/BlockServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/service/impl/BlockServiceImpl.java @@ -1,7 +1,20 @@ package com.isu.gaswellwatch.service.impl; +import java.util.ArrayList; import java.util.Collection; import java.util.List; + +import cn.dev33.satoken.stp.StpUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.isu.gaswellwatch.config.SnowflakeConfig; +import com.isu.gaswellwatch.constants.UserConstant; +import com.isu.gaswellwatch.entity.*; +import com.isu.gaswellwatch.service.BlockDepartmentService; +import com.isu.gaswellwatch.service.UserService; +import com.isu.gaswellwatch.utils.ConverterUtil; +import com.isu.gaswellwatch.vo.UserLoginInfoVO; +import com.isu.gaswellwatch.vo.UserVO; +import jakarta.annotation.Resource; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -11,7 +24,6 @@ import com.isu.gaswellwatch.dto.BlockEditRequest; import com.isu.gaswellwatch.vo.BlockPageQuery; import com.isu.gaswellwatch.vo.BlockVO; import com.isu.gaswellwatch.dao.BlockDao; -import com.isu.gaswellwatch.entity.Block; import com.isu.gaswellwatch.service.BlockService; import com.isu.gaswellwatch.mapper.BlockMapper; import org.mapstruct.factory.Mappers; @@ -30,6 +42,12 @@ public class BlockServiceImpl extends ServiceImpl implements B private final BlockDao blockDao; private final BlockMapper blockMapper = Mappers.getMapper(BlockMapper.class); + @Resource + private BlockDepartmentService blockDepartmentService; + @Resource + private UserService userService; + @Resource + private SnowflakeConfig snowflakeConfig; /** * 查询区块 @@ -39,29 +57,41 @@ public class BlockServiceImpl extends ServiceImpl implements B */ @Override public BlockVO selectBlockById(Long id) { - return blockMapper.toPageVO(blockDao.selectBlockById(id)); + return ConverterUtil.convert(blockDao.selectBlockById(id),BlockVO.class); } /** * 查询区块列表 * - * @param block 区块 * @return 区块 */ @Override - public List selectBlockList(Block block) { - return blockMapper.toPageVO(blockDao.selectBlockList(block)); + public List selectBlockList() { + //根据当前用户所属的部门筛选可以看到的区块 + UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession().get(UserConstant.TOKEN_SESSION); + UserVO userVO = userService.selectUserInfo(userLoginInfoVO.getUserVO().getUsername()); + if("admin".equals(userVO.getUsername())){ + //对admin用户不进行过滤筛选 + return blockDao.selectBlockList(null); + }else{ + if(userVO.getDepartment()!=null){ + return blockDao.selectBlockList(userVO.getDepartment().getId()); + }else{ + return new ArrayList<>(); + } + } + } /** * 分页查询区块列表 * - * @param query 查询条件 + * @param name 区块名称 * @return 区块 */ @Override - public Page pageForQuery(BlockPageQuery query){ - return blockDao.pageForQuery(new Page<>(query.getCurrentPage(), query.getPageSize()), query); + public Page pageForQuery(Integer currentPage,Integer pageSize,String name){ + return blockDao.pageForQuery(new Page<>(currentPage, pageSize), name); } /** @@ -72,8 +102,20 @@ public class BlockServiceImpl extends ServiceImpl implements B */ @Override @Transactional(rollbackFor = Throwable.class) - public int insertBlock(BlockCreateRequest blockCreateRequest) { - return blockDao.insertBlock(blockMapper.create(blockCreateRequest)); + public void insertBlock(BlockCreateRequest blockCreateRequest) { + + blockCreateRequest.setId(snowflakeConfig.snowflakeId()); + blockDao.insertBlock(blockMapper.create(blockCreateRequest)); + + //增加区块部门关联 + if(blockCreateRequest.getDepartmentId()!=null){ + blockDepartmentService.remove(new LambdaQueryWrapper().eq(BlockDepartment::getBlockId, blockCreateRequest.getId())); + addDepartment(blockCreateRequest.getDepartmentId(), blockCreateRequest.getId()); + } + } + + private void addDepartment(Long departmentId, Long blockId) { + BlockDepartment.builder().id(snowflakeConfig.snowflakeId()).blockId(blockId).departmentId(departmentId).build().insert(); } /** @@ -84,10 +126,14 @@ public class BlockServiceImpl extends ServiceImpl implements B */ @Override @Transactional(rollbackFor = Throwable.class) - public int updateBlock(BlockEditRequest blockEditRequest) { - Block block = blockDao.selectBlockById(blockEditRequest.getId()); - blockMapper.copyToEntity(blockEditRequest, block); - return blockDao.updateBlock(block); + public void updateBlock(BlockEditRequest blockEditRequest) { + updateById(Block.builder().id(blockEditRequest.getId()).name(blockEditRequest.getName()).details(blockEditRequest.getDetails()).build()); + + //增加区块部门关联 + if(blockEditRequest.getDepartmentId()!=null){ + blockDepartmentService.remove(new LambdaQueryWrapper().eq(BlockDepartment::getBlockId, blockEditRequest.getId())); + addDepartment(blockEditRequest.getDepartmentId(), blockEditRequest.getId()); + } } /** @@ -98,8 +144,9 @@ public class BlockServiceImpl extends ServiceImpl implements B */ @Override @Transactional(rollbackFor = Throwable.class) - public int deleteBlockById(Long id) { - return blockDao.deleteBlockById(id); + public void deleteBlockById(Long id) { + blockDao.deleteBlockById(id); + blockDepartmentService.remove(new LambdaQueryWrapper().eq(BlockDepartment::getBlockId, id)); } /** diff --git a/src/main/java/com/isu/gaswellwatch/service/impl/UserServiceImpl.java b/src/main/java/com/isu/gaswellwatch/service/impl/UserServiceImpl.java index 8c29fff..b72d002 100644 --- a/src/main/java/com/isu/gaswellwatch/service/impl/UserServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/service/impl/UserServiceImpl.java @@ -38,7 +38,6 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; @Service("userService") @@ -265,6 +264,11 @@ public class UserServiceImpl extends ServiceImpl implements UserS return new ArrayList<>(); } + @Override + public UserVO selectUserInfo(String username){ + return userDao.selectUserInfo(username); + } + private UserLoginInfoVO buildTokenSession(String username){ UserLoginInfoVO userInfoVO = new UserLoginInfoVO(); UserVO userVO = userDao.selectUserInfo(username); diff --git a/src/main/java/com/isu/gaswellwatch/vo/BlockPageQuery.java b/src/main/java/com/isu/gaswellwatch/vo/BlockPageQuery.java index b25a24e..56b0b72 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/BlockPageQuery.java +++ b/src/main/java/com/isu/gaswellwatch/vo/BlockPageQuery.java @@ -24,13 +24,7 @@ public class BlockPageQuery extends PageQuery { @Serial private static final long serialVersionUID = 1L; - /** 上级标识 */ - private Long parentId; - /** 名称 */ private String name; - /** 是否已删除 */ - private Integer deleted; - } diff --git a/src/main/java/com/isu/gaswellwatch/vo/BlockVO.java b/src/main/java/com/isu/gaswellwatch/vo/BlockVO.java index 819061d..1280a43 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/BlockVO.java +++ b/src/main/java/com/isu/gaswellwatch/vo/BlockVO.java @@ -9,7 +9,6 @@ import lombok.experimental.SuperBuilder; import java.io.Serial; import java.io.Serializable; -import java.time.LocalDateTime; /** * 区块页面返回对象 blocks @@ -31,28 +30,18 @@ public class BlockVO implements Serializable { /** 主键 */ private Long id; - /** 上级标识 */ - private Long parentId; - /** 名称 */ private String name; /** 描述 */ private String details; - /** 是否已删除 */ - private Integer deleted; - - /** 创建人 */ - private Long createBy; - /** 创建时间 */ - private LocalDateTime createTime; - - /** 更新人 */ - private Long updateBy; + private String createTime; /** 更新时间 */ - private LocalDateTime updateTime; + private String updateTime; + /** 关联部门 */ + private DepartmentVO department; } diff --git a/src/main/resources/gaswellwatch.sql b/src/main/resources/gaswellwatch.sql index 7bb45b5..3776e57 100644 --- a/src/main/resources/gaswellwatch.sql +++ b/src/main/resources/gaswellwatch.sql @@ -11,33 +11,56 @@ Target Server Version : 80034 File Encoding : 65001 - Date: 22/11/2024 17:54:19 + Date: 23/11/2024 18:48:09 */ SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- --- Table structure for blocks +-- Table structure for block -- ---------------------------- -DROP TABLE IF EXISTS `blocks`; -CREATE TABLE `blocks` ( - `id` bigint NOT NULL COMMENT '主键', - `parent_id` bigint NOT NULL COMMENT '上级标识', - `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '名称', - `details` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '描述', - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已删除', - `create_by` bigint NOT NULL COMMENT '创建人', - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_by` bigint NOT NULL COMMENT '更新人', - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - PRIMARY KEY (`id`) USING BTREE +DROP TABLE IF EXISTS `block`; +CREATE TABLE `block` ( + `id` bigint NOT NULL COMMENT '主键', + `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '名称', + `details` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '描述', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='区块管理'; -- ---------------------------- --- Records of blocks +-- Records of block -- ---------------------------- BEGIN; +INSERT INTO `block` (`id`, `name`, `details`, `create_time`, `update_time`) VALUES (1860217436825976832, '桃7', '测试用', '2024-11-23 15:02:52', '2024-11-23 15:02:52'); +INSERT INTO `block` (`id`, `name`, `details`, `create_time`, `update_time`) VALUES (1860217990331498496, '苏5', '测试用', '2024-11-23 15:05:04', '2024-11-23 15:05:04'); +INSERT INTO `block` (`id`, `name`, `details`, `create_time`, `update_time`) VALUES (1860218019209281536, '苏46', '测试用', '2024-11-23 15:05:11', '2024-11-23 15:05:11'); +INSERT INTO `block` (`id`, `name`, `details`, `create_time`, `update_time`) VALUES (1860233760696434688, '苏59', '测试用', '2024-11-23 16:07:44', '2024-11-23 16:07:44'); +COMMIT; + +-- ---------------------------- +-- Table structure for block_department +-- ---------------------------- +DROP TABLE IF EXISTS `block_department`; +CREATE TABLE `block_department` ( + `id` bigint NOT NULL COMMENT '主键', + `block_id` bigint NOT NULL, + `department_id` bigint NOT NULL, + `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='区块部门关联表'; + +-- ---------------------------- +-- Records of block_department +-- ---------------------------- +BEGIN; +INSERT INTO `block_department` (`id`, `block_id`, `department_id`, `create_time`, `update_time`) VALUES (1860217436872114176, 1860217436825976832, 1, '2024-11-23 15:02:52', '2024-11-23 15:02:52'); +INSERT INTO `block_department` (`id`, `block_id`, `department_id`, `create_time`, `update_time`) VALUES (1860217990339887104, 1860217990331498496, 1, '2024-11-23 15:05:04', '2024-11-23 15:05:04'); +INSERT INTO `block_department` (`id`, `block_id`, `department_id`, `create_time`, `update_time`) VALUES (1860218019217670144, 1860218019209281536, 1, '2024-11-23 15:05:11', '2024-11-23 15:05:11'); +INSERT INTO `block_department` (`id`, `block_id`, `department_id`, `create_time`, `update_time`) VALUES (1860233760709017600, 1860233760696434688, 2, '2024-11-23 16:07:44', '2024-11-23 16:07:44'); COMMIT; -- ---------------------------- @@ -172,7 +195,7 @@ CREATE TABLE `dictionary` ( PRIMARY KEY (`id`), KEY `type_index` (`type`) USING BTREE, KEY `type_code_index` (`type`,`code`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='字典表'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统字典表'; -- ---------------------------- -- Records of dictionary @@ -220,7 +243,7 @@ CREATE TABLE `menu` ( `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='菜单管理'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='菜单管理'; -- ---------------------------- -- Records of menu @@ -247,7 +270,7 @@ CREATE TABLE `role` ( `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='角色管理'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='角色管理'; -- ---------------------------- -- Records of role @@ -274,7 +297,7 @@ CREATE TABLE `role_menu` ( `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='角色菜单关联表'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='角色菜单关联表'; -- ---------------------------- -- Records of role_menu @@ -288,11 +311,14 @@ INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time` INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859271166338793472, 1854121363019661312, 1834500987037941760, NULL, '2024-11-21 00:22:44', '2024-11-21 00:22:44'); INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859271166338793473, 1854121363019661312, 1834501029547212800, NULL, '2024-11-21 00:22:44', '2024-11-21 00:22:44'); INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859271166338793474, 1854121363019661312, 1834501061923045376, NULL, '2024-11-21 00:22:44', '2024-11-21 00:22:44'); -INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859898030757511168, 1, 1834501029547212800, NULL, '2024-11-22 17:53:40', '2024-11-22 17:53:40'); -INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859898030757511169, 1, 1834500987037941760, NULL, '2024-11-22 17:53:40', '2024-11-22 17:53:40'); -INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859898030757511170, 1, 1834501061923045376, NULL, '2024-11-22 17:53:40', '2024-11-22 17:53:40'); -INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859898030757511171, 1, 1834501151140085760, NULL, '2024-11-22 17:53:40', '2024-11-22 17:53:40'); -INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859898030757511172, 1, 1834500910013743104, NULL, '2024-11-22 17:53:40', '2024-11-22 17:53:40'); +INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859942446616543232, 1, 1834501029547212800, NULL, '2024-11-22 20:50:09', '2024-11-22 20:50:09'); +INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859942446616543233, 1, 1834499936926826496, NULL, '2024-11-22 20:50:09', '2024-11-22 20:50:09'); +INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859942446616543234, 1, 1834500987037941760, NULL, '2024-11-22 20:50:09', '2024-11-22 20:50:09'); +INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859942446616543235, 1, 1834501061923045376, NULL, '2024-11-22 20:50:09', '2024-11-22 20:50:09'); +INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859942446616543236, 1, 1834501151140085760, NULL, '2024-11-22 20:50:09', '2024-11-22 20:50:09'); +INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859942446616543237, 1, 1834500910013743104, NULL, '2024-11-22 20:50:09', '2024-11-22 20:50:09'); +INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859942446616543238, 1, 1834501113332629504, NULL, '2024-11-22 20:50:09', '2024-11-22 20:50:09'); +INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1859942446616543239, 1, 1834501183620775936, NULL, '2024-11-22 20:50:09', '2024-11-22 20:50:09'); COMMIT; -- ---------------------------- @@ -310,7 +336,7 @@ CREATE TABLE `user` ( `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='用户表'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户表'; -- ---------------------------- -- Records of user @@ -319,7 +345,7 @@ BEGIN; INSERT INTO `user` (`id`, `username`, `password`, `nickname`, `phone`, `picture`, `is_enable`, `create_time`, `update_time`) VALUES (1, 'admin', '7c4a8d09ca3762af61e59520943dc26494f8941b', 'admin', '13028138200', NULL, '1', '2024-08-30 10:17:10', '2024-10-25 10:14:24'); INSERT INTO `user` (`id`, `username`, `password`, `nickname`, `phone`, `picture`, `is_enable`, `create_time`, `update_time`) VALUES (1850801224132067328, 'test1', '7c4a8d09ca3762af61e59520943dc26494f8941b', '张四', '13012341234', NULL, '1', '2024-10-28 15:26:12', '2024-10-28 15:56:52'); INSERT INTO `user` (`id`, `username`, `password`, `nickname`, `phone`, `picture`, `is_enable`, `create_time`, `update_time`) VALUES (1850812935484473344, 'test2', '7c4a8d09ca3762af61e59520943dc26494f8941b', '王五', '13012341235', NULL, '1', '2024-10-28 16:12:44', '2024-10-28 16:12:44'); -INSERT INTO `user` (`id`, `username`, `password`, `nickname`, `phone`, `picture`, `is_enable`, `create_time`, `update_time`) VALUES (1853726975508611072, '123d', '7c4a8d09ca3762af61e59520943dc26494f8941b', '123dd', '13333333331', NULL, '0', '2024-11-05 17:12:06', '2024-11-06 15:04:57'); +INSERT INTO `user` (`id`, `username`, `password`, `nickname`, `phone`, `picture`, `is_enable`, `create_time`, `update_time`) VALUES (1853726975508611072, '123d', '7c4a8d09ca3762af61e59520943dc26494f8941b', '123dd', '13333333331', NULL, '1', '2024-11-05 17:12:06', '2024-11-23 18:39:45'); INSERT INTO `user` (`id`, `username`, `password`, `nickname`, `phone`, `picture`, `is_enable`, `create_time`, `update_time`) VALUES (1859282476250169344, '123dd', '7c4a8d09ca3762af61e59520943dc26494f8941b', '安定', '13333333333', NULL, '1', '2024-11-21 01:07:40', '2024-11-21 01:07:40'); INSERT INTO `user` (`id`, `username`, `password`, `nickname`, `phone`, `picture`, `is_enable`, `create_time`, `update_time`) VALUES (1859283318915203072, 'dfg2', '7c4a8d09ca3762af61e59520943dc26494f8941b', '213安定', '13999999999', NULL, '1', '2024-11-21 01:11:01', '2024-11-21 01:11:01'); COMMIT; @@ -335,7 +361,7 @@ CREATE TABLE `user_department` ( `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='用户部门关联表'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户部门关联表'; -- ---------------------------- -- Records of user_department @@ -367,7 +393,7 @@ CREATE TABLE `user_operation_record` ( `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='用户操作记录表'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户操作记录表'; -- ---------------------------- -- Records of user_operation_record @@ -386,7 +412,7 @@ CREATE TABLE `user_role` ( `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='用户角色关联表'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户角色关联表'; -- ---------------------------- -- Records of user_role diff --git a/src/main/resources/mapper/BlockMapper.xml b/src/main/resources/mapper/BlockMapper.xml index f999a7a..7151189 100644 --- a/src/main/resources/mapper/BlockMapper.xml +++ b/src/main/resources/mapper/BlockMapper.xml @@ -6,103 +6,95 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - - - - + + + + - - - - - - + + + + + + + + - select t1.id, t1.parent_id, t1.name, t1.details, t1.deleted, t1.create_by, t1.create_time, t1.update_by, t1.update_time from blocks t1 + select t1.id, t1.`name`, t1.details, t1.create_time, t1.update_time from block t1 - - - and t1.parent_id = #{parentId} - and t1.name like concat('%', #{name}, '%') - and t1.deleted = #{deleted} + left join block_department bd on t1.id = bd.block_id + + bd.department_id = #{departmentId} + - insert into blocks + insert into block - parent_id, - name, + id, + `name`, details, - deleted, - create_by, - create_time, - update_by, - update_time, - #{parentId}, + #{id}, #{name}, #{details}, - #{deleted}, - #{createBy}, - #{createTime}, - #{updateBy}, - #{updateTime}, - update blocks + update block - parent_id = #{parentId}, name = #{name}, details = #{details}, - deleted = #{deleted}, - create_by = #{createBy}, - create_time = #{createTime}, - update_by = #{updateBy}, - update_time = #{updateTime}, where id = #{id} - delete from blocks where id = #{id} + delete from block where id = #{id} - delete from blocks where id in + delete from block where id in #{id} + + \ No newline at end of file