mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-06 07:21:24 +08:00
Added regex search in DepartmentManagement
This commit is contained in:
@@ -8,6 +8,7 @@ import com.cfive.pinnacle.entity.common.ResponseResult;
|
|||||||
import com.cfive.pinnacle.service.IDepartmentService;
|
import com.cfive.pinnacle.service.IDepartmentService;
|
||||||
import com.cfive.pinnacle.utils.WebUtil;
|
import com.cfive.pinnacle.utils.WebUtil;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -22,6 +23,7 @@ import java.util.List;
|
|||||||
* @author FatttSnake
|
* @author FatttSnake
|
||||||
* @since 2023-04-30
|
* @since 2023-04-30
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/department")
|
@RequestMapping("/department")
|
||||||
@Tag(name = "部门", description = "部门相关接口")
|
@Tag(name = "部门", description = "部门相关接口")
|
||||||
@@ -45,8 +47,9 @@ public class DepartmentController {
|
|||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@PreAuthorize("hasAuthority('department:admin:get')")
|
@PreAuthorize("hasAuthority('department:admin:get')")
|
||||||
public ResponseResult<IPage<Department>> getAllDepartment(Long currentPage, Long pageSize, Integer searchType, String searchInput) {
|
public ResponseResult<IPage<Department>> getAllDepartment(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchRegex) {
|
||||||
return ResponseResult.databaseSelectSuccess(departmentService.getAllDepartment(currentPage, pageSize, searchType, searchInput));
|
log.info(searchInput);
|
||||||
|
return ResponseResult.databaseSelectSuccess(departmentService.getAllDepartment(currentPage, pageSize, searchType, searchInput, searchRegex));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("list")
|
@GetMapping("list")
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public class ResponseCode {
|
|||||||
public static final int DATABASE_CONNECT_ERROR = 20036;
|
public static final int DATABASE_CONNECT_ERROR = 20036;
|
||||||
public static final int DATABASE_DATA_TO_LONG = 20037;
|
public static final int DATABASE_DATA_TO_LONG = 20037;
|
||||||
public static final int DATABASE_DATA_VALIDATION_FAILED = 20038;
|
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 UNAUTHORIZED = 30010;
|
||||||
public static final int ACCESS_DENIED = 30030;
|
public static final int ACCESS_DENIED = 30030;
|
||||||
|
|||||||
@@ -21,5 +21,5 @@ public interface DepartmentMapper extends BaseMapper<Department> {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
List<Department> getDepartAndUser();
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ public interface IDepartmentService extends IService<Department> {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
List<Department> getDepartAndUser();
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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;
|
IPage<Department> departmentIPage;
|
||||||
if (currentPage == null || pageSize == null) {
|
if (currentPage == null || pageSize == null) {
|
||||||
departmentIPage = PageDTO.of(0, -1);
|
departmentIPage = PageDTO.of(0, -1);
|
||||||
@@ -43,6 +43,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
departmentIPage = PageDTO.of(currentPage, pageSize);
|
departmentIPage = PageDTO.of(currentPage, pageSize);
|
||||||
}
|
}
|
||||||
searchInput = searchInput.trim();
|
searchInput = searchInput.trim();
|
||||||
return departmentMapper.getAllDepartment(departmentIPage, searchType, searchInput);
|
|
||||||
|
return departmentMapper.getAllDepartment(departmentIPage, searchType, searchInput, searchRegex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,31 +4,60 @@
|
|||||||
|
|
||||||
<select id="getAllDepartment" resultType="department">
|
<select id="getAllDepartment" resultType="department">
|
||||||
select id, name, tel, address, deleted, version
|
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 != ''">
|
<if test="searchInput != null and searchInput != ''">
|
||||||
<choose>
|
<choose>
|
||||||
<when test="searchType == 0">
|
<when test="searchType == 0">
|
||||||
and (
|
<if test="searchRegex == 1">
|
||||||
instr(name, #{searchInput}) > 0
|
and (
|
||||||
or instr(tel, #{searchInput}) > 0
|
name regexp #{searchInput}
|
||||||
or instr(address, #{searchInput}) > 0
|
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>
|
||||||
<when test="searchType == 1">
|
<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>
|
||||||
<when test="searchType == 2">
|
<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>
|
||||||
<when test="searchType == 3">
|
<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>
|
</when>
|
||||||
</choose>
|
</choose>
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getDepartAndUser" resultMap="department">
|
<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>
|
</select>
|
||||||
<resultMap id="department" type="department" autoMapping="true">
|
<resultMap id="department" type="department" autoMapping="true">
|
||||||
<id column="did" property="id"/>
|
<id column="did" property="id"/>
|
||||||
|
|||||||
@@ -24,22 +24,35 @@
|
|||||||
</el-button>
|
</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="16">
|
<el-col :span="16">
|
||||||
<el-input
|
<el-form-item :error="isRegexLegal ? '' : '非法正则表达式'">
|
||||||
v-model="inputInput"
|
<el-input
|
||||||
class="fill-with"
|
v-model="inputInput"
|
||||||
placeholder="请输入内容"
|
class="fill-with"
|
||||||
clearable
|
placeholder="请输入内容"
|
||||||
@keyup.enter="handleQuery"
|
clearable
|
||||||
>
|
@keyup.enter="handleQuery"
|
||||||
<template #prepend>
|
@change="handleInputChange"
|
||||||
<el-select v-model="selectedType" style="width: 100px">
|
>
|
||||||
<el-option label="综合搜索" :value="0" />
|
<template #prepend>
|
||||||
<el-option label="名称" :value="1" />
|
<el-select v-model="selectedType" style="width: 100px">
|
||||||
<el-option label="电话" :value="2" />
|
<el-option label="综合搜索" :value="0" />
|
||||||
<el-option label="地址" :value="3" />
|
<el-option label="名称" :value="1" />
|
||||||
</el-select>
|
<el-option label="电话" :value="2" />
|
||||||
</template>
|
<el-option label="地址" :value="3" />
|
||||||
</el-input>
|
</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>
|
||||||
<el-col :span="-1">
|
<el-col :span="-1">
|
||||||
<el-button type="primary" @click="handleQuery">查询</el-button>
|
<el-button type="primary" @click="handleQuery">查询</el-button>
|
||||||
@@ -141,7 +154,10 @@ export default {
|
|||||||
selectedType: 0,
|
selectedType: 0,
|
||||||
searchInput: '',
|
searchInput: '',
|
||||||
inputInput: '',
|
inputInput: '',
|
||||||
|
searchRegex: 0,
|
||||||
|
checkedRegex: 0,
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
|
isRegexLegal: true,
|
||||||
pageSize: 50,
|
pageSize: 50,
|
||||||
totalCount: 0,
|
totalCount: 0,
|
||||||
departmentTable: [],
|
departmentTable: [],
|
||||||
@@ -164,13 +180,21 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadDepartmentTable() {
|
loadDepartmentTable() {
|
||||||
|
if (!this.isRegexLegal) {
|
||||||
|
ElMessage.error({
|
||||||
|
dangerouslyUseHTMLString: true,
|
||||||
|
message: '<strong>非法正则表达式</strong>,请重新输入'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
this.tableLoading = true
|
this.tableLoading = true
|
||||||
request
|
request
|
||||||
.get('/department', {
|
.get('/department', {
|
||||||
currentPage: this.currentPage,
|
currentPage: this.currentPage,
|
||||||
pageSize: this.pageSize,
|
pageSize: this.pageSize,
|
||||||
searchType: this.searchType,
|
searchType: this.searchType,
|
||||||
searchInput: this.searchInput
|
searchInput: this.searchInput,
|
||||||
|
searchRegex: this.searchRegex ?? 0
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const response = res.data
|
const response = res.data
|
||||||
@@ -300,13 +324,30 @@ export default {
|
|||||||
handleQuery() {
|
handleQuery() {
|
||||||
this.searchType = _.cloneDeep(this.selectedType)
|
this.searchType = _.cloneDeep(this.selectedType)
|
||||||
this.searchInput = _.cloneDeep(this.inputInput)
|
this.searchInput = _.cloneDeep(this.inputInput)
|
||||||
|
this.searchRegex = _.cloneDeep(this.checkedRegex)
|
||||||
this.currentPage = 1
|
this.currentPage = 1
|
||||||
|
this.handleInputChange()
|
||||||
this.loadDepartmentTable()
|
this.loadDepartmentTable()
|
||||||
},
|
},
|
||||||
handleClear() {
|
handleClear() {
|
||||||
this.selectedType = 0
|
this.selectedType = 0
|
||||||
this.inputInput = ''
|
this.inputInput = ''
|
||||||
|
this.checkedRegex = 0
|
||||||
this.handleQuery()
|
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() {
|
mounted() {
|
||||||
|
|||||||
Reference in New Issue
Block a user