mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 23:11:24 +08:00
Added DepartmentManagement
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
package com.cfive.pinnacle.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.Department;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.IDepartmentService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,18 +22,58 @@ import java.util.List;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/department")
|
||||
@CrossOrigin
|
||||
@Tag(name = "部门", description = "部门相关接口")
|
||||
public class DepartmentController {
|
||||
private IDepartmentService departmentService;
|
||||
|
||||
@Autowired
|
||||
IDepartmentService departmentService;
|
||||
public void setDepartmentService(IDepartmentService departmentService) {
|
||||
this.departmentService = departmentService;
|
||||
}
|
||||
|
||||
//获取所有部门及其各部门所属成员
|
||||
@GetMapping
|
||||
public ResponseResult getDepartAndUser(){
|
||||
@GetMapping("/user")
|
||||
@Deprecated
|
||||
public ResponseResult getDepartAndUser() {
|
||||
List<Department> getDepartAndUser = departmentService.getDepartAndUser();
|
||||
Integer code = getDepartAndUser != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
|
||||
String msg = getDepartAndUser != null ? "" : "数据查询失败,请尝试!";
|
||||
return ResponseResult.build(code, msg, getDepartAndUser);
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('department:admin:add')")
|
||||
public ResponseResult<?> addDepartment(@RequestBody Department department) {
|
||||
if (departmentService.save(department)) {
|
||||
return ResponseResult.databaseSaveSuccess(null);
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@PreAuthorize("hasAuthority('department:admin:modify')")
|
||||
public ResponseResult<?> modifyDepartment(@RequestBody Department department) {
|
||||
if (departmentService.updateById(department)) {
|
||||
return ResponseResult.databaseUpdateSuccess(null);
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("hasAuthority('department:admin:delete')")
|
||||
public ResponseResult<?> deleteDepartment(@PathVariable Long id) {
|
||||
if (departmentService.removeById(id)) {
|
||||
return ResponseResult.databaseDeleteSuccess();
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.User;
|
||||
import com.cfive.pinnacle.service.IStaffService;
|
||||
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.*;
|
||||
@@ -18,7 +17,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/staff")
|
||||
public class StaffController {
|
||||
@@ -38,7 +36,6 @@ public class StaffController {
|
||||
@PutMapping
|
||||
@PreAuthorize("hasAnyAuthority('staff:manege:modify', 'staff:admin:modify')")
|
||||
public ResponseResult<?> modifyStaff(@RequestBody User user) {
|
||||
log.info(user.toString());
|
||||
if (staffService.modifyStaff(user)) {
|
||||
return ResponseResult.databaseUpdateSuccess(null);
|
||||
} else {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.cfive.pinnacle.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.Department;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,5 +18,8 @@ import java.util.List;
|
||||
*/
|
||||
@Mapper
|
||||
public interface DepartmentMapper extends BaseMapper<Department> {
|
||||
@Deprecated
|
||||
List<Department> getDepartAndUser();
|
||||
|
||||
IPage<Department> getAllDepartment(IPage<Department> page, @Param("searchType") Integer searchType, @Param("searchInput") String searchInput);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.cfive.pinnacle.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.Department;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
@@ -14,6 +15,8 @@ import java.util.List;
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface IDepartmentService extends IService<Department> {
|
||||
@Deprecated
|
||||
List<Department> getDepartAndUser();
|
||||
|
||||
IPage<Department> getAllDepartment(Long currentPage, Long pageSize, Integer searchType, String searchInput);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.cfive.pinnacle.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
||||
import com.cfive.pinnacle.entity.Department;
|
||||
import com.cfive.pinnacle.mapper.DepartmentMapper;
|
||||
import com.cfive.pinnacle.service.IDepartmentService;
|
||||
@@ -19,11 +21,28 @@ import java.util.List;
|
||||
*/
|
||||
@Service
|
||||
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements IDepartmentService {
|
||||
@Autowired
|
||||
private DepartmentMapper departmentMapper;
|
||||
|
||||
@Autowired
|
||||
public void setDepartmentMapper(DepartmentMapper departmentMapper) {
|
||||
this.departmentMapper = departmentMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public List<Department> getDepartAndUser() {
|
||||
return departmentMapper.getDepartAndUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<Department> getAllDepartment(Long currentPage, Long pageSize, Integer searchType, String searchInput) {
|
||||
IPage<Department> departmentIPage;
|
||||
if (currentPage == null || pageSize == null) {
|
||||
departmentIPage = PageDTO.of(0, -1);
|
||||
} else {
|
||||
departmentIPage = PageDTO.of(currentPage, pageSize);
|
||||
}
|
||||
searchInput = searchInput.trim();
|
||||
return departmentMapper.getAllDepartment(departmentIPage, searchType, searchInput);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
||||
} else {
|
||||
userIPage = PageDTO.of(currentPage, pageSize);
|
||||
}
|
||||
searchInput = searchInput.trim();
|
||||
searchInput = searchInput.trim();
|
||||
return staffMapper.getAllStaff(userIPage, departmentId, searchType, searchInput, searchGender, searchBirthFrom, searchBirthTo);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cfive.pinnacle.mapper.DepartmentMapper">
|
||||
|
||||
<select id="getAllDepartment" resultType="department">
|
||||
select id, name, tel, address, deleted, version
|
||||
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
|
||||
)
|
||||
</when>
|
||||
<when test="searchType == 1">
|
||||
and instr(name, #{searchInput}) > 0
|
||||
</when>
|
||||
<when test="searchType == 2">
|
||||
and instr(tel, #{searchInput}) > 0
|
||||
</when>
|
||||
<when test="searchType == 3">
|
||||
and instr(address, #{searchInput}) > 0
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user