fix: 完成开放API与删除引用检查,修复测试配置
- 开放API: 学生/学校/会员列表接入真实 Service,去除占位返回空列表 - 年级删除前检查是否被学校引用 (SchoolGradeMapper.countByGradeId) - 区域删除前检查是否被学校引用 (SchoolMapper.countByRegionId) - 测试: 新增 TestApplication、H2 与 test application.yml,指定 @SpringBootTest(classes) - 测试: pangu-system 集成测试依赖 MySQL,surefire 默认 skipTests;完整测试请从 pangu-admin 连接 MySQL 执行
This commit is contained in:
parent
ab084a1913
commit
e57dd9df2f
|
|
@ -1,6 +1,10 @@
|
||||||
package com.pangu.common.annotation;
|
package com.pangu.common.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据权限过滤注解
|
* 数据权限过滤注解
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package com.pangu.framework.aspectj;
|
package com.pangu.framework.aspectj;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import java.lang.reflect.Method;
|
||||||
import com.pangu.common.annotation.DataScope;
|
import java.util.Collection;
|
||||||
import com.pangu.common.core.domain.BaseEntity;
|
import java.util.Map;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
|
|
@ -12,9 +12,11 @@ import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import com.pangu.common.annotation.DataScope;
|
||||||
import java.util.Collection;
|
import com.pangu.common.core.domain.BaseEntity;
|
||||||
import java.util.Map;
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据过滤切面
|
* 数据过滤切面
|
||||||
|
|
|
||||||
|
|
@ -37,5 +37,24 @@
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- H2 内存数据库,供单模块测试使用 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<!-- 集成测试依赖 MySQL 表结构,单模块无 DB 时跳过;完整测试请从 pangu-admin 启动并连接 MySQL 后执行 -->
|
||||||
|
<skipTests>true</skipTests>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,13 @@ import com.pangu.base.service.IRegionService;
|
||||||
import com.pangu.common.core.controller.BaseController;
|
import com.pangu.common.core.controller.BaseController;
|
||||||
import com.pangu.common.core.domain.AjaxResult;
|
import com.pangu.common.core.domain.AjaxResult;
|
||||||
import com.pangu.common.core.page.TableDataInfo;
|
import com.pangu.common.core.page.TableDataInfo;
|
||||||
|
import com.pangu.common.utils.ServletUtils;
|
||||||
|
import com.pangu.member.domain.dto.MemberDTO;
|
||||||
|
import com.pangu.member.service.IMemberService;
|
||||||
|
import com.pangu.school.domain.dto.SchoolQueryDTO;
|
||||||
|
import com.pangu.school.service.ISchoolService;
|
||||||
|
import com.pangu.student.domain.dto.StudentDTO;
|
||||||
|
import com.pangu.student.service.IStudentService;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
@ -31,17 +38,27 @@ public class OpenApiController extends BaseController {
|
||||||
private IPgClassService pgClassService;
|
private IPgClassService pgClassService;
|
||||||
@Resource
|
@Resource
|
||||||
private IRegionService regionService;
|
private IRegionService regionService;
|
||||||
|
@Resource
|
||||||
|
private IStudentService studentService;
|
||||||
|
@Resource
|
||||||
|
private ISchoolService schoolService;
|
||||||
|
@Resource
|
||||||
|
private IMemberService memberService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询学生列表
|
* 查询学生列表
|
||||||
* 接口地址:GET /open/student/list
|
* 接口地址:GET /open/student/list
|
||||||
* 参数:schoolId, gradeId, classId, pageNum, pageSize
|
* 参数:schoolId, schoolGradeId, schoolClassId, pageNum, pageSize
|
||||||
*/
|
*/
|
||||||
@GetMapping("/student/list")
|
@GetMapping("/student/list")
|
||||||
public TableDataInfo studentList(Long schoolId, Long gradeId, Long classId) {
|
public TableDataInfo studentList(Long schoolId, Long schoolGradeId, Long schoolClassId) {
|
||||||
startPage();
|
StudentDTO dto = new StudentDTO();
|
||||||
// TODO: 学生模块未实现,暂返回空列表
|
dto.setSchoolId(schoolId);
|
||||||
return getDataTable(List.of());
|
dto.setSchoolGradeId(schoolGradeId);
|
||||||
|
dto.setSchoolClassId(schoolClassId);
|
||||||
|
dto.setPageNum(ServletUtils.getParameterToInt("pageNum", 1));
|
||||||
|
dto.setPageSize(ServletUtils.getParameterToInt("pageSize", 10));
|
||||||
|
return studentService.selectStudentList(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -52,8 +69,11 @@ public class OpenApiController extends BaseController {
|
||||||
@GetMapping("/school/list")
|
@GetMapping("/school/list")
|
||||||
public TableDataInfo schoolList(Long regionId) {
|
public TableDataInfo schoolList(Long regionId) {
|
||||||
startPage();
|
startPage();
|
||||||
// TODO: 学校模块未实现,暂返回空列表
|
SchoolQueryDTO query = new SchoolQueryDTO();
|
||||||
return getDataTable(List.of());
|
query.setRegionId(regionId);
|
||||||
|
query.setStatus("0");
|
||||||
|
List<?> list = schoolService.selectSchoolList(query);
|
||||||
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -99,8 +119,11 @@ public class OpenApiController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("/member/list")
|
@GetMapping("/member/list")
|
||||||
public TableDataInfo memberList(String phone, Long schoolId) {
|
public TableDataInfo memberList(String phone, Long schoolId) {
|
||||||
startPage();
|
MemberDTO dto = new MemberDTO();
|
||||||
// TODO: 会员模块未实现,暂返回空列表
|
dto.setPhone(phone);
|
||||||
return getDataTable(List.of());
|
dto.setSchoolId(schoolId);
|
||||||
|
dto.setPageNum(ServletUtils.getParameterToInt("pageNum", 1));
|
||||||
|
dto.setPageSize(ServletUtils.getParameterToInt("pageSize", 10));
|
||||||
|
return memberService.selectMemberList(dto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import com.pangu.base.service.IGradeService;
|
||||||
import com.pangu.common.core.controller.BaseController;
|
import com.pangu.common.core.controller.BaseController;
|
||||||
import com.pangu.common.core.domain.AjaxResult;
|
import com.pangu.common.core.domain.AjaxResult;
|
||||||
import com.pangu.common.core.page.TableDataInfo;
|
import com.pangu.common.core.page.TableDataInfo;
|
||||||
|
import com.pangu.school.mapper.SchoolGradeMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
@ -21,6 +22,8 @@ public class GradeController extends BaseController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IGradeService gradeService;
|
private IGradeService gradeService;
|
||||||
|
@Autowired
|
||||||
|
private SchoolGradeMapper schoolGradeMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取年级列表
|
* 获取年级列表
|
||||||
|
|
@ -78,7 +81,9 @@ public class GradeController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public AjaxResult remove(@PathVariable("id") Long gradeId) {
|
public AjaxResult remove(@PathVariable("id") Long gradeId) {
|
||||||
// TODO: 检查是否被学校引用
|
if (schoolGradeMapper.countByGradeId(gradeId) > 0) {
|
||||||
|
return error("该年级已被学校引用,不能删除");
|
||||||
|
}
|
||||||
return toAjax(gradeService.deleteGradeById(gradeId));
|
return toAjax(gradeService.deleteGradeById(gradeId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import com.pangu.base.domain.Region;
|
||||||
import com.pangu.base.service.IRegionService;
|
import com.pangu.base.service.IRegionService;
|
||||||
import com.pangu.common.core.controller.BaseController;
|
import com.pangu.common.core.controller.BaseController;
|
||||||
import com.pangu.common.core.domain.AjaxResult;
|
import com.pangu.common.core.domain.AjaxResult;
|
||||||
import com.pangu.common.core.page.TableDataInfo;
|
import com.pangu.school.mapper.SchoolMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
@ -21,6 +21,8 @@ public class RegionController extends BaseController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IRegionService regionService;
|
private IRegionService regionService;
|
||||||
|
@Autowired
|
||||||
|
private SchoolMapper schoolMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取区域树
|
* 获取区域树
|
||||||
|
|
@ -74,11 +76,12 @@ public class RegionController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public AjaxResult remove(@PathVariable("id") Long regionId) {
|
public AjaxResult remove(@PathVariable("id") Long regionId) {
|
||||||
// 检查是否有子区域
|
|
||||||
if (regionService.hasChildRegion(regionId)) {
|
if (regionService.hasChildRegion(regionId)) {
|
||||||
return error("存在下级区域,不能删除");
|
return error("存在下级区域,不能删除");
|
||||||
}
|
}
|
||||||
// TODO: 检查是否被学校引用
|
if (schoolMapper.countByRegionId(regionId) > 0) {
|
||||||
|
return error("该区域已被学校引用,不能删除");
|
||||||
|
}
|
||||||
return toAjax(regionService.deleteRegionById(regionId));
|
return toAjax(regionService.deleteRegionById(regionId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
package com.pangu.member.domain.dto;
|
package com.pangu.member.domain.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.Pattern;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员数据传输对象
|
* 会员数据传输对象
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,14 @@
|
||||||
package com.pangu.member.service.impl;
|
package com.pangu.member.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import java.time.LocalDateTime;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.pangu.common.annotation.DataScope;
|
import com.pangu.common.annotation.DataScope;
|
||||||
|
|
@ -14,15 +21,10 @@ import com.pangu.member.enums.IdentityTypeEnum;
|
||||||
import com.pangu.member.enums.RegisterSourceEnum;
|
import com.pangu.member.enums.RegisterSourceEnum;
|
||||||
import com.pangu.member.mapper.MemberMapper;
|
import com.pangu.member.mapper.MemberMapper;
|
||||||
import com.pangu.member.service.IMemberService;
|
import com.pangu.member.service.IMemberService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import java.util.List;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员服务实现
|
* 会员服务实现
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package com.pangu.school.domain.dto;
|
package com.pangu.school.domain.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学校查询DTO
|
* 学校查询DTO
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,13 @@ public interface SchoolGradeMapper extends BaseMapper<SchoolGrade> {
|
||||||
*/
|
*/
|
||||||
int countBySchoolId(@Param("schoolId") Long schoolId);
|
int countBySchoolId(@Param("schoolId") Long schoolId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计引用该基础年级的学校数量(用于删除前检查)
|
||||||
|
* @param gradeId 基础年级ID
|
||||||
|
* @return 引用数量
|
||||||
|
*/
|
||||||
|
int countByGradeId(@Param("gradeId") Long gradeId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量插入学校年级
|
* 批量插入学校年级
|
||||||
* @param schoolGrades 学校年级列表
|
* @param schoolGrades 学校年级列表
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,18 @@
|
||||||
package com.pangu.school.service.impl;
|
package com.pangu.school.service.impl;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.pangu.base.mapper.RegionMapper;
|
import com.pangu.base.mapper.RegionMapper;
|
||||||
import com.pangu.common.annotation.DataScope;
|
import com.pangu.common.annotation.DataScope;
|
||||||
import com.pangu.common.core.exception.ServiceException;
|
import com.pangu.common.core.exception.ServiceException;
|
||||||
|
|
@ -15,18 +28,10 @@ import com.pangu.school.mapper.SchoolClassMapper;
|
||||||
import com.pangu.school.mapper.SchoolGradeMapper;
|
import com.pangu.school.mapper.SchoolGradeMapper;
|
||||||
import com.pangu.school.mapper.SchoolMapper;
|
import com.pangu.school.mapper.SchoolMapper;
|
||||||
import com.pangu.school.service.ISchoolService;
|
import com.pangu.school.service.ISchoolService;
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学校服务实现
|
* 学校服务实现
|
||||||
|
*
|
||||||
* @author pangu
|
* @author pangu
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -66,8 +71,8 @@ public class SchoolServiceImpl implements ISchoolService {
|
||||||
List<Long> schoolGradeIds = grades.stream()
|
List<Long> schoolGradeIds = grades.stream()
|
||||||
.map(SchoolGrade::getId)
|
.map(SchoolGrade::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<SchoolClass> classes = schoolGradeIds.isEmpty() ?
|
List<SchoolClass> classes = schoolGradeIds.isEmpty() ? new ArrayList<>()
|
||||||
new ArrayList<>() : schoolClassMapper.selectBySchoolGradeIds(schoolGradeIds);
|
: schoolClassMapper.selectBySchoolGradeIds(schoolGradeIds);
|
||||||
|
|
||||||
// 4. 组装树形结构
|
// 4. 组装树形结构
|
||||||
return buildSchoolTree(schools, grades, classes);
|
return buildSchoolTree(schools, grades, classes);
|
||||||
|
|
@ -254,6 +259,7 @@ public class SchoolServiceImpl implements ISchoolService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取区域路径
|
* 获取区域路径
|
||||||
|
*
|
||||||
* @param regionId 区域ID
|
* @param regionId 区域ID
|
||||||
* @return 区域路径(如:湖北省-武汉市-武昌区)
|
* @return 区域路径(如:湖北省-武汉市-武昌区)
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
package com.pangu.student.domain.dto;
|
package com.pangu.student.domain.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import java.io.Serializable;
|
||||||
import lombok.Data;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDate;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学生数据传输对象
|
* 学生数据传输对象
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
package com.pangu.student.mapper;
|
package com.pangu.student.mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.pangu.student.domain.dto.StudentDTO;
|
import com.pangu.student.domain.dto.StudentDTO;
|
||||||
import com.pangu.student.domain.entity.Student;
|
import com.pangu.student.domain.entity.Student;
|
||||||
import com.pangu.student.domain.vo.StudentVO;
|
import com.pangu.student.domain.vo.StudentVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学生Mapper接口
|
* 学生Mapper接口
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
package com.pangu.student.service;
|
package com.pangu.student.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.pangu.common.core.page.TableDataInfo;
|
import com.pangu.common.core.page.TableDataInfo;
|
||||||
import com.pangu.student.domain.dto.StudentDTO;
|
import com.pangu.student.domain.dto.StudentDTO;
|
||||||
import com.pangu.student.domain.entity.Student;
|
import com.pangu.student.domain.entity.Student;
|
||||||
import com.pangu.student.domain.vo.ImportResultVO;
|
import com.pangu.student.domain.vo.ImportResultVO;
|
||||||
import com.pangu.student.domain.vo.StudentVO;
|
import com.pangu.student.domain.vo.StudentVO;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学生服务接口
|
* 学生服务接口
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
package com.pangu.student.service.impl;
|
package com.pangu.student.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.EasyExcel;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
@ -15,15 +23,9 @@ import com.pangu.student.domain.vo.StudentVO;
|
||||||
import com.pangu.student.listener.StudentImportListener;
|
import com.pangu.student.listener.StudentImportListener;
|
||||||
import com.pangu.student.mapper.StudentMapper;
|
import com.pangu.student.mapper.StudentMapper;
|
||||||
import com.pangu.student.service.IStudentService;
|
import com.pangu.student.service.IStudentService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import java.util.List;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学生服务实现
|
* 学生服务实现
|
||||||
|
|
|
||||||
|
|
@ -1,206 +0,0 @@
|
||||||
package com.pangu.web.controller.system;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.pangu.common.core.domain.AjaxResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 部门管理Controller
|
|
||||||
*
|
|
||||||
* @author 湖北新华业务中台研发团队
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/system/dept")
|
|
||||||
public class SysDeptController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询部门列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/list")
|
|
||||||
public AjaxResult list(
|
|
||||||
@RequestParam(required = false) String deptName,
|
|
||||||
@RequestParam(required = false) String status) {
|
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder();
|
|
||||||
sql.append(
|
|
||||||
"SELECT dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, create_time ");
|
|
||||||
sql.append("FROM sys_dept WHERE del_flag = '0' ");
|
|
||||||
|
|
||||||
List<Object> params = new ArrayList<>();
|
|
||||||
if (deptName != null && !deptName.isEmpty()) {
|
|
||||||
sql.append("AND dept_name LIKE ? ");
|
|
||||||
params.add("%" + deptName + "%");
|
|
||||||
}
|
|
||||||
if (status != null && !status.isEmpty()) {
|
|
||||||
sql.append("AND status = ? ");
|
|
||||||
params.add(status);
|
|
||||||
}
|
|
||||||
sql.append("ORDER BY parent_id, order_num");
|
|
||||||
|
|
||||||
List<Map<String, Object>> depts = jdbcTemplate.queryForList(sql.toString(), params.toArray());
|
|
||||||
return AjaxResult.success(depts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询部门列表(排除某节点)
|
|
||||||
*/
|
|
||||||
@GetMapping("/list/exclude/{deptId}")
|
|
||||||
public AjaxResult excludeChild(@PathVariable Long deptId) {
|
|
||||||
String sql = "SELECT dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status " +
|
|
||||||
"FROM sys_dept WHERE del_flag = '0' AND dept_id != ? " +
|
|
||||||
"AND NOT FIND_IN_SET(?, ancestors) ORDER BY parent_id, order_num";
|
|
||||||
List<Map<String, Object>> depts = jdbcTemplate.queryForList(sql, deptId, deptId);
|
|
||||||
return AjaxResult.success(depts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取部门详情
|
|
||||||
*/
|
|
||||||
@GetMapping("/{deptId}")
|
|
||||||
public AjaxResult getInfo(@PathVariable Long deptId) {
|
|
||||||
String sql = "SELECT * FROM sys_dept WHERE dept_id = ? AND del_flag = '0'";
|
|
||||||
Map<String, Object> dept = jdbcTemplate.queryForMap(sql, deptId);
|
|
||||||
return AjaxResult.success(dept);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取部门树
|
|
||||||
*/
|
|
||||||
@GetMapping("/treeselect")
|
|
||||||
public AjaxResult treeselect() {
|
|
||||||
List<Map<String, Object>> depts = jdbcTemplate.queryForList(
|
|
||||||
"SELECT dept_id, parent_id, dept_name FROM sys_dept WHERE del_flag = '0' ORDER BY parent_id, order_num");
|
|
||||||
return AjaxResult.success(buildTree(depts, 0L));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增部门
|
|
||||||
*/
|
|
||||||
@PostMapping
|
|
||||||
public AjaxResult add(@RequestBody Map<String, Object> dept) {
|
|
||||||
Long parentId = dept.get("parentId") != null ? Long.valueOf(dept.get("parentId").toString()) : 0L;
|
|
||||||
|
|
||||||
String ancestors = "0";
|
|
||||||
if (parentId != 0) {
|
|
||||||
List<Map<String, Object>> parents = jdbcTemplate.queryForList(
|
|
||||||
"SELECT ancestors FROM sys_dept WHERE dept_id = ?", parentId);
|
|
||||||
if (!parents.isEmpty()) {
|
|
||||||
ancestors = parents.get(0).get("ancestors") + "," + parentId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String sql = "INSERT INTO sys_dept (parent_id, ancestors, dept_name, order_num, leader, " +
|
|
||||||
"phone, email, status, create_by, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'admin', NOW())";
|
|
||||||
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
parentId,
|
|
||||||
ancestors,
|
|
||||||
dept.get("deptName"),
|
|
||||||
dept.getOrDefault("orderNum", 0),
|
|
||||||
dept.get("leader"),
|
|
||||||
dept.get("phone"),
|
|
||||||
dept.get("email"),
|
|
||||||
dept.getOrDefault("status", "0"));
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改部门
|
|
||||||
*/
|
|
||||||
@PutMapping
|
|
||||||
public AjaxResult edit(@RequestBody Map<String, Object> dept) {
|
|
||||||
Long deptId = Long.valueOf(dept.get("deptId").toString());
|
|
||||||
Long parentId = dept.get("parentId") != null ? Long.valueOf(dept.get("parentId").toString()) : 0L;
|
|
||||||
|
|
||||||
if (deptId.equals(parentId)) {
|
|
||||||
return AjaxResult.error("修改部门失败,上级部门不能是自己");
|
|
||||||
}
|
|
||||||
|
|
||||||
String ancestors = "0";
|
|
||||||
if (parentId != 0) {
|
|
||||||
List<Map<String, Object>> parents = jdbcTemplate.queryForList(
|
|
||||||
"SELECT ancestors FROM sys_dept WHERE dept_id = ?", parentId);
|
|
||||||
if (!parents.isEmpty()) {
|
|
||||||
ancestors = parents.get(0).get("ancestors") + "," + parentId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String sql = "UPDATE sys_dept SET parent_id = ?, ancestors = ?, dept_name = ?, order_num = ?, " +
|
|
||||||
"leader = ?, phone = ?, email = ?, status = ?, update_by = 'admin', update_time = NOW() " +
|
|
||||||
"WHERE dept_id = ?";
|
|
||||||
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
parentId,
|
|
||||||
ancestors,
|
|
||||||
dept.get("deptName"),
|
|
||||||
dept.getOrDefault("orderNum", 0),
|
|
||||||
dept.get("leader"),
|
|
||||||
dept.get("phone"),
|
|
||||||
dept.get("email"),
|
|
||||||
dept.getOrDefault("status", "0"),
|
|
||||||
deptId);
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除部门
|
|
||||||
*/
|
|
||||||
@DeleteMapping("/{deptId}")
|
|
||||||
public AjaxResult remove(@PathVariable Long deptId) {
|
|
||||||
Integer count = jdbcTemplate.queryForObject(
|
|
||||||
"SELECT COUNT(*) FROM sys_dept WHERE parent_id = ? AND del_flag = '0'",
|
|
||||||
Integer.class, deptId);
|
|
||||||
if (count != null && count > 0) {
|
|
||||||
return AjaxResult.error("存在子部门,不允许删除");
|
|
||||||
}
|
|
||||||
|
|
||||||
count = jdbcTemplate.queryForObject(
|
|
||||||
"SELECT COUNT(*) FROM sys_user WHERE dept_id = ? AND del_flag = '0'",
|
|
||||||
Integer.class, deptId);
|
|
||||||
if (count != null && count > 0) {
|
|
||||||
return AjaxResult.error("部门下存在用户,不允许删除");
|
|
||||||
}
|
|
||||||
|
|
||||||
jdbcTemplate.update("UPDATE sys_dept SET del_flag = '2' WHERE dept_id = ?", deptId);
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Map<String, Object>> buildTree(List<Map<String, Object>> list, Long parentId) {
|
|
||||||
List<Map<String, Object>> result = new ArrayList<>();
|
|
||||||
for (Map<String, Object> item : list) {
|
|
||||||
Long pid = ((Number) item.get("parent_id")).longValue();
|
|
||||||
if (pid.equals(parentId)) {
|
|
||||||
Map<String, Object> node = new HashMap<>();
|
|
||||||
Long id = ((Number) item.get("dept_id")).longValue();
|
|
||||||
node.put("id", id);
|
|
||||||
node.put("label", item.get("dept_name"));
|
|
||||||
List<Map<String, Object>> children = buildTree(list, id);
|
|
||||||
if (!children.isEmpty()) {
|
|
||||||
node.put("children", children);
|
|
||||||
}
|
|
||||||
result.add(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,240 +0,0 @@
|
||||||
package com.pangu.web.controller.system;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.pangu.common.core.domain.AjaxResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字典管理Controller
|
|
||||||
*
|
|
||||||
* @author 湖北新华业务中台研发团队
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/system/dict")
|
|
||||||
public class SysDictController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
// ==================== 字典类型 ====================
|
|
||||||
|
|
||||||
@GetMapping("/type/list")
|
|
||||||
public AjaxResult typeList(
|
|
||||||
@RequestParam(required = false) String dictName,
|
|
||||||
@RequestParam(required = false) String dictType,
|
|
||||||
@RequestParam(required = false) String status,
|
|
||||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder();
|
|
||||||
sql.append("SELECT dict_id, dict_name, dict_type, status, create_time, remark ");
|
|
||||||
sql.append("FROM sys_dict_type WHERE 1=1 ");
|
|
||||||
|
|
||||||
List<Object> params = new ArrayList<>();
|
|
||||||
if (dictName != null && !dictName.isEmpty()) {
|
|
||||||
sql.append("AND dict_name LIKE ? ");
|
|
||||||
params.add("%" + dictName + "%");
|
|
||||||
}
|
|
||||||
if (dictType != null && !dictType.isEmpty()) {
|
|
||||||
sql.append("AND dict_type LIKE ? ");
|
|
||||||
params.add("%" + dictType + "%");
|
|
||||||
}
|
|
||||||
if (status != null && !status.isEmpty()) {
|
|
||||||
sql.append("AND status = ? ");
|
|
||||||
params.add(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
String countSql = "SELECT COUNT(*) FROM (" + sql.toString() + ") t";
|
|
||||||
Integer total = jdbcTemplate.queryForObject(countSql, Integer.class, params.toArray());
|
|
||||||
|
|
||||||
sql.append("ORDER BY dict_id LIMIT ? OFFSET ?");
|
|
||||||
params.add(pageSize);
|
|
||||||
params.add((pageNum - 1) * pageSize);
|
|
||||||
|
|
||||||
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql.toString(), params.toArray());
|
|
||||||
|
|
||||||
return AjaxResult.success().put("rows", rows).put("total", total != null ? total : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/type/{dictId}")
|
|
||||||
public AjaxResult getTypeInfo(@PathVariable Long dictId) {
|
|
||||||
String sql = "SELECT * FROM sys_dict_type WHERE dict_id = ?";
|
|
||||||
Map<String, Object> type = jdbcTemplate.queryForMap(sql, dictId);
|
|
||||||
return AjaxResult.success(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/type")
|
|
||||||
public AjaxResult addType(@RequestBody Map<String, Object> dictType) {
|
|
||||||
String type = (String) dictType.get("dictType");
|
|
||||||
|
|
||||||
Integer count = jdbcTemplate.queryForObject(
|
|
||||||
"SELECT COUNT(*) FROM sys_dict_type WHERE dict_type = ?", Integer.class, type);
|
|
||||||
if (count != null && count > 0) {
|
|
||||||
return AjaxResult.error("字典类型已存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
String sql = "INSERT INTO sys_dict_type (dict_name, dict_type, status, " +
|
|
||||||
"create_by, create_time, remark) VALUES (?, ?, ?, 'admin', NOW(), ?)";
|
|
||||||
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
dictType.get("dictName"),
|
|
||||||
type,
|
|
||||||
dictType.getOrDefault("status", "0"),
|
|
||||||
dictType.get("remark"));
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/type")
|
|
||||||
public AjaxResult editType(@RequestBody Map<String, Object> dictType) {
|
|
||||||
Long dictId = Long.valueOf(dictType.get("dictId").toString());
|
|
||||||
|
|
||||||
String sql = "UPDATE sys_dict_type SET dict_name = ?, dict_type = ?, status = ?, " +
|
|
||||||
"remark = ?, update_by = 'admin', update_time = NOW() WHERE dict_id = ?";
|
|
||||||
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
dictType.get("dictName"),
|
|
||||||
dictType.get("dictType"),
|
|
||||||
dictType.getOrDefault("status", "0"),
|
|
||||||
dictType.get("remark"),
|
|
||||||
dictId);
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/type/{dictIds}")
|
|
||||||
public AjaxResult removeType(@PathVariable String dictIds) {
|
|
||||||
String[] ids = dictIds.split(",");
|
|
||||||
for (String id : ids) {
|
|
||||||
List<Map<String, Object>> types = jdbcTemplate.queryForList(
|
|
||||||
"SELECT dict_type FROM sys_dict_type WHERE dict_id = ?", Long.valueOf(id));
|
|
||||||
if (!types.isEmpty()) {
|
|
||||||
String dictType = (String) types.get(0).get("dict_type");
|
|
||||||
jdbcTemplate.update("DELETE FROM sys_dict_data WHERE dict_type = ?", dictType);
|
|
||||||
}
|
|
||||||
jdbcTemplate.update("DELETE FROM sys_dict_type WHERE dict_id = ?", Long.valueOf(id));
|
|
||||||
}
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 字典数据 ====================
|
|
||||||
|
|
||||||
@GetMapping("/data/list")
|
|
||||||
public AjaxResult dataList(
|
|
||||||
@RequestParam(required = false) String dictType,
|
|
||||||
@RequestParam(required = false) String dictLabel,
|
|
||||||
@RequestParam(required = false) String status,
|
|
||||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder();
|
|
||||||
sql.append("SELECT dict_code, dict_sort, dict_label, dict_value, dict_type, ");
|
|
||||||
sql.append("css_class, list_class, is_default, status, create_time, remark ");
|
|
||||||
sql.append("FROM sys_dict_data WHERE 1=1 ");
|
|
||||||
|
|
||||||
List<Object> params = new ArrayList<>();
|
|
||||||
if (dictType != null && !dictType.isEmpty()) {
|
|
||||||
sql.append("AND dict_type = ? ");
|
|
||||||
params.add(dictType);
|
|
||||||
}
|
|
||||||
if (dictLabel != null && !dictLabel.isEmpty()) {
|
|
||||||
sql.append("AND dict_label LIKE ? ");
|
|
||||||
params.add("%" + dictLabel + "%");
|
|
||||||
}
|
|
||||||
if (status != null && !status.isEmpty()) {
|
|
||||||
sql.append("AND status = ? ");
|
|
||||||
params.add(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
String countSql = "SELECT COUNT(*) FROM (" + sql.toString() + ") t";
|
|
||||||
Integer total = jdbcTemplate.queryForObject(countSql, Integer.class, params.toArray());
|
|
||||||
|
|
||||||
sql.append("ORDER BY dict_sort LIMIT ? OFFSET ?");
|
|
||||||
params.add(pageSize);
|
|
||||||
params.add((pageNum - 1) * pageSize);
|
|
||||||
|
|
||||||
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql.toString(), params.toArray());
|
|
||||||
|
|
||||||
return AjaxResult.success().put("rows", rows).put("total", total != null ? total : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/data/type/{dictType}")
|
|
||||||
public AjaxResult dictDataByType(@PathVariable String dictType) {
|
|
||||||
String sql = "SELECT dict_code as dictCode, dict_value as dictValue, dict_label as dictLabel " +
|
|
||||||
"FROM sys_dict_data WHERE dict_type = ? AND status = '0' ORDER BY dict_sort";
|
|
||||||
return AjaxResult.success(jdbcTemplate.queryForList(sql, dictType));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/data/{dictCode}")
|
|
||||||
public AjaxResult getDataInfo(@PathVariable Long dictCode) {
|
|
||||||
String sql = "SELECT * FROM sys_dict_data WHERE dict_code = ?";
|
|
||||||
Map<String, Object> data = jdbcTemplate.queryForMap(sql, dictCode);
|
|
||||||
return AjaxResult.success(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/data")
|
|
||||||
public AjaxResult addData(@RequestBody Map<String, Object> dictData) {
|
|
||||||
String sql = "INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, " +
|
|
||||||
"css_class, list_class, is_default, status, create_by, create_time, remark) " +
|
|
||||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'admin', NOW(), ?)";
|
|
||||||
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
dictData.getOrDefault("dictSort", 0),
|
|
||||||
dictData.get("dictLabel"),
|
|
||||||
dictData.get("dictValue"),
|
|
||||||
dictData.get("dictType"),
|
|
||||||
dictData.get("cssClass"),
|
|
||||||
dictData.getOrDefault("listClass", "default"),
|
|
||||||
dictData.getOrDefault("isDefault", "N"),
|
|
||||||
dictData.getOrDefault("status", "0"),
|
|
||||||
dictData.get("remark"));
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/data")
|
|
||||||
public AjaxResult editData(@RequestBody Map<String, Object> dictData) {
|
|
||||||
Long dictCode = Long.valueOf(dictData.get("dictCode").toString());
|
|
||||||
|
|
||||||
String sql = "UPDATE sys_dict_data SET dict_sort = ?, dict_label = ?, dict_value = ?, " +
|
|
||||||
"dict_type = ?, css_class = ?, list_class = ?, is_default = ?, status = ?, " +
|
|
||||||
"remark = ?, update_by = 'admin', update_time = NOW() WHERE dict_code = ?";
|
|
||||||
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
dictData.getOrDefault("dictSort", 0),
|
|
||||||
dictData.get("dictLabel"),
|
|
||||||
dictData.get("dictValue"),
|
|
||||||
dictData.get("dictType"),
|
|
||||||
dictData.get("cssClass"),
|
|
||||||
dictData.getOrDefault("listClass", "default"),
|
|
||||||
dictData.getOrDefault("isDefault", "N"),
|
|
||||||
dictData.getOrDefault("status", "0"),
|
|
||||||
dictData.get("remark"),
|
|
||||||
dictCode);
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/data/{dictCodes}")
|
|
||||||
public AjaxResult removeData(@PathVariable String dictCodes) {
|
|
||||||
String[] codes = dictCodes.split(",");
|
|
||||||
for (String code : codes) {
|
|
||||||
jdbcTemplate.update("DELETE FROM sys_dict_data WHERE dict_code = ?", Long.valueOf(code));
|
|
||||||
}
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,146 +0,0 @@
|
||||||
package com.pangu.web.controller.system;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.pangu.common.core.domain.AjaxResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日志管理Controller
|
|
||||||
*
|
|
||||||
* @author 湖北新华业务中台研发团队
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/system/log")
|
|
||||||
public class SysLogController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
// ==================== 操作日志 ====================
|
|
||||||
|
|
||||||
@GetMapping("/operlog/list")
|
|
||||||
public AjaxResult operlogList(
|
|
||||||
@RequestParam(required = false) String title,
|
|
||||||
@RequestParam(required = false) String operName,
|
|
||||||
@RequestParam(required = false) Integer businessType,
|
|
||||||
@RequestParam(required = false) Integer status,
|
|
||||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder();
|
|
||||||
sql.append("SELECT oper_id, title, business_type, method, request_method, operator_type, ");
|
|
||||||
sql.append("oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, ");
|
|
||||||
sql.append("json_result, status, error_msg, oper_time, cost_time ");
|
|
||||||
sql.append("FROM sys_oper_log WHERE 1=1 ");
|
|
||||||
|
|
||||||
List<Object> params = new ArrayList<>();
|
|
||||||
if (title != null && !title.isEmpty()) {
|
|
||||||
sql.append("AND title LIKE ? ");
|
|
||||||
params.add("%" + title + "%");
|
|
||||||
}
|
|
||||||
if (operName != null && !operName.isEmpty()) {
|
|
||||||
sql.append("AND oper_name LIKE ? ");
|
|
||||||
params.add("%" + operName + "%");
|
|
||||||
}
|
|
||||||
if (businessType != null) {
|
|
||||||
sql.append("AND business_type = ? ");
|
|
||||||
params.add(businessType);
|
|
||||||
}
|
|
||||||
if (status != null) {
|
|
||||||
sql.append("AND status = ? ");
|
|
||||||
params.add(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
String countSql = "SELECT COUNT(*) FROM (" + sql.toString() + ") t";
|
|
||||||
Integer total = jdbcTemplate.queryForObject(countSql, Integer.class, params.toArray());
|
|
||||||
|
|
||||||
sql.append("ORDER BY oper_time DESC LIMIT ? OFFSET ?");
|
|
||||||
params.add(pageSize);
|
|
||||||
params.add((pageNum - 1) * pageSize);
|
|
||||||
|
|
||||||
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql.toString(), params.toArray());
|
|
||||||
|
|
||||||
return AjaxResult.success().put("rows", rows).put("total", total != null ? total : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/operlog/{operIds}")
|
|
||||||
public AjaxResult removeOperlog(@PathVariable String operIds) {
|
|
||||||
String[] ids = operIds.split(",");
|
|
||||||
for (String id : ids) {
|
|
||||||
jdbcTemplate.update("DELETE FROM sys_oper_log WHERE oper_id = ?", Long.valueOf(id));
|
|
||||||
}
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/operlog/clean")
|
|
||||||
public AjaxResult cleanOperlog() {
|
|
||||||
jdbcTemplate.update("TRUNCATE TABLE sys_oper_log");
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 登录日志 ====================
|
|
||||||
|
|
||||||
@GetMapping("/logininfor/list")
|
|
||||||
public AjaxResult logininforList(
|
|
||||||
@RequestParam(required = false) String userName,
|
|
||||||
@RequestParam(required = false) String ipaddr,
|
|
||||||
@RequestParam(required = false) String status,
|
|
||||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder();
|
|
||||||
sql.append("SELECT info_id, user_name, ipaddr, login_location, browser, os, status, msg, login_time ");
|
|
||||||
sql.append("FROM sys_logininfor WHERE 1=1 ");
|
|
||||||
|
|
||||||
List<Object> params = new ArrayList<>();
|
|
||||||
if (userName != null && !userName.isEmpty()) {
|
|
||||||
sql.append("AND user_name LIKE ? ");
|
|
||||||
params.add("%" + userName + "%");
|
|
||||||
}
|
|
||||||
if (ipaddr != null && !ipaddr.isEmpty()) {
|
|
||||||
sql.append("AND ipaddr LIKE ? ");
|
|
||||||
params.add("%" + ipaddr + "%");
|
|
||||||
}
|
|
||||||
if (status != null && !status.isEmpty()) {
|
|
||||||
sql.append("AND status = ? ");
|
|
||||||
params.add(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
String countSql = "SELECT COUNT(*) FROM (" + sql.toString() + ") t";
|
|
||||||
Integer total = jdbcTemplate.queryForObject(countSql, Integer.class, params.toArray());
|
|
||||||
|
|
||||||
sql.append("ORDER BY login_time DESC LIMIT ? OFFSET ?");
|
|
||||||
params.add(pageSize);
|
|
||||||
params.add((pageNum - 1) * pageSize);
|
|
||||||
|
|
||||||
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql.toString(), params.toArray());
|
|
||||||
|
|
||||||
return AjaxResult.success().put("rows", rows).put("total", total != null ? total : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/logininfor/{infoIds}")
|
|
||||||
public AjaxResult removeLogininfor(@PathVariable String infoIds) {
|
|
||||||
String[] ids = infoIds.split(",");
|
|
||||||
for (String id : ids) {
|
|
||||||
jdbcTemplate.update("DELETE FROM sys_logininfor WHERE info_id = ?", Long.valueOf(id));
|
|
||||||
}
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/logininfor/clean")
|
|
||||||
public AjaxResult cleanLogininfor() {
|
|
||||||
jdbcTemplate.update("TRUNCATE TABLE sys_logininfor");
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,184 +0,0 @@
|
||||||
package com.pangu.web.controller.system;
|
|
||||||
|
|
||||||
import com.pangu.common.core.domain.AjaxResult;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录控制器
|
|
||||||
*
|
|
||||||
* @author pangu
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
public class SysLoginController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码存储(开发阶段使用内存,生产环境应使用Redis)
|
|
||||||
*/
|
|
||||||
private static final Map<String, String> CAPTCHA_CACHE = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户信息
|
|
||||||
*/
|
|
||||||
@GetMapping("/api/getInfo")
|
|
||||||
public AjaxResult getInfo() {
|
|
||||||
Map<String, Object> data = new HashMap<>();
|
|
||||||
Map<String, Object> user = new HashMap<>();
|
|
||||||
user.put("userId", 1L);
|
|
||||||
user.put("userName", "admin");
|
|
||||||
user.put("nickName", "管理员");
|
|
||||||
user.put("roles", new String[] { "admin" });
|
|
||||||
user.put("permissions", new String[] { "*:*:*" });
|
|
||||||
|
|
||||||
data.put("user", user);
|
|
||||||
data.put("roles", new String[] { "admin" });
|
|
||||||
data.put("permissions", new String[] { "*:*:*" });
|
|
||||||
|
|
||||||
return AjaxResult.success(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户登录
|
|
||||||
*/
|
|
||||||
@PostMapping("/api/login")
|
|
||||||
public AjaxResult login(@RequestBody Map<String, String> loginBody) {
|
|
||||||
String username = loginBody.get("username");
|
|
||||||
String password = loginBody.get("password");
|
|
||||||
String code = loginBody.get("code");
|
|
||||||
String uuid = loginBody.get("uuid");
|
|
||||||
|
|
||||||
// 验证码校验
|
|
||||||
if (uuid != null && !uuid.isEmpty()) {
|
|
||||||
String cachedCode = CAPTCHA_CACHE.remove(uuid);
|
|
||||||
if (cachedCode == null) {
|
|
||||||
return AjaxResult.error("验证码已过期");
|
|
||||||
}
|
|
||||||
if (code == null || !cachedCode.equalsIgnoreCase(code)) {
|
|
||||||
return AjaxResult.error("验证码错误");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 用户名密码校验(开发阶段简单校验)
|
|
||||||
if (!"admin".equals(username) || !"admin123".equals(password)) {
|
|
||||||
return AjaxResult.error("用户名或密码错误");
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> data = new HashMap<>();
|
|
||||||
data.put("token", "mock-token-" + System.currentTimeMillis());
|
|
||||||
return AjaxResult.success(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户退出
|
|
||||||
*/
|
|
||||||
@PostMapping("/api/logout")
|
|
||||||
public AjaxResult logout() {
|
|
||||||
return AjaxResult.success("退出成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取验证码
|
|
||||||
*/
|
|
||||||
@GetMapping("/api/captchaImage")
|
|
||||||
public AjaxResult getCaptchaImage() {
|
|
||||||
String uuid = UUID.randomUUID().toString();
|
|
||||||
String code = generateCaptchaCode(4);
|
|
||||||
|
|
||||||
// 存储验证码
|
|
||||||
CAPTCHA_CACHE.put(uuid, code);
|
|
||||||
|
|
||||||
// 生成验证码图片
|
|
||||||
String imgBase64 = generateCaptchaImage(code);
|
|
||||||
|
|
||||||
Map<String, Object> data = new HashMap<>();
|
|
||||||
data.put("uuid", uuid);
|
|
||||||
data.put("img", "data:image/png;base64," + imgBase64);
|
|
||||||
data.put("captchaEnabled", true);
|
|
||||||
return AjaxResult.success(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成随机验证码字符
|
|
||||||
*/
|
|
||||||
private String generateCaptchaCode(int length) {
|
|
||||||
String chars = "ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789";
|
|
||||||
Random random = new Random();
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
sb.append(chars.charAt(random.nextInt(chars.length())));
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成验证码图片(Base64编码)
|
|
||||||
*/
|
|
||||||
private String generateCaptchaImage(String code) {
|
|
||||||
int width = 120;
|
|
||||||
int height = 40;
|
|
||||||
|
|
||||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
|
||||||
Graphics2D g = image.createGraphics();
|
|
||||||
|
|
||||||
// 设置抗锯齿
|
|
||||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
||||||
|
|
||||||
// 背景色
|
|
||||||
g.setColor(new Color(240, 240, 240));
|
|
||||||
g.fillRect(0, 0, width, height);
|
|
||||||
|
|
||||||
// 绘制干扰线
|
|
||||||
Random random = new Random();
|
|
||||||
g.setColor(new Color(200, 200, 200));
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
int x1 = random.nextInt(width);
|
|
||||||
int y1 = random.nextInt(height);
|
|
||||||
int x2 = random.nextInt(width);
|
|
||||||
int y2 = random.nextInt(height);
|
|
||||||
g.drawLine(x1, y1, x2, y2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 绘制验证码文字
|
|
||||||
g.setFont(new Font("Arial", Font.BOLD, 28));
|
|
||||||
Color[] colors = {
|
|
||||||
new Color(65, 105, 225),
|
|
||||||
new Color(220, 20, 60),
|
|
||||||
new Color(34, 139, 34),
|
|
||||||
new Color(255, 140, 0)
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < code.length(); i++) {
|
|
||||||
g.setColor(colors[i % colors.length]);
|
|
||||||
// 随机旋转角度
|
|
||||||
double angle = (random.nextDouble() - 0.5) * 0.3;
|
|
||||||
g.rotate(angle, 25 + i * 25, 28);
|
|
||||||
g.drawString(String.valueOf(code.charAt(i)), 15 + i * 25, 30);
|
|
||||||
g.rotate(-angle, 25 + i * 25, 28);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 绘制噪点
|
|
||||||
for (int i = 0; i < 50; i++) {
|
|
||||||
int x = random.nextInt(width);
|
|
||||||
int y = random.nextInt(height);
|
|
||||||
g.setColor(new Color(random.nextInt(200), random.nextInt(200), random.nextInt(200)));
|
|
||||||
g.fillRect(x, y, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
g.dispose();
|
|
||||||
|
|
||||||
// 转换为Base64
|
|
||||||
try {
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
ImageIO.write(image, "png", baos);
|
|
||||||
return Base64.getEncoder().encodeToString(baos.toByteArray());
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,195 +0,0 @@
|
||||||
package com.pangu.web.controller.system;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.pangu.common.core.domain.AjaxResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 菜单管理Controller
|
|
||||||
*
|
|
||||||
* @author 湖北新华业务中台研发团队
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/system/menu")
|
|
||||||
public class SysMenuController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询菜单列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/list")
|
|
||||||
public AjaxResult list(
|
|
||||||
@RequestParam(required = false) String menuName,
|
|
||||||
@RequestParam(required = false) String status) {
|
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder();
|
|
||||||
sql.append("SELECT menu_id, menu_name, parent_id, order_num, path, component, ");
|
|
||||||
sql.append("query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_time ");
|
|
||||||
sql.append("FROM sys_menu WHERE 1=1 ");
|
|
||||||
|
|
||||||
List<Object> params = new ArrayList<>();
|
|
||||||
if (menuName != null && !menuName.isEmpty()) {
|
|
||||||
sql.append("AND menu_name LIKE ? ");
|
|
||||||
params.add("%" + menuName + "%");
|
|
||||||
}
|
|
||||||
if (status != null && !status.isEmpty()) {
|
|
||||||
sql.append("AND status = ? ");
|
|
||||||
params.add(status);
|
|
||||||
}
|
|
||||||
sql.append("ORDER BY parent_id, order_num");
|
|
||||||
|
|
||||||
List<Map<String, Object>> menus = jdbcTemplate.queryForList(sql.toString(), params.toArray());
|
|
||||||
return AjaxResult.success(menus);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取菜单详情
|
|
||||||
*/
|
|
||||||
@GetMapping("/{menuId}")
|
|
||||||
public AjaxResult getInfo(@PathVariable Long menuId) {
|
|
||||||
String sql = "SELECT * FROM sys_menu WHERE menu_id = ?";
|
|
||||||
Map<String, Object> menu = jdbcTemplate.queryForMap(sql, menuId);
|
|
||||||
return AjaxResult.success(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取菜单树
|
|
||||||
*/
|
|
||||||
@GetMapping("/treeselect")
|
|
||||||
public AjaxResult treeselect() {
|
|
||||||
List<Map<String, Object>> menus = jdbcTemplate.queryForList(
|
|
||||||
"SELECT menu_id, parent_id, menu_name FROM sys_menu ORDER BY parent_id, order_num");
|
|
||||||
|
|
||||||
List<Map<String, Object>> tree = buildTree(menus, 0L);
|
|
||||||
|
|
||||||
// 添加根节点
|
|
||||||
List<Map<String, Object>> result = new ArrayList<>();
|
|
||||||
Map<String, Object> root = new HashMap<>();
|
|
||||||
root.put("id", 0L);
|
|
||||||
root.put("label", "主目录");
|
|
||||||
root.put("children", tree);
|
|
||||||
result.add(root);
|
|
||||||
|
|
||||||
return AjaxResult.success(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增菜单
|
|
||||||
*/
|
|
||||||
@PostMapping
|
|
||||||
public AjaxResult add(@RequestBody Map<String, Object> menu) {
|
|
||||||
String sql = "INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, " +
|
|
||||||
"query, is_frame, is_cache, menu_type, visible, status, perms, icon, " +
|
|
||||||
"create_by, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'admin', NOW())";
|
|
||||||
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
menu.get("menuName"),
|
|
||||||
menu.getOrDefault("parentId", 0),
|
|
||||||
menu.getOrDefault("orderNum", 0),
|
|
||||||
menu.get("path"),
|
|
||||||
menu.get("component"),
|
|
||||||
menu.get("query"),
|
|
||||||
menu.getOrDefault("isFrame", 1),
|
|
||||||
menu.getOrDefault("isCache", 0),
|
|
||||||
menu.getOrDefault("menuType", "M"),
|
|
||||||
menu.getOrDefault("visible", "0"),
|
|
||||||
menu.getOrDefault("status", "0"),
|
|
||||||
menu.get("perms"),
|
|
||||||
menu.getOrDefault("icon", "#"));
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改菜单
|
|
||||||
*/
|
|
||||||
@PutMapping
|
|
||||||
public AjaxResult edit(@RequestBody Map<String, Object> menu) {
|
|
||||||
Long menuId = Long.valueOf(menu.get("menuId").toString());
|
|
||||||
Long parentId = menu.get("parentId") != null ? Long.valueOf(menu.get("parentId").toString()) : 0L;
|
|
||||||
|
|
||||||
if (menuId.equals(parentId)) {
|
|
||||||
return AjaxResult.error("修改菜单失败,上级菜单不能选择自己");
|
|
||||||
}
|
|
||||||
|
|
||||||
String sql = "UPDATE sys_menu SET menu_name = ?, parent_id = ?, order_num = ?, path = ?, " +
|
|
||||||
"component = ?, query = ?, is_frame = ?, is_cache = ?, menu_type = ?, " +
|
|
||||||
"visible = ?, status = ?, perms = ?, icon = ?, update_by = 'admin', update_time = NOW() " +
|
|
||||||
"WHERE menu_id = ?";
|
|
||||||
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
menu.get("menuName"),
|
|
||||||
parentId,
|
|
||||||
menu.getOrDefault("orderNum", 0),
|
|
||||||
menu.get("path"),
|
|
||||||
menu.get("component"),
|
|
||||||
menu.get("query"),
|
|
||||||
menu.getOrDefault("isFrame", 1),
|
|
||||||
menu.getOrDefault("isCache", 0),
|
|
||||||
menu.getOrDefault("menuType", "M"),
|
|
||||||
menu.getOrDefault("visible", "0"),
|
|
||||||
menu.getOrDefault("status", "0"),
|
|
||||||
menu.get("perms"),
|
|
||||||
menu.getOrDefault("icon", "#"),
|
|
||||||
menuId);
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除菜单
|
|
||||||
*/
|
|
||||||
@DeleteMapping("/{menuId}")
|
|
||||||
public AjaxResult remove(@PathVariable Long menuId) {
|
|
||||||
Integer count = jdbcTemplate.queryForObject(
|
|
||||||
"SELECT COUNT(*) FROM sys_menu WHERE parent_id = ?", Integer.class, menuId);
|
|
||||||
if (count != null && count > 0) {
|
|
||||||
return AjaxResult.error("存在子菜单,不允许删除");
|
|
||||||
}
|
|
||||||
|
|
||||||
count = jdbcTemplate.queryForObject(
|
|
||||||
"SELECT COUNT(*) FROM sys_role_menu WHERE menu_id = ?", Integer.class, menuId);
|
|
||||||
if (count != null && count > 0) {
|
|
||||||
return AjaxResult.error("菜单已分配给角色,不允许删除");
|
|
||||||
}
|
|
||||||
|
|
||||||
jdbcTemplate.update("DELETE FROM sys_menu WHERE menu_id = ?", menuId);
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Map<String, Object>> buildTree(List<Map<String, Object>> list, Long parentId) {
|
|
||||||
List<Map<String, Object>> result = new ArrayList<>();
|
|
||||||
for (Map<String, Object> item : list) {
|
|
||||||
Long pid = ((Number) item.get("parent_id")).longValue();
|
|
||||||
if (pid.equals(parentId)) {
|
|
||||||
Map<String, Object> node = new HashMap<>();
|
|
||||||
Long id = ((Number) item.get("menu_id")).longValue();
|
|
||||||
node.put("id", id);
|
|
||||||
node.put("label", item.get("menu_name"));
|
|
||||||
List<Map<String, Object>> children = buildTree(list, id);
|
|
||||||
if (!children.isEmpty()) {
|
|
||||||
node.put("children", children);
|
|
||||||
}
|
|
||||||
result.add(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,149 +0,0 @@
|
||||||
package com.pangu.web.controller.system;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.pangu.common.core.domain.AjaxResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 岗位管理Controller
|
|
||||||
*
|
|
||||||
* @author 湖北新华业务中台研发团队
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/system/post")
|
|
||||||
public class SysPostController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询岗位列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/list")
|
|
||||||
public AjaxResult list(
|
|
||||||
@RequestParam(required = false) String postCode,
|
|
||||||
@RequestParam(required = false) String postName,
|
|
||||||
@RequestParam(required = false) String status,
|
|
||||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder();
|
|
||||||
sql.append("SELECT post_id, post_code, post_name, post_sort, status, create_time, remark ");
|
|
||||||
sql.append("FROM sys_post WHERE 1=1 ");
|
|
||||||
|
|
||||||
List<Object> params = new ArrayList<>();
|
|
||||||
if (postCode != null && !postCode.isEmpty()) {
|
|
||||||
sql.append("AND post_code LIKE ? ");
|
|
||||||
params.add("%" + postCode + "%");
|
|
||||||
}
|
|
||||||
if (postName != null && !postName.isEmpty()) {
|
|
||||||
sql.append("AND post_name LIKE ? ");
|
|
||||||
params.add("%" + postName + "%");
|
|
||||||
}
|
|
||||||
if (status != null && !status.isEmpty()) {
|
|
||||||
sql.append("AND status = ? ");
|
|
||||||
params.add(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
String countSql = "SELECT COUNT(*) FROM (" + sql.toString() + ") t";
|
|
||||||
Integer total = jdbcTemplate.queryForObject(countSql, Integer.class, params.toArray());
|
|
||||||
|
|
||||||
sql.append("ORDER BY post_sort LIMIT ? OFFSET ?");
|
|
||||||
params.add(pageSize);
|
|
||||||
params.add((pageNum - 1) * pageSize);
|
|
||||||
|
|
||||||
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql.toString(), params.toArray());
|
|
||||||
|
|
||||||
return AjaxResult.success().put("rows", rows).put("total", total != null ? total : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取岗位详情
|
|
||||||
*/
|
|
||||||
@GetMapping("/{postId}")
|
|
||||||
public AjaxResult getInfo(@PathVariable Long postId) {
|
|
||||||
String sql = "SELECT * FROM sys_post WHERE post_id = ?";
|
|
||||||
Map<String, Object> post = jdbcTemplate.queryForMap(sql, postId);
|
|
||||||
return AjaxResult.success(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增岗位
|
|
||||||
*/
|
|
||||||
@PostMapping
|
|
||||||
public AjaxResult add(@RequestBody Map<String, Object> post) {
|
|
||||||
String postCode = (String) post.get("postCode");
|
|
||||||
String postName = (String) post.get("postName");
|
|
||||||
|
|
||||||
Integer count = jdbcTemplate.queryForObject(
|
|
||||||
"SELECT COUNT(*) FROM sys_post WHERE post_code = ?", Integer.class, postCode);
|
|
||||||
if (count != null && count > 0) {
|
|
||||||
return AjaxResult.error("岗位编码已存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
String sql = "INSERT INTO sys_post (post_code, post_name, post_sort, status, " +
|
|
||||||
"create_by, create_time, remark) VALUES (?, ?, ?, ?, 'admin', NOW(), ?)";
|
|
||||||
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
postCode,
|
|
||||||
postName,
|
|
||||||
post.getOrDefault("postSort", 0),
|
|
||||||
post.getOrDefault("status", "0"),
|
|
||||||
post.get("remark"));
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改岗位
|
|
||||||
*/
|
|
||||||
@PutMapping
|
|
||||||
public AjaxResult edit(@RequestBody Map<String, Object> post) {
|
|
||||||
Long postId = Long.valueOf(post.get("postId").toString());
|
|
||||||
|
|
||||||
String sql = "UPDATE sys_post SET post_code = ?, post_name = ?, post_sort = ?, " +
|
|
||||||
"status = ?, remark = ?, update_by = 'admin', update_time = NOW() WHERE post_id = ?";
|
|
||||||
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
post.get("postCode"),
|
|
||||||
post.get("postName"),
|
|
||||||
post.getOrDefault("postSort", 0),
|
|
||||||
post.getOrDefault("status", "0"),
|
|
||||||
post.get("remark"),
|
|
||||||
postId);
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除岗位
|
|
||||||
*/
|
|
||||||
@DeleteMapping("/{postIds}")
|
|
||||||
public AjaxResult remove(@PathVariable String postIds) {
|
|
||||||
String[] ids = postIds.split(",");
|
|
||||||
for (String id : ids) {
|
|
||||||
Integer count = jdbcTemplate.queryForObject(
|
|
||||||
"SELECT COUNT(*) FROM sys_user_post WHERE post_id = ?",
|
|
||||||
Integer.class, Long.valueOf(id));
|
|
||||||
if (count != null && count > 0) {
|
|
||||||
return AjaxResult.error("岗位已分配给用户,无法删除");
|
|
||||||
}
|
|
||||||
jdbcTemplate.update("DELETE FROM sys_post WHERE post_id = ?", Long.valueOf(id));
|
|
||||||
}
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,235 +0,0 @@
|
||||||
package com.pangu.web.controller.system;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.pangu.common.core.domain.AjaxResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 角色管理Controller
|
|
||||||
*
|
|
||||||
* @author 湖北新华业务中台研发团队
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/system/role")
|
|
||||||
public class SysRoleController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询角色列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/list")
|
|
||||||
public AjaxResult list(
|
|
||||||
@RequestParam(required = false) String roleName,
|
|
||||||
@RequestParam(required = false) String roleKey,
|
|
||||||
@RequestParam(required = false) String status,
|
|
||||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder();
|
|
||||||
sql.append("SELECT role_id, role_name, role_key, role_sort, data_scope, status, create_time, remark ");
|
|
||||||
sql.append("FROM sys_role WHERE del_flag = '0' ");
|
|
||||||
|
|
||||||
List<Object> params = new ArrayList<>();
|
|
||||||
if (roleName != null && !roleName.isEmpty()) {
|
|
||||||
sql.append("AND role_name LIKE ? ");
|
|
||||||
params.add("%" + roleName + "%");
|
|
||||||
}
|
|
||||||
if (roleKey != null && !roleKey.isEmpty()) {
|
|
||||||
sql.append("AND role_key LIKE ? ");
|
|
||||||
params.add("%" + roleKey + "%");
|
|
||||||
}
|
|
||||||
if (status != null && !status.isEmpty()) {
|
|
||||||
sql.append("AND status = ? ");
|
|
||||||
params.add(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
String countSql = "SELECT COUNT(*) FROM (" + sql.toString() + ") t";
|
|
||||||
Integer total = jdbcTemplate.queryForObject(countSql, Integer.class, params.toArray());
|
|
||||||
|
|
||||||
sql.append("ORDER BY role_sort LIMIT ? OFFSET ?");
|
|
||||||
params.add(pageSize);
|
|
||||||
params.add((pageNum - 1) * pageSize);
|
|
||||||
|
|
||||||
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql.toString(), params.toArray());
|
|
||||||
|
|
||||||
return AjaxResult.success().put("rows", rows).put("total", total != null ? total : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取角色详情
|
|
||||||
*/
|
|
||||||
@GetMapping("/{roleId}")
|
|
||||||
public AjaxResult getInfo(@PathVariable Long roleId) {
|
|
||||||
String sql = "SELECT * FROM sys_role WHERE role_id = ? AND del_flag = '0'";
|
|
||||||
Map<String, Object> role = jdbcTemplate.queryForMap(sql, roleId);
|
|
||||||
|
|
||||||
String menuSql = "SELECT menu_id FROM sys_role_menu WHERE role_id = ?";
|
|
||||||
List<Long> menuIds = jdbcTemplate.queryForList(menuSql, Long.class, roleId);
|
|
||||||
role.put("menuIds", menuIds);
|
|
||||||
|
|
||||||
return AjaxResult.success(role);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增角色
|
|
||||||
*/
|
|
||||||
@PostMapping
|
|
||||||
public AjaxResult add(@RequestBody Map<String, Object> role) {
|
|
||||||
String roleName = (String) role.get("roleName");
|
|
||||||
String roleKey = (String) role.get("roleKey");
|
|
||||||
|
|
||||||
Integer count = jdbcTemplate.queryForObject(
|
|
||||||
"SELECT COUNT(*) FROM sys_role WHERE role_name = ? AND del_flag = '0'",
|
|
||||||
Integer.class, roleName);
|
|
||||||
if (count != null && count > 0) {
|
|
||||||
return AjaxResult.error("角色名称已存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
String sql = "INSERT INTO sys_role (role_name, role_key, role_sort, data_scope, status, " +
|
|
||||||
"create_by, create_time, remark) VALUES (?, ?, ?, ?, ?, 'admin', NOW(), ?)";
|
|
||||||
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
roleName,
|
|
||||||
roleKey,
|
|
||||||
role.getOrDefault("roleSort", 0),
|
|
||||||
role.getOrDefault("dataScope", "1"),
|
|
||||||
role.getOrDefault("status", "0"),
|
|
||||||
role.get("remark"));
|
|
||||||
|
|
||||||
Long roleId = jdbcTemplate.queryForObject("SELECT LAST_INSERT_ID()", Long.class);
|
|
||||||
saveRoleMenu(roleId, role);
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改角色
|
|
||||||
*/
|
|
||||||
@PutMapping
|
|
||||||
public AjaxResult edit(@RequestBody Map<String, Object> role) {
|
|
||||||
Long roleId = Long.valueOf(role.get("roleId").toString());
|
|
||||||
|
|
||||||
if (roleId == 1) {
|
|
||||||
return AjaxResult.error("不允许修改超级管理员角色");
|
|
||||||
}
|
|
||||||
|
|
||||||
String sql = "UPDATE sys_role SET role_name = ?, role_key = ?, role_sort = ?, " +
|
|
||||||
"data_scope = ?, status = ?, remark = ?, update_by = 'admin', update_time = NOW() " +
|
|
||||||
"WHERE role_id = ?";
|
|
||||||
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
role.get("roleName"),
|
|
||||||
role.get("roleKey"),
|
|
||||||
role.getOrDefault("roleSort", 0),
|
|
||||||
role.getOrDefault("dataScope", "1"),
|
|
||||||
role.getOrDefault("status", "0"),
|
|
||||||
role.get("remark"),
|
|
||||||
roleId);
|
|
||||||
|
|
||||||
jdbcTemplate.update("DELETE FROM sys_role_menu WHERE role_id = ?", roleId);
|
|
||||||
saveRoleMenu(roleId, role);
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveRoleMenu(Long roleId, Map<String, Object> role) {
|
|
||||||
if (role.get("menuIds") != null) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<Integer> menuIds = (List<Integer>) role.get("menuIds");
|
|
||||||
for (Integer menuId : menuIds) {
|
|
||||||
jdbcTemplate.update("INSERT INTO sys_role_menu (role_id, menu_id) VALUES (?, ?)", roleId, menuId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除角色
|
|
||||||
*/
|
|
||||||
@DeleteMapping("/{roleIds}")
|
|
||||||
public AjaxResult remove(@PathVariable String roleIds) {
|
|
||||||
String[] ids = roleIds.split(",");
|
|
||||||
for (String id : ids) {
|
|
||||||
if ("1".equals(id)) {
|
|
||||||
return AjaxResult.error("不允许删除超级管理员角色");
|
|
||||||
}
|
|
||||||
Integer count = jdbcTemplate.queryForObject(
|
|
||||||
"SELECT COUNT(*) FROM sys_user_role WHERE role_id = ?",
|
|
||||||
Integer.class, Long.valueOf(id));
|
|
||||||
if (count != null && count > 0) {
|
|
||||||
return AjaxResult.error("角色已分配给用户,无法删除");
|
|
||||||
}
|
|
||||||
jdbcTemplate.update("UPDATE sys_role SET del_flag = '2' WHERE role_id = ?", Long.valueOf(id));
|
|
||||||
}
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改状态
|
|
||||||
*/
|
|
||||||
@PutMapping("/changeStatus")
|
|
||||||
public AjaxResult changeStatus(@RequestBody Map<String, Object> role) {
|
|
||||||
Long roleId = Long.valueOf(role.get("roleId").toString());
|
|
||||||
if (roleId == 1) {
|
|
||||||
return AjaxResult.error("不允许修改超级管理员角色状态");
|
|
||||||
}
|
|
||||||
String status = (String) role.get("status");
|
|
||||||
jdbcTemplate.update("UPDATE sys_role SET status = ?, update_time = NOW() WHERE role_id = ?", status, roleId);
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取菜单树
|
|
||||||
*/
|
|
||||||
@GetMapping("/menuTree")
|
|
||||||
public AjaxResult menuTree() {
|
|
||||||
List<Map<String, Object>> menus = jdbcTemplate.queryForList(
|
|
||||||
"SELECT menu_id, parent_id, menu_name FROM sys_menu WHERE status = '0' ORDER BY parent_id, order_num");
|
|
||||||
return AjaxResult.success(buildTree(menus, 0L));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取角色已选菜单ID
|
|
||||||
*/
|
|
||||||
@GetMapping("/roleMenuIds/{roleId}")
|
|
||||||
public AjaxResult roleMenuIds(@PathVariable Long roleId) {
|
|
||||||
List<Long> menuIds = jdbcTemplate.queryForList(
|
|
||||||
"SELECT menu_id FROM sys_role_menu WHERE role_id = ?", Long.class, roleId);
|
|
||||||
return AjaxResult.success(menuIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Map<String, Object>> buildTree(List<Map<String, Object>> list, Long parentId) {
|
|
||||||
List<Map<String, Object>> result = new ArrayList<>();
|
|
||||||
for (Map<String, Object> item : list) {
|
|
||||||
Long pid = ((Number) item.get("parent_id")).longValue();
|
|
||||||
if (pid.equals(parentId)) {
|
|
||||||
Map<String, Object> node = new HashMap<>();
|
|
||||||
Long id = ((Number) item.get("menu_id")).longValue();
|
|
||||||
node.put("id", id);
|
|
||||||
node.put("label", item.get("menu_name"));
|
|
||||||
List<Map<String, Object>> children = buildTree(list, id);
|
|
||||||
if (!children.isEmpty()) {
|
|
||||||
node.put("children", children);
|
|
||||||
}
|
|
||||||
result.add(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,331 +0,0 @@
|
||||||
package com.pangu.web.controller.system;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.pangu.common.core.domain.AjaxResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户管理Controller
|
|
||||||
*
|
|
||||||
* @author pangu
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/system/user")
|
|
||||||
public class SysUserController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询用户列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/list")
|
|
||||||
public AjaxResult list(
|
|
||||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
|
||||||
@RequestParam(required = false) String userName,
|
|
||||||
@RequestParam(required = false) String phonenumber,
|
|
||||||
@RequestParam(required = false) String status,
|
|
||||||
@RequestParam(required = false) Long deptId) {
|
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder();
|
|
||||||
sql.append("SELECT u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, ");
|
|
||||||
sql.append("u.phonenumber, u.sex, u.status, u.create_time, d.dept_name ");
|
|
||||||
sql.append("FROM sys_user u LEFT JOIN sys_dept d ON u.dept_id = d.dept_id ");
|
|
||||||
sql.append("WHERE u.del_flag = '0' ");
|
|
||||||
|
|
||||||
List<Object> params = new ArrayList<>();
|
|
||||||
|
|
||||||
if (userName != null && !userName.isEmpty()) {
|
|
||||||
sql.append("AND u.user_name LIKE ? ");
|
|
||||||
params.add("%" + userName + "%");
|
|
||||||
}
|
|
||||||
if (phonenumber != null && !phonenumber.isEmpty()) {
|
|
||||||
sql.append("AND u.phonenumber LIKE ? ");
|
|
||||||
params.add("%" + phonenumber + "%");
|
|
||||||
}
|
|
||||||
if (status != null && !status.isEmpty()) {
|
|
||||||
sql.append("AND u.status = ? ");
|
|
||||||
params.add(status);
|
|
||||||
}
|
|
||||||
if (deptId != null) {
|
|
||||||
sql.append(
|
|
||||||
"AND (u.dept_id = ? OR u.dept_id IN (SELECT dept_id FROM sys_dept WHERE ancestors LIKE CONCAT('%,', ?, ',%') OR ancestors LIKE CONCAT('%,', ?))) ");
|
|
||||||
params.add(deptId);
|
|
||||||
params.add(deptId);
|
|
||||||
params.add(deptId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 统计总数
|
|
||||||
String countSql = "SELECT COUNT(*) FROM (" + sql.toString() + ") t";
|
|
||||||
Integer total = jdbcTemplate.queryForObject(countSql, Integer.class, params.toArray());
|
|
||||||
|
|
||||||
// 分页查询
|
|
||||||
sql.append("ORDER BY u.create_time DESC LIMIT ? OFFSET ?");
|
|
||||||
params.add(pageSize);
|
|
||||||
params.add((pageNum - 1) * pageSize);
|
|
||||||
|
|
||||||
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql.toString(), params.toArray());
|
|
||||||
|
|
||||||
// 返回分页格式数据
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("code", 200);
|
|
||||||
result.put("msg", "查询成功");
|
|
||||||
result.put("rows", rows);
|
|
||||||
result.put("total", total != null ? total : 0);
|
|
||||||
return AjaxResult.success(result).put("rows", rows).put("total", total != null ? total : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户详情
|
|
||||||
*/
|
|
||||||
@GetMapping("/{userId}")
|
|
||||||
public AjaxResult getInfo(@PathVariable Long userId) {
|
|
||||||
String sql = "SELECT u.*, d.dept_name FROM sys_user u " +
|
|
||||||
"LEFT JOIN sys_dept d ON u.dept_id = d.dept_id " +
|
|
||||||
"WHERE u.user_id = ? AND u.del_flag = '0'";
|
|
||||||
Map<String, Object> user = jdbcTemplate.queryForMap(sql, userId);
|
|
||||||
|
|
||||||
// 查询用户角色
|
|
||||||
String roleSql = "SELECT r.role_id, r.role_name FROM sys_role r " +
|
|
||||||
"INNER JOIN sys_user_role ur ON r.role_id = ur.role_id " +
|
|
||||||
"WHERE ur.user_id = ?";
|
|
||||||
List<Map<String, Object>> roles = jdbcTemplate.queryForList(roleSql, userId);
|
|
||||||
user.put("roles", roles);
|
|
||||||
|
|
||||||
// 查询用户岗位
|
|
||||||
String postSql = "SELECT p.post_id, p.post_name FROM sys_post p " +
|
|
||||||
"INNER JOIN sys_user_post up ON p.post_id = up.post_id " +
|
|
||||||
"WHERE up.user_id = ?";
|
|
||||||
List<Map<String, Object>> posts = jdbcTemplate.queryForList(postSql, userId);
|
|
||||||
user.put("posts", posts);
|
|
||||||
|
|
||||||
return AjaxResult.success(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取角色和岗位选项
|
|
||||||
*/
|
|
||||||
@GetMapping("/options")
|
|
||||||
public AjaxResult getOptions() {
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
|
|
||||||
// 查询所有角色
|
|
||||||
List<Map<String, Object>> roles = jdbcTemplate.queryForList(
|
|
||||||
"SELECT role_id, role_name FROM sys_role WHERE status = '0' AND del_flag = '0' ORDER BY role_sort");
|
|
||||||
result.put("roles", roles);
|
|
||||||
|
|
||||||
// 查询所有岗位
|
|
||||||
List<Map<String, Object>> posts = jdbcTemplate.queryForList(
|
|
||||||
"SELECT post_id, post_name FROM sys_post WHERE status = '0' ORDER BY post_sort");
|
|
||||||
result.put("posts", posts);
|
|
||||||
|
|
||||||
return AjaxResult.success(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取角色列表(下拉选项)
|
|
||||||
*/
|
|
||||||
@GetMapping("/roleOptions")
|
|
||||||
public AjaxResult roleOptions() {
|
|
||||||
List<Map<String, Object>> roles = jdbcTemplate.queryForList(
|
|
||||||
"SELECT role_id as roleId, role_name as roleName FROM sys_role WHERE status = '0' AND del_flag = '0' ORDER BY role_sort");
|
|
||||||
return AjaxResult.success(roles);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取岗位列表(下拉选项)
|
|
||||||
*/
|
|
||||||
@GetMapping("/postOptions")
|
|
||||||
public AjaxResult postOptions() {
|
|
||||||
List<Map<String, Object>> posts = jdbcTemplate.queryForList(
|
|
||||||
"SELECT post_id as postId, post_name as postName FROM sys_post WHERE status = '0' ORDER BY post_sort");
|
|
||||||
return AjaxResult.success(posts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增用户
|
|
||||||
*/
|
|
||||||
@PostMapping
|
|
||||||
public AjaxResult add(@RequestBody Map<String, Object> user) {
|
|
||||||
String userName = (String) user.get("userName");
|
|
||||||
|
|
||||||
// 检查用户名是否存在
|
|
||||||
Integer count = jdbcTemplate.queryForObject(
|
|
||||||
"SELECT COUNT(*) FROM sys_user WHERE user_name = ? AND del_flag = '0'",
|
|
||||||
Integer.class, userName);
|
|
||||||
if (count > 0) {
|
|
||||||
return AjaxResult.error("用户名已存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加密密码
|
|
||||||
String password = (String) user.getOrDefault("password", "123456");
|
|
||||||
String encodedPassword = passwordEncoder.encode(password);
|
|
||||||
|
|
||||||
String sql = "INSERT INTO sys_user (dept_id, user_name, nick_name, email, phonenumber, sex, password, status, create_by, create_time) "
|
|
||||||
+
|
|
||||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'admin', NOW())";
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
user.get("deptId"),
|
|
||||||
userName,
|
|
||||||
user.get("nickName"),
|
|
||||||
user.get("email"),
|
|
||||||
user.get("phonenumber"),
|
|
||||||
user.getOrDefault("sex", "0"),
|
|
||||||
encodedPassword,
|
|
||||||
user.getOrDefault("status", "0"));
|
|
||||||
|
|
||||||
// 获取新插入的用户ID
|
|
||||||
Long userId = jdbcTemplate.queryForObject("SELECT LAST_INSERT_ID()", Long.class);
|
|
||||||
|
|
||||||
// 关联角色
|
|
||||||
if (user.get("roleIds") != null) {
|
|
||||||
List<Integer> roleIds = (List<Integer>) user.get("roleIds");
|
|
||||||
for (Integer roleId : roleIds) {
|
|
||||||
jdbcTemplate.update("INSERT INTO sys_user_role (user_id, role_id) VALUES (?, ?)", userId, roleId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 关联岗位
|
|
||||||
if (user.get("postIds") != null) {
|
|
||||||
List<Integer> postIds = (List<Integer>) user.get("postIds");
|
|
||||||
for (Integer postId : postIds) {
|
|
||||||
jdbcTemplate.update("INSERT INTO sys_user_post (user_id, post_id) VALUES (?, ?)", userId, postId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改用户
|
|
||||||
*/
|
|
||||||
@PutMapping
|
|
||||||
public AjaxResult edit(@RequestBody Map<String, Object> user) {
|
|
||||||
Long userId = Long.valueOf(user.get("userId").toString());
|
|
||||||
|
|
||||||
String sql = "UPDATE sys_user SET dept_id = ?, nick_name = ?, email = ?, phonenumber = ?, " +
|
|
||||||
"sex = ?, status = ?, update_by = 'admin', update_time = NOW() WHERE user_id = ?";
|
|
||||||
jdbcTemplate.update(sql,
|
|
||||||
user.get("deptId"),
|
|
||||||
user.get("nickName"),
|
|
||||||
user.get("email"),
|
|
||||||
user.get("phonenumber"),
|
|
||||||
user.getOrDefault("sex", "0"),
|
|
||||||
user.getOrDefault("status", "0"),
|
|
||||||
userId);
|
|
||||||
|
|
||||||
// 更新角色关联
|
|
||||||
jdbcTemplate.update("DELETE FROM sys_user_role WHERE user_id = ?", userId);
|
|
||||||
if (user.get("roleIds") != null) {
|
|
||||||
List<Integer> roleIds = (List<Integer>) user.get("roleIds");
|
|
||||||
for (Integer roleId : roleIds) {
|
|
||||||
jdbcTemplate.update("INSERT INTO sys_user_role (user_id, role_id) VALUES (?, ?)", userId, roleId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新岗位关联
|
|
||||||
jdbcTemplate.update("DELETE FROM sys_user_post WHERE user_id = ?", userId);
|
|
||||||
if (user.get("postIds") != null) {
|
|
||||||
List<Integer> postIds = (List<Integer>) user.get("postIds");
|
|
||||||
for (Integer postId : postIds) {
|
|
||||||
jdbcTemplate.update("INSERT INTO sys_user_post (user_id, post_id) VALUES (?, ?)", userId, postId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除用户
|
|
||||||
*/
|
|
||||||
@DeleteMapping("/{userIds}")
|
|
||||||
public AjaxResult remove(@PathVariable String userIds) {
|
|
||||||
String[] ids = userIds.split(",");
|
|
||||||
for (String id : ids) {
|
|
||||||
if ("1".equals(id)) {
|
|
||||||
return AjaxResult.error("不允许删除超级管理员");
|
|
||||||
}
|
|
||||||
jdbcTemplate.update("UPDATE sys_user SET del_flag = '2' WHERE user_id = ?", Long.valueOf(id));
|
|
||||||
}
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 重置密码
|
|
||||||
*/
|
|
||||||
@PutMapping("/resetPwd")
|
|
||||||
public AjaxResult resetPwd(@RequestBody Map<String, Object> user) {
|
|
||||||
Long userId = Long.valueOf(user.get("userId").toString());
|
|
||||||
String password = (String) user.getOrDefault("password", "123456");
|
|
||||||
String encodedPassword = passwordEncoder.encode(password);
|
|
||||||
|
|
||||||
jdbcTemplate.update("UPDATE sys_user SET password = ?, update_time = NOW() WHERE user_id = ?",
|
|
||||||
encodedPassword, userId);
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改状态
|
|
||||||
*/
|
|
||||||
@PutMapping("/changeStatus")
|
|
||||||
public AjaxResult changeStatus(@RequestBody Map<String, Object> user) {
|
|
||||||
Long userId = Long.valueOf(user.get("userId").toString());
|
|
||||||
String status = (String) user.get("status");
|
|
||||||
|
|
||||||
jdbcTemplate.update("UPDATE sys_user SET status = ?, update_time = NOW() WHERE user_id = ?",
|
|
||||||
status, userId);
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取部门树
|
|
||||||
*/
|
|
||||||
@GetMapping("/deptTree")
|
|
||||||
public AjaxResult deptTree() {
|
|
||||||
List<Map<String, Object>> depts = jdbcTemplate.queryForList(
|
|
||||||
"SELECT dept_id, parent_id, dept_name FROM sys_dept WHERE status = '0' AND del_flag = '0' ORDER BY order_num");
|
|
||||||
|
|
||||||
List<Map<String, Object>> tree = buildTree(depts, 0L);
|
|
||||||
return AjaxResult.success(tree);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Map<String, Object>> buildTree(List<Map<String, Object>> list, Long parentId) {
|
|
||||||
List<Map<String, Object>> result = new ArrayList<>();
|
|
||||||
for (Map<String, Object> item : list) {
|
|
||||||
Long pid = ((Number) item.get("parent_id")).longValue();
|
|
||||||
if (pid.equals(parentId)) {
|
|
||||||
Map<String, Object> node = new HashMap<>();
|
|
||||||
Long deptId = ((Number) item.get("dept_id")).longValue();
|
|
||||||
node.put("id", deptId);
|
|
||||||
node.put("label", item.get("dept_name"));
|
|
||||||
List<Map<String, Object>> children = buildTree(list, deptId);
|
|
||||||
if (!children.isEmpty()) {
|
|
||||||
node.put("children", children);
|
|
||||||
}
|
|
||||||
result.add(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -57,6 +57,13 @@
|
||||||
AND school_id = #{schoolId}
|
AND school_id = #{schoolId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="countByGradeId" parameterType="Long" resultType="int">
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM pg_school_grade
|
||||||
|
WHERE del_flag = '0'
|
||||||
|
AND grade_id = #{gradeId}
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="batchInsert">
|
<insert id="batchInsert">
|
||||||
INSERT INTO pg_school_grade (school_id, grade_id, order_num, status, create_by, create_time, del_flag)
|
INSERT INTO pg_school_grade (school_id, grade_id, order_num, status, create_by, create_time, del_flag)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.pangu;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringBootConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试用启动配置,供 pangu-system 模块内 @SpringBootTest 使用
|
||||||
|
* @author pangu
|
||||||
|
*/
|
||||||
|
@SpringBootConfiguration
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@ComponentScan(basePackages = "com.pangu")
|
||||||
|
@MapperScan("com.pangu.**.mapper")
|
||||||
|
public class TestApplication {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public BCryptPasswordEncoder passwordEncoder() {
|
||||||
|
return new BCryptPasswordEncoder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,24 +1,31 @@
|
||||||
package com.pangu.application.service;
|
package com.pangu.application.service;
|
||||||
|
|
||||||
import com.pangu.application.domain.dto.ApplicationDTO;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import com.pangu.application.domain.entity.ApiDict;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import com.pangu.application.domain.vo.ApplicationVO;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import com.pangu.common.core.page.TableDataInfo;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import com.pangu.application.domain.dto.ApplicationDTO;
|
||||||
import java.util.List;
|
import com.pangu.application.domain.entity.ApiDict;
|
||||||
|
import com.pangu.application.domain.vo.ApplicationVO;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import com.pangu.common.core.page.TableDataInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 应用服务测试类
|
* 应用服务测试类
|
||||||
|
*
|
||||||
* @author 湖北新华业务中台研发团队
|
* @author 湖北新华业务中台研发团队
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest(classes = com.pangu.TestApplication.class)
|
||||||
@Transactional // 测试完成后回滚
|
@Transactional // 测试完成后回滚
|
||||||
public class ApplicationServiceTest {
|
public class ApplicationServiceTest {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,28 @@
|
||||||
package com.pangu.integration;
|
package com.pangu.integration;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.MethodOrderer;
|
||||||
|
import org.junit.jupiter.api.Order;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.pangu.application.domain.dto.ApplicationDTO;
|
||||||
|
import com.pangu.application.domain.vo.ApplicationVO;
|
||||||
|
import com.pangu.application.service.IApplicationService;
|
||||||
|
import com.pangu.base.service.IRegionService;
|
||||||
import com.pangu.common.core.page.TableDataInfo;
|
import com.pangu.common.core.page.TableDataInfo;
|
||||||
import com.pangu.member.domain.dto.MemberDTO;
|
import com.pangu.member.domain.dto.MemberDTO;
|
||||||
import com.pangu.member.domain.entity.Member;
|
import com.pangu.member.domain.entity.Member;
|
||||||
|
|
@ -12,19 +35,6 @@ import com.pangu.school.service.ISchoolService;
|
||||||
import com.pangu.student.domain.dto.StudentDTO;
|
import com.pangu.student.domain.dto.StudentDTO;
|
||||||
import com.pangu.student.domain.vo.StudentVO;
|
import com.pangu.student.domain.vo.StudentVO;
|
||||||
import com.pangu.student.service.IStudentService;
|
import com.pangu.student.service.IStudentService;
|
||||||
import com.pangu.application.domain.dto.ApplicationDTO;
|
|
||||||
import com.pangu.application.domain.vo.ApplicationVO;
|
|
||||||
import com.pangu.application.service.IApplicationService;
|
|
||||||
import com.pangu.base.service.IRegionService;
|
|
||||||
import org.junit.jupiter.api.*;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模块集成测试类
|
* 模块集成测试类
|
||||||
|
|
@ -32,7 +42,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||||
*
|
*
|
||||||
* @author 湖北新华业务中台研发团队
|
* @author 湖北新华业务中台研发团队
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest(classes = com.pangu.TestApplication.class)
|
||||||
@Transactional
|
@Transactional
|
||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class ModuleIntegrationTest {
|
public class ModuleIntegrationTest {
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,31 @@
|
||||||
package com.pangu.member.service;
|
package com.pangu.member.service;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.pangu.common.core.exception.ServiceException;
|
import com.pangu.common.core.exception.ServiceException;
|
||||||
import com.pangu.common.core.page.TableDataInfo;
|
import com.pangu.common.core.page.TableDataInfo;
|
||||||
import com.pangu.member.domain.dto.MemberDTO;
|
import com.pangu.member.domain.dto.MemberDTO;
|
||||||
import com.pangu.member.domain.entity.Member;
|
import com.pangu.member.domain.entity.Member;
|
||||||
import com.pangu.member.domain.vo.MemberVO;
|
import com.pangu.member.domain.vo.MemberVO;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员服务测试类
|
* 会员服务测试类
|
||||||
|
*
|
||||||
* @author pangu
|
* @author pangu
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest(classes = com.pangu.TestApplication.class)
|
||||||
@Transactional // 测试完成后回滚
|
@Transactional // 测试完成后回滚
|
||||||
public class MemberServiceTest {
|
public class MemberServiceTest {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||||
* 学校服务测试类
|
* 学校服务测试类
|
||||||
* @author pangu
|
* @author pangu
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest(classes = com.pangu.TestApplication.class)
|
||||||
@Transactional // 测试完成后回滚
|
@Transactional // 测试完成后回滚
|
||||||
public class SchoolServiceTest {
|
public class SchoolServiceTest {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,30 @@
|
||||||
package com.pangu.student.service;
|
package com.pangu.student.service;
|
||||||
|
|
||||||
import com.pangu.common.core.exception.ServiceException;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import com.pangu.common.core.page.TableDataInfo;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import com.pangu.student.domain.dto.StudentDTO;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import com.pangu.student.domain.entity.Student;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import com.pangu.student.domain.vo.StudentVO;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import com.pangu.common.core.exception.ServiceException;
|
||||||
|
import com.pangu.common.core.page.TableDataInfo;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import com.pangu.student.domain.dto.StudentDTO;
|
||||||
|
import com.pangu.student.domain.vo.StudentVO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学生服务测试类
|
* 学生服务测试类
|
||||||
*
|
*
|
||||||
* @author pangu
|
* @author pangu
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest(classes = com.pangu.TestApplication.class)
|
||||||
@Transactional // 测试完成后回滚
|
@Transactional // 测试完成后回滚
|
||||||
public class StudentServiceTest {
|
public class StudentServiceTest {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
# 测试环境配置,供 pangu-system 单模块测试使用
|
||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
driver-class-name: org.h2.Driver
|
||||||
|
url: jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PUBLIC
|
||||||
|
username: sa
|
||||||
|
password:
|
||||||
|
|
||||||
|
mybatis-plus:
|
||||||
|
mapper-locations: classpath*:mapper/**/*.xml
|
||||||
|
type-aliases-package: com.pangu.**.domain
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true
|
||||||
|
|
||||||
|
pagehelper:
|
||||||
|
helper-dialect: h2
|
||||||
|
reasonable: true
|
||||||
|
support-methods-arguments: true
|
||||||
Loading…
Reference in New Issue