增加部门接口,支持用户部门关联

This commit is contained in:
qinjie 2024-11-17 02:47:06 +08:00
parent 6a31efbd0b
commit 91ca2b51f2
25 changed files with 469 additions and 183 deletions

View File

@ -1,55 +0,0 @@
package com.isu.gaswellwatch.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.annotation.OperationLog;
import com.isu.gaswellwatch.dto.CompanyDTO;
import com.isu.gaswellwatch.dto.CompanyEditDTO;
import com.isu.gaswellwatch.entity.Response;
import com.isu.gaswellwatch.enums.LogType;
import com.isu.gaswellwatch.service.CompanyService;
import com.isu.gaswellwatch.vo.CompanyVO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("company")
public class CompanyController {
/**
* 服务对象
*/
@Resource
private CompanyService companyService;
@GetMapping("/page")
public Response<Page<CompanyVO>> page(@RequestParam(defaultValue = "1") Integer currentPage,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String name,
@RequestParam(required = false) String code){
return Response.succeed(companyService.page(currentPage,pageSize,name,code));
}
@PostMapping("/add")
@OperationLog(description = "新增公司",type = LogType.ADD)
public Response<String> add(@RequestBody @Valid CompanyDTO companyDTO){
companyService.add(companyDTO);
return Response.succeed();
}
@PostMapping("/edit")
@OperationLog(description = "修改公司",type = LogType.UPDATE)
public Response<String> edit(@RequestBody @Valid CompanyEditDTO companyEditDTO){
companyService.edit(companyEditDTO);
return Response.succeed();
}
@GetMapping("/delete")
@OperationLog(description = "删除公司",type = LogType.DELETE)
public Response<String> delete(@RequestParam Long id){
companyService.delete(id);
return Response.succeed();
}
}

View File

@ -0,0 +1,63 @@
package com.isu.gaswellwatch.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.annotation.OperationLog;
import com.isu.gaswellwatch.dto.DepartmentDTO;
import com.isu.gaswellwatch.dto.DepartmentEditDTO;
import com.isu.gaswellwatch.entity.Department;
import com.isu.gaswellwatch.entity.Response;
import com.isu.gaswellwatch.enums.LogType;
import com.isu.gaswellwatch.service.DepartmentService;
import com.isu.gaswellwatch.vo.DepartmentVO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("department")
public class DepartmentController {
/**
* 服务对象
*/
@Resource
private DepartmentService departmentService;
@GetMapping("/page")
public Response<Page<DepartmentVO>> page(@RequestParam(defaultValue = "1") Integer currentPage,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String name,
@RequestParam(required = false) String code){
return Response.succeed(departmentService.page(currentPage,pageSize,name,code));
}
@PostMapping("/add")
@OperationLog(description = "新增部门",type = LogType.ADD)
public Response<String> add(@RequestBody @Valid DepartmentDTO companyDTO){
departmentService.add(companyDTO);
return Response.succeed();
}
@PostMapping("/edit")
@OperationLog(description = "修改部门",type = LogType.UPDATE)
public Response<String> edit(@RequestBody @Valid DepartmentEditDTO departmentEditDTO){
departmentService.edit(departmentEditDTO);
return Response.succeed();
}
@GetMapping("/delete")
@OperationLog(description = "删除部门",type = LogType.DELETE)
public Response<String> delete(@RequestParam Long id){
departmentService.delete(id);
return Response.succeed();
}
@GetMapping("/list")
public Response<List<Department>> list(){
return Response.succeed(departmentService.list());
}
}

View File

@ -6,13 +6,15 @@ import com.isu.gaswellwatch.annotation.OperationLog;
import com.isu.gaswellwatch.dto.RoleDTO;
import com.isu.gaswellwatch.dto.RoleEditDTO;
import com.isu.gaswellwatch.entity.Response;
import com.isu.gaswellwatch.entity.Role;
import com.isu.gaswellwatch.enums.LogType;
import com.isu.gaswellwatch.service.RoleService;
import com.isu.gaswellwatch.vo.RoleVO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("role")
@ -24,7 +26,7 @@ public class RoleController {
private RoleService roleService;
@GetMapping("/page")
public Response<Page<RoleVO>> page(@RequestParam(defaultValue = "1") Integer currentPage,
public Response<Page<Role>> page(@RequestParam(defaultValue = "1") Integer currentPage,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String name){
return Response.succeed(roleService.page(currentPage,pageSize,name));
@ -50,5 +52,10 @@ public class RoleController {
roleService.delete(id);
return Response.succeed();
}
@GetMapping("/list")
public Response<List<Role>> delete(){
return Response.succeed(roleService.list());
}
}

View File

@ -2,19 +2,17 @@ package com.isu.gaswellwatch.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.entity.Company;
import com.isu.gaswellwatch.vo.CompanyVO;
import com.isu.gaswellwatch.entity.Department;
import com.isu.gaswellwatch.vo.DepartmentVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface CompanyDao extends BaseMapper<Company> {
public interface DepartmentDao extends BaseMapper<Department> {
Page<CompanyVO> page(Page<Object> page,
Page<DepartmentVO> page(Page<Object> page,
@Param("name") String name,
@Param("code") String code
);

View File

@ -0,0 +1,13 @@
package com.isu.gaswellwatch.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isu.gaswellwatch.entity.UserDepartment;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@Mapper
@Repository
public interface UserDepartmentDao extends BaseMapper<UserDepartment> {
}

View File

@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CompanyDTO {
public class DepartmentDTO {
//公司名称
@NotBlank(message = "名称不能为空")
private String name;

View File

@ -12,7 +12,7 @@ import lombok.NoArgsConstructor;
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CompanyEditDTO {
public class DepartmentEditDTO {
@NotNull(message = "id不能为空")
private Long id;
//名称

View File

@ -32,4 +32,7 @@ public class UserEditDTO {
@NotNull(message = "角色不能为空")
private List<RoleVO> roles;
//部门ID
private Long departmentId;
}

View File

@ -9,7 +9,7 @@ import java.util.Date;
@Data
@Builder
public class Company extends Model<Company> {
public class Department extends Model<Department> {
private Long id;
//名称

View File

@ -0,0 +1,28 @@
package com.isu.gaswellwatch.entity;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Builder;
import lombok.Data;
import java.util.Date;
@Data
@Builder
public class UserDepartment extends Model<UserDepartment> {
private Long id;
//用户id
private Long userId;
//角色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;
}

View File

@ -1,17 +0,0 @@
package com.isu.gaswellwatch.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.isu.gaswellwatch.dto.CompanyDTO;
import com.isu.gaswellwatch.dto.CompanyEditDTO;
import com.isu.gaswellwatch.entity.Company;
import com.isu.gaswellwatch.vo.CompanyVO;
public interface CompanyService extends IService<Company> {
Page<CompanyVO> page(Integer currentPage, Integer pageSize, String name,String code);
void add(CompanyDTO companyDTO);
void edit(CompanyEditDTO companyEditDTO);
void delete(Long id);
}

View File

@ -0,0 +1,20 @@
package com.isu.gaswellwatch.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.isu.gaswellwatch.dto.DepartmentDTO;
import com.isu.gaswellwatch.dto.DepartmentEditDTO;
import com.isu.gaswellwatch.entity.Department;
import com.isu.gaswellwatch.vo.DepartmentVO;
import java.util.List;
public interface DepartmentService extends IService<Department> {
Page<DepartmentVO> page(Integer currentPage, Integer pageSize, String name, String code);
void add(DepartmentDTO companyDTO);
void edit(DepartmentEditDTO departmentEditDTO);
void delete(Long id);
}

View File

@ -9,7 +9,7 @@ import com.isu.gaswellwatch.vo.RoleVO;
public interface RoleService extends IService<Role> {
Page<RoleVO> page(Integer currentPage, Integer pageSize, String name);
Page<Role> page(Integer currentPage, Integer pageSize, String name);
void add(RoleDTO roleDTO);
void edit(RoleEditDTO roleEditDTO);
void delete(Long id);

View File

@ -0,0 +1,9 @@
package com.isu.gaswellwatch.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.isu.gaswellwatch.entity.UserDepartment;
public interface UserDepartmentService extends IService<UserDepartment> {
}

View File

@ -1,66 +0,0 @@
package com.isu.gaswellwatch.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isu.gaswellwatch.config.SnowflakeConfig;
import com.isu.gaswellwatch.service.CompanyService;
import com.isu.gaswellwatch.dao.CompanyDao;
import com.isu.gaswellwatch.dto.*;
import com.isu.gaswellwatch.entity.Company;
import com.isu.gaswellwatch.exception.BusinessException;
import com.isu.gaswellwatch.utils.ConverterUtil;
import com.isu.gaswellwatch.vo.CompanyVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service("companyService")
@Transactional(rollbackFor = Exception.class)
public class CompanyServiceImpl extends ServiceImpl<CompanyDao, Company> implements CompanyService {
@Resource
private SnowflakeConfig snowflakeConfig;
@Resource
private CompanyDao companyDao;
@Override
public Page<CompanyVO> page(Integer currentPage, Integer pageSize, String name,String code){
Page<CompanyVO> page = companyDao.page(new Page<>(currentPage, pageSize),name,code);
return ConverterUtil.convertPage(page,CompanyVO.class);
}
@Override
public void add(CompanyDTO companyDTO){
//查重
List<Company> list = list(new LambdaQueryWrapper<Company>().eq(Company::getName, companyDTO.getName()));
if(CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("已有相同名称,请重新输入");
}
Long companyId = snowflakeConfig.snowflakeId();
save(Company.builder().id(companyId).name(companyDTO.getName()).description(companyDTO.getDescription()).code(companyDTO.getCode()).build());
}
@Override
public void edit(CompanyEditDTO companyEditDTO){
List<Company> list = list(new LambdaQueryWrapper<Company>().eq(Company::getName, companyEditDTO.getName()).ne(Company::getId, companyEditDTO.getId()));
if(CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("公司名称已存在,请重新输入");
}
updateById(ConverterUtil.convert(companyEditDTO, Company.class));
}
@Override
public void delete(Long id){
//TODO 如果公司绑定了气井 不能删除
//删除
removeById(id);
}
}

View File

@ -0,0 +1,67 @@
package com.isu.gaswellwatch.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isu.gaswellwatch.config.SnowflakeConfig;
import com.isu.gaswellwatch.service.DepartmentService;
import com.isu.gaswellwatch.dao.DepartmentDao;
import com.isu.gaswellwatch.dto.*;
import com.isu.gaswellwatch.entity.Department;
import com.isu.gaswellwatch.exception.BusinessException;
import com.isu.gaswellwatch.utils.ConverterUtil;
import com.isu.gaswellwatch.vo.DepartmentVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service("departmentService")
@Transactional(rollbackFor = Exception.class)
public class DepartmentServiceImpl extends ServiceImpl<DepartmentDao, Department> implements DepartmentService {
@Resource
private SnowflakeConfig snowflakeConfig;
@Resource
private DepartmentDao companyDao;
@Override
public Page<DepartmentVO> page(Integer currentPage, Integer pageSize, String name, String code){
Page<DepartmentVO> page = companyDao.page(new Page<>(currentPage, pageSize),name,code);
return ConverterUtil.convertPage(page, DepartmentVO.class);
}
@Override
public void add(DepartmentDTO companyDTO){
//查重
List<Department> list = list(new LambdaQueryWrapper<Department>().eq(Department::getName, companyDTO.getName()));
if(CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("已有相同名称,请重新输入");
}
Long companyId = snowflakeConfig.snowflakeId();
save(Department.builder().id(companyId).name(companyDTO.getName()).description(companyDTO.getDescription()).code(companyDTO.getCode()).build());
}
@Override
public void edit(DepartmentEditDTO departmentEditDTO){
List<Department> list = list(new LambdaQueryWrapper<Department>().eq(Department::getName, departmentEditDTO.getName()).ne(Department::getId, departmentEditDTO.getId()));
if(CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("部门名称已存在,请重新输入");
}
updateById(ConverterUtil.convert(departmentEditDTO, Department.class));
}
@Override
public void delete(Long id){
//TODO 如果部门绑定了气井 不能删除
//删除
removeById(id);
}
}

View File

@ -42,9 +42,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleDao, Role> implements RoleS
private UserRoleService userRoleService;
@Override
public Page<RoleVO> page(Integer currentPage, Integer pageSize, String name){
Page<Role> page = page(new Page<>(currentPage, pageSize), new LambdaQueryWrapper<Role>().like(StringUtils.isNotBlank(name), Role::getName, name).orderByDesc(Role::getCreateTime));
return ConverterUtil.convertPage(page,RoleVO.class);
public Page<Role> page(Integer currentPage, Integer pageSize, String name){
return page(new Page<>(currentPage, pageSize), new LambdaQueryWrapper<Role>().like(StringUtils.isNotBlank(name), Role::getName, name).orderByDesc(Role::getCreateTime));
}
@Override

View File

@ -0,0 +1,15 @@
package com.isu.gaswellwatch.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isu.gaswellwatch.dao.UserDepartmentDao;
import com.isu.gaswellwatch.entity.UserDepartment;
import com.isu.gaswellwatch.service.UserDepartmentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service("userDepartmentService")
@Transactional(rollbackFor = Exception.class)
public class UserDepartmentServiceImpl extends ServiceImpl<UserDepartmentDao, UserDepartment> implements UserDepartmentService {
}

View File

@ -17,9 +17,11 @@ import com.isu.gaswellwatch.dto.ModifyPasswordDTO;
import com.isu.gaswellwatch.dto.UserDTO;
import com.isu.gaswellwatch.dto.UserEditDTO;
import com.isu.gaswellwatch.entity.User;
import com.isu.gaswellwatch.entity.UserDepartment;
import com.isu.gaswellwatch.entity.UserExport;
import com.isu.gaswellwatch.entity.UserRole;
import com.isu.gaswellwatch.exception.BusinessException;
import com.isu.gaswellwatch.service.UserDepartmentService;
import com.isu.gaswellwatch.service.UserRoleService;
import com.isu.gaswellwatch.service.UserService;
import com.isu.gaswellwatch.utils.ConverterUtil;
@ -48,6 +50,8 @@ public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserS
@Resource
private UserRoleService userRoleService;
@Resource
private UserDepartmentService userDepartmentService;
@Resource
private SnowflakeConfig snowflakeConfig;
@Resource
private MenuServiceImpl menuService;
@ -143,6 +147,16 @@ public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserS
//关联更新
userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, user.getId()));
addRelation(userEditDTO.getRoles(), user);
if(userEditDTO.getDepartmentId()!=null){
userDepartmentService.remove(new LambdaQueryWrapper<UserDepartment>().eq(UserDepartment::getUserId, user.getId()));
addDepartment(userEditDTO.getDepartmentId(), user);
}
}
private void addDepartment(Long departmentId, User user) {
UserDepartment.builder().id(snowflakeConfig.snowflakeId()).userId(user.getId()).departmentId(departmentId).build().insert();
}
@Override

View File

@ -6,13 +6,12 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CompanyVO implements Serializable {
public class DepartmentVO implements Serializable {
private Long id;
//名称
private String name;

View File

@ -17,4 +17,6 @@ public class RoleVO implements Serializable {
private String name;
//描述
private String description;
//创建时间
private String createTime;
}

View File

@ -27,4 +27,7 @@ public class UserVO implements Serializable {
//创建时间
private String createTime;
//所属部门
private DepartmentVO department;
}

View File

@ -11,17 +11,85 @@
Target Server Version : 80034
File Encoding : 65001
Date: 01/11/2024 16:44:33
Date: 17/11/2024 02:45:52
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for company
-- Table structure for blocks
-- ----------------------------
DROP TABLE IF EXISTS `company`;
CREATE TABLE `company` (
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
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='区块管理';
-- ----------------------------
-- Records of blocks
-- ----------------------------
BEGIN;
COMMIT;
-- ----------------------------
-- Table structure for command_points
-- ----------------------------
DROP TABLE IF EXISTS `command_points`;
CREATE TABLE `command_points` (
`command_id` bigint NOT NULL COMMENT '对应指令标识',
`id` bigint NOT NULL COMMENT '主键',
`field` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '采集后转换字段名称',
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '采集后显示名称',
`type` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '数据类型,主要用于读取数据长度控制int16,uint16,int32,uint32,int64,uint64,float,double,bit,string',
`address` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '采集驱动地址',
`factor` decimal(10,4) NOT NULL COMMENT '乘系数',
`precision` int DEFAULT NULL COMMENT '精度',
`details` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '描述',
`sort_num` int NOT NULL COMMENT '排序号',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='指令点表';
-- ----------------------------
-- Records of command_points
-- ----------------------------
BEGIN;
COMMIT;
-- ----------------------------
-- Table structure for commands
-- ----------------------------
DROP TABLE IF EXISTS `commands`;
CREATE TABLE `commands` (
`id` bigint NOT NULL COMMENT '主键',
`ref_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '引用类型DEVICE:设备DEVICE_TYPE:设备类型',
`ref_id` bigint NOT NULL COMMENT '引用对象标识',
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '指令名称',
`type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '指令类型Read:读Write:写默认Read。',
`collection_frequency` int DEFAULT NULL COMMENT '采集频率默认30秒。采集类指令必填',
`details` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '指令描述',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='指令表';
-- ----------------------------
-- Records of commands
-- ----------------------------
BEGIN;
COMMIT;
-- ----------------------------
-- Table structure for department
-- ----------------------------
DROP TABLE IF EXISTS `department`;
CREATE TABLE `department` (
`id` bigint NOT NULL,
`name` varchar(255) DEFAULT NULL COMMENT '公司名称',
`description` varchar(500) DEFAULT NULL COMMENT '描述',
@ -29,10 +97,82 @@ CREATE TABLE `company` (
`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`code` varchar(100) DEFAULT NULL COMMENT '公司编号',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='部门管理\n';
-- ----------------------------
-- Records of company
-- Records of department
-- ----------------------------
BEGIN;
INSERT INTO `department` (`id`, `name`, `description`, `create_time`, `update_time`, `code`) VALUES (1, '第一业务部', '', '2024-11-17 01:11:07', '2024-11-17 01:11:07', '0001');
INSERT INTO `department` (`id`, `name`, `description`, `create_time`, `update_time`, `code`) VALUES (2, '第二业务部', '', '2024-11-17 01:11:21', '2024-11-17 01:11:21', '0002');
COMMIT;
-- ----------------------------
-- Table structure for device_types
-- ----------------------------
DROP TABLE IF EXISTS `device_types`;
CREATE TABLE `device_types` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '名称',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='设备类型';
-- ----------------------------
-- Records of device_types
-- ----------------------------
BEGIN;
COMMIT;
-- ----------------------------
-- Table structure for devices
-- ----------------------------
DROP TABLE IF EXISTS `devices`;
CREATE TABLE `devices` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`device_type_id` bigint NOT NULL COMMENT '设备类型',
`code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '设备编号',
`group_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '分组名称',
`product_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '设备品牌',
`address` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '通讯地址',
`collection_flag` bit(1) NOT NULL COMMENT '是否采集标志',
`collection_frequency` int NOT NULL DEFAULT '30' COMMENT '采集频率默认30秒。',
`control_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '控制类型',
`running_mode` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '生产模式,计时器;间开电压',
`status` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '状态',
`status_time` datetime 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
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='设备列表';
-- ----------------------------
-- Records of devices
-- ----------------------------
BEGIN;
COMMIT;
-- ----------------------------
-- Table structure for gas_wells
-- ----------------------------
DROP TABLE IF EXISTS `gas_wells`;
CREATE TABLE `gas_wells` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`company_id` bigint DEFAULT 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_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
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='气井管理';
-- ----------------------------
-- Records of gas_wells
-- ----------------------------
BEGIN;
COMMIT;
@ -52,7 +192,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;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='菜单管理';
-- ----------------------------
-- Records of menu
@ -79,7 +219,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;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='角色管理';
-- ----------------------------
-- Records of role
@ -90,6 +230,8 @@ INSERT INTO `role` (`id`, `name`, `description`, `create_time`, `update_time`) V
INSERT INTO `role` (`id`, `name`, `description`, `create_time`, `update_time`) VALUES (1836581703372505088, '测试角色22', '测试角色2', '2024-09-19 09:42:54', '2024-09-19 09:55:03');
INSERT INTO `role` (`id`, `name`, `description`, `create_time`, `update_time`) VALUES (1836581757135093760, '测试角色234', '测试角色2', '2024-09-19 09:43:07', '2024-09-19 09:46:25');
INSERT INTO `role` (`id`, `name`, `description`, `create_time`, `update_time`) VALUES (1851162080074268672, '测试角色123', 'test', '2024-10-29 15:20:07', '2024-10-29 15:20:07');
INSERT INTO `role` (`id`, `name`, `description`, `create_time`, `update_time`) VALUES (1854116823323115520, '22222', '', '2024-11-06 19:01:13', '2024-11-06 19:01:13');
INSERT INTO `role` (`id`, `name`, `description`, `create_time`, `update_time`) VALUES (1854121363019661312, '33333', '', '2024-11-06 19:19:15', '2024-11-06 19:19:15');
COMMIT;
-- ----------------------------
@ -104,7 +246,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;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='角色菜单关联表';
-- ----------------------------
-- Records of role_menu
@ -118,6 +260,9 @@ 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 (6, 1, 1834501113332629504, NULL, '2024-10-29 15:31:35', '2024-10-29 15:31:35');
INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (7, 1, 1834501151140085760, NULL, '2024-10-29 15:31:51', '2024-10-29 15:31:51');
INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1851162080078462976, 1851162080074268672, 1834500910013743104, NULL, '2024-10-29 15:20:07', '2024-10-29 15:20:07');
INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1854116823335698432, 1854116823323115520, 1834499936926826496, NULL, '2024-11-06 19:01:13', '2024-11-06 19:01:13');
INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1854116823335698433, 1854116823323115520, 1834501029547212800, NULL, '2024-11-06 19:01:13', '2024-11-06 19:01:13');
INSERT INTO `role_menu` (`id`, `role_id`, `menu_id`, `identifier`, `create_time`, `update_time`) VALUES (1854116823335698434, 1854116823323115520, 1834501061923045376, NULL, '2024-11-06 19:01:13', '2024-11-06 19:01:13');
COMMIT;
-- ----------------------------
@ -135,7 +280,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;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='用户表';
-- ----------------------------
-- Records of user
@ -144,6 +289,27 @@ 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');
COMMIT;
-- ----------------------------
-- Table structure for user_department
-- ----------------------------
DROP TABLE IF EXISTS `user_department`;
CREATE TABLE `user_department` (
`id` bigint NOT NULL,
`user_id` bigint DEFAULT NULL COMMENT '用户id',
`department_id` bigint DEFAULT NULL COMMENT '部门id',
`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 user_department
-- ----------------------------
BEGIN;
INSERT INTO `user_department` (`id`, `user_id`, `department_id`, `create_time`, `update_time`) VALUES (1857847465089171456, 1850812935484473344, 1, '2024-11-17 02:05:27', '2024-11-17 02:05:27');
COMMIT;
-- ----------------------------
@ -166,7 +332,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;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='用户操作记录表';
-- ----------------------------
-- Records of user_operation_record
@ -185,7 +351,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;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='用户角色关联表';
-- ----------------------------
-- Records of user_role
@ -193,7 +359,8 @@ CREATE TABLE `user_role` (
BEGIN;
INSERT INTO `user_role` (`id`, `user_id`, `role_id`, `create_time`, `update_time`) VALUES (1, 1, 1, '2024-10-28 15:28:14', '2024-10-28 15:28:14');
INSERT INTO `user_role` (`id`, `user_id`, `role_id`, `create_time`, `update_time`) VALUES (1850808941676593152, 1850801224132067328, 1836575681450868736, '2024-10-28 15:56:52', '2024-10-28 15:56:52');
INSERT INTO `user_role` (`id`, `user_id`, `role_id`, `create_time`, `update_time`) VALUES (1850812935497056256, 1850812935484473344, 1836575681450868736, '2024-10-28 16:12:44', '2024-10-28 16:12:44');
INSERT INTO `user_role` (`id`, `user_id`, `role_id`, `create_time`, `update_time`) VALUES (1854057365498757120, 1853726975508611072, 1836581703372505088, '2024-11-06 15:04:57', '2024-11-06 15:04:57');
INSERT INTO `user_role` (`id`, `user_id`, `role_id`, `create_time`, `update_time`) VALUES (1857847465064005632, 1850812935484473344, 1836575681450868736, '2024-11-17 02:05:27', '2024-11-17 02:05:27');
COMMIT;
SET FOREIGN_KEY_CHECKS = 1;

View File

@ -1,10 +1,10 @@
<?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.isu.gaswellwatch.dao.CompanyDao">
<mapper namespace="com.isu.gaswellwatch.dao.DepartmentDao">
<select id="page" resultType="com.isu.gaswellwatch.vo.CompanyVO">
<select id="page" resultType="com.isu.gaswellwatch.vo.DepartmentVO">
select u.id, u.name, u.description, u.code, u.create_time, u.update_time
from company u
from department u
<where>
<if test="name!=null and name!='' ">
and u.name LIKE CONCAT('%',#{name},'%')

View File

@ -8,6 +8,12 @@
<result column="phone" property="phone"/>
<result column="is_enable" property="isEnable"/>
<result column="create_time" property="createTime"/>
<association property="department" javaType="com.isu.gaswellwatch.vo.DepartmentVO" >
<id column="departmentId" property="id"/>
<result column="departmentName" property="name"/>
<result column="departmentDescription" property="description"/>
<result column="departmentCode" property="code"/>
</association>
<collection property="roles" javaType="java.util.List" ofType="com.isu.gaswellwatch.vo.RoleVO">
<id column="roleId" property="id"/>
<result column="roleName" property="name"/>
@ -45,6 +51,8 @@
<result column="phone" property="phone"/>
<result column="is_enable" property="isEnable"/>
<result column="create_time" property="createTime"/>
<association property="department" javaType="com.isu.gaswellwatch.vo.DepartmentVO" select="getUserDepartment" column="{user_id=id}">
</association>
<collection property="roles" javaType="java.util.List" ofType="com.isu.gaswellwatch.vo.RoleVO" select="getUserRoles" column="{user_id=id}">
</collection>
</resultMap>
@ -79,12 +87,21 @@
where ur.user_id=#{user_id}
</select>
<select id="getUserDepartment" resultType="com.isu.gaswellwatch.vo.DepartmentVO">
SELECT d.id, d.name, d.description
FROM department d
LEFT JOIN user_department ud ON ud.department_id=d.id
where ud.user_id=#{user_id}
</select>
<select id="selectUserInfo" resultMap="userVOResultMap">
select u.id, u.username, u.nickname, u.phone, u.is_enable, r.id as roleId, r.name as roleName, r.description as roleDescription
select u.id, u.username, u.nickname, u.phone, u.is_enable, r.id as roleId, r.name as roleName, r.description as roleDescription,
d.id as departmentId, d.name as departmentName, d.description as departmentDescription,d.code as departmentCode
from user u
left join user_role t on u.id = t.user_id
left join role r on t.role_id = r.id
left join user_department ud on u.id = ud.user_id
left join department d on ud.department_id = d.id
where u.username = #{username}
</select>