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"/>