1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-05 23:11:24 +08:00

Added regex search in DepartmentManagement

This commit is contained in:
2023-06-04 03:21:30 +08:00
parent ef109de4ab
commit 7da56998b2
7 changed files with 108 additions and 33 deletions

View File

@@ -8,6 +8,7 @@ import com.cfive.pinnacle.entity.common.ResponseResult;
import com.cfive.pinnacle.service.IDepartmentService;
import com.cfive.pinnacle.utils.WebUtil;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@@ -22,6 +23,7 @@ import java.util.List;
* @author FatttSnake
* @since 2023-04-30
*/
@Slf4j
@RestController
@RequestMapping("/department")
@Tag(name = "部门", description = "部门相关接口")
@@ -45,8 +47,9 @@ public class DepartmentController {
@GetMapping
@PreAuthorize("hasAuthority('department:admin:get')")
public ResponseResult<IPage<Department>> getAllDepartment(Long currentPage, Long pageSize, Integer searchType, String searchInput) {
return ResponseResult.databaseSelectSuccess(departmentService.getAllDepartment(currentPage, pageSize, searchType, searchInput));
public ResponseResult<IPage<Department>> getAllDepartment(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchRegex) {
log.info(searchInput);
return ResponseResult.databaseSelectSuccess(departmentService.getAllDepartment(currentPage, pageSize, searchType, searchInput, searchRegex));
}
@GetMapping("list")

View File

@@ -25,6 +25,7 @@ public class ResponseCode {
public static final int DATABASE_CONNECT_ERROR = 20036;
public static final int DATABASE_DATA_TO_LONG = 20037;
public static final int DATABASE_DATA_VALIDATION_FAILED = 20038;
public static final int DATABASE_EXECUTE_ERROR = 20039;
public static final int UNAUTHORIZED = 30010;
public static final int ACCESS_DENIED = 30030;

View File

@@ -21,5 +21,5 @@ public interface DepartmentMapper extends BaseMapper<Department> {
@Deprecated
List<Department> getDepartAndUser();
IPage<Department> getAllDepartment(IPage<Department> page, @Param("searchType") Integer searchType, @Param("searchInput") String searchInput);
IPage<Department> getAllDepartment(IPage<Department> page, @Param("searchType") Integer searchType, @Param("searchInput") String searchInput, @Param("searchRegex") Integer searchRegex);
}

View File

@@ -18,5 +18,5 @@ public interface IDepartmentService extends IService<Department> {
@Deprecated
List<Department> getDepartAndUser();
IPage<Department> getAllDepartment(Long currentPage, Long pageSize, Integer searchType, String searchInput);
IPage<Department> getAllDepartment(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchRegex);
}

View File

@@ -35,7 +35,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
}
@Override
public IPage<Department> getAllDepartment(Long currentPage, Long pageSize, Integer searchType, String searchInput) {
public IPage<Department> getAllDepartment(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchRegex) {
IPage<Department> departmentIPage;
if (currentPage == null || pageSize == null) {
departmentIPage = PageDTO.of(0, -1);
@@ -43,6 +43,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
departmentIPage = PageDTO.of(currentPage, pageSize);
}
searchInput = searchInput.trim();
return departmentMapper.getAllDepartment(departmentIPage, searchType, searchInput);
return departmentMapper.getAllDepartment(departmentIPage, searchType, searchInput, searchRegex);
}
}

View File

@@ -4,31 +4,60 @@
<select id="getAllDepartment" resultType="department">
select id, name, tel, address, deleted, version
from t_department where deleted = 0
from t_department where deleted = 0
<if test="searchInput != null and searchInput != ''">
<choose>
<when test="searchType == 0">
and (
instr(name, #{searchInput}) > 0
or instr(tel, #{searchInput}) > 0
or instr(address, #{searchInput}) > 0
)
<if test="searchRegex == 1">
and (
name regexp #{searchInput}
or tel regexp #{searchInput}
or address regexp #{searchInput}
)
</if>
<if test="searchRegex != 1">
and (
instr(name, #{searchInput}) > 0
or instr(tel, #{searchInput}) > 0
or instr(address, #{searchInput}) > 0
)
</if>
</when>
<when test="searchType == 1">
and instr(name, #{searchInput}) > 0
<if test="searchRegex == 1">
and name regexp #{searchInput}
</if>
<if test="searchRegex != 1">
and instr(name, #{searchInput}) > 0
</if>
</when>
<when test="searchType == 2">
and instr(tel, #{searchInput}) > 0
<if test="searchRegex == 1">
and tel regexp #{searchInput}
</if>
<if test="searchRegex != 1">
and instr(tel, #{searchInput}) > 0
</if>
</when>
<when test="searchType == 3">
and instr(address, #{searchInput}) > 0
<if test="searchRegex == 1">
and address regexp #{searchInput}
</if>
<if test="searchRegex != 1">
and instr(address, #{searchInput}) > 0
</if>
</when>
</choose>
</if>
</select>
<select id="getDepartAndUser" resultMap="department">
select d.id did,name,u.id uid,username from t_department d,t_user u where d.id=u.department_id and d.deleted=0 and u.deleted=0
select d.id did, name, u.id uid, username
from t_department d,
t_user u
where d.id = u.department_id
and d.deleted = 0
and u.deleted = 0
</select>
<resultMap id="department" type="department" autoMapping="true">
<id column="did" property="id"/>

View File

@@ -24,22 +24,35 @@
</el-button>
</el-col>
<el-col :span="16">
<el-input
v-model="inputInput"
class="fill-with"
placeholder="请输入内容"
clearable
@keyup.enter="handleQuery"
>
<template #prepend>
<el-select v-model="selectedType" style="width: 100px">
<el-option label="综合搜索" :value="0" />
<el-option label="名称" :value="1" />
<el-option label="电话" :value="2" />
<el-option label="地址" :value="3" />
</el-select>
</template>
</el-input>
<el-form-item :error="isRegexLegal ? '' : '非法正则表达式'">
<el-input
v-model="inputInput"
class="fill-with"
placeholder="请输入内容"
clearable
@keyup.enter="handleQuery"
@change="handleInputChange"
>
<template #prepend>
<el-select v-model="selectedType" style="width: 100px">
<el-option label="综合搜索" :value="0" />
<el-option label="名称" :value="1" />
<el-option label="电话" :value="2" />
<el-option label="地址" :value="3" />
</el-select>
</template>
<template #suffix>
<el-tooltip content="正则表达式">
<el-checkbox
v-model="checkedRegex"
label=".*"
:true-label="1"
@change="handleInputChange"
/>
</el-tooltip>
</template>
</el-input>
</el-form-item>
</el-col>
<el-col :span="-1">
<el-button type="primary" @click="handleQuery">查询</el-button>
@@ -141,7 +154,10 @@ export default {
selectedType: 0,
searchInput: '',
inputInput: '',
searchRegex: 0,
checkedRegex: 0,
currentPage: 1,
isRegexLegal: true,
pageSize: 50,
totalCount: 0,
departmentTable: [],
@@ -164,13 +180,21 @@ export default {
},
methods: {
loadDepartmentTable() {
if (!this.isRegexLegal) {
ElMessage.error({
dangerouslyUseHTMLString: true,
message: '<strong>非法正则表达式</strong>,请重新输入'
})
return
}
this.tableLoading = true
request
.get('/department', {
currentPage: this.currentPage,
pageSize: this.pageSize,
searchType: this.searchType,
searchInput: this.searchInput
searchInput: this.searchInput,
searchRegex: this.searchRegex ?? 0
})
.then((res) => {
const response = res.data
@@ -300,13 +324,30 @@ export default {
handleQuery() {
this.searchType = _.cloneDeep(this.selectedType)
this.searchInput = _.cloneDeep(this.inputInput)
this.searchRegex = _.cloneDeep(this.checkedRegex)
this.currentPage = 1
this.handleInputChange()
this.loadDepartmentTable()
},
handleClear() {
this.selectedType = 0
this.inputInput = ''
this.checkedRegex = 0
this.handleQuery()
},
handleInputChange() {
if (this.checkedRegex) {
try {
RegExp(this.inputInput)
this.isRegexLegal = !(
this.inputInput.includes('{}') || this.inputInput.includes('[]')
)
} catch (e) {
this.isRegexLegal = false
}
} else {
this.isRegexLegal = true
}
}
},
mounted() {