提交 6b71a190 authored 作者: gongwenjie's avatar gongwenjie

合并分支 'gwj' 到 'master'

Gwj 查看合并请求 !19
流水线 #25 已取消 于阶段
...@@ -67,4 +67,8 @@ public class ConfigController { ...@@ -67,4 +67,8 @@ public class ConfigController {
return ok(configService.findHolidaysByMonth(date)); return ok(configService.findHolidaysByMonth(date));
} }
@ApiOperation("清除所有节假日数据")
@GetMapping("/deleteAll")
public ResponseEntity deleteAll(){return ok(configService.deleteAll());}
} }
...@@ -41,19 +41,39 @@ public class DepartController { ...@@ -41,19 +41,39 @@ public class DepartController {
return ok(departmentService.addDepartments(department)); return ok(departmentService.addDepartments(department));
} }
@ApiOperation(value = "修改部门",response = Department.class)
@PutMapping
public ResponseEntity updateDepartments(@RequestBody @Valid Department department){
boolean b = departmentService.updateDepartment(department);
if(b){
return ok("修改部门成功");
}
return ok("修改部门失败");
}
@ApiOperation(value = "根据id查找部门") @ApiOperation(value = "根据id查找部门")
@PostMapping("/findOne") @GetMapping("/findOne/{id}")
public ResponseEntity<Department> findDept(@RequestParam String id){ public ResponseEntity<Department> findDept(@PathVariable("id") String id){
return ok(departmentService.findOne(id)); return ok(departmentService.findOne(id));
} }
@ApiOperation(value = "查找部门列表") @ApiOperation(value = "查找部门列表")
@PostMapping("/findList") @GetMapping("/findList")
public ResponseEntity findList(){ public ResponseEntity findList(){
return ok(departmentService.findList()); return ok(departmentService.findList());
} }
@ApiOperation(value = "删除部门")
@DeleteMapping("/deleteDepartment/{id}")
public ResponseEntity deleteDepartment(@PathVariable("id") String id){
boolean b = departmentService.deleteDepartment(id);
if(b){
return ok("删除部门成功");
}
return ok("删除部门失败,可能原因是部门下有角色或者用户");
}
} }
...@@ -49,4 +49,5 @@ public interface ConfigService { ...@@ -49,4 +49,5 @@ public interface ConfigService {
Config findConfig(); Config findConfig();
boolean deleteAll();
} }
...@@ -40,4 +40,7 @@ public interface IDepartmentService { ...@@ -40,4 +40,7 @@ public interface IDepartmentService {
*/ */
List<Department> findList(); List<Department> findList();
boolean deleteDepartment(String id);
boolean updateDepartment(Department department);
} }
...@@ -120,4 +120,10 @@ public class ConfigServiceImpl implements ConfigService { ...@@ -120,4 +120,10 @@ public class ConfigServiceImpl implements ConfigService {
return configDao.findAll().get(0); return configDao.findAll().get(0);
} }
@Override
public boolean deleteAll() {
dayDao.deleteAll();
return true;
}
} }
package com.zjty.tynotes.pas.service.impl; package com.zjty.tynotes.pas.service.impl;
import com.zjty.tynotes.pas.dao.DepartmentDao; import com.zjty.tynotes.pas.dao.DepartmentDao;
import com.zjty.tynotes.pas.dao.PasUserDao;
import com.zjty.tynotes.pas.dao.RoleDao;
import com.zjty.tynotes.pas.entity.Department; import com.zjty.tynotes.pas.entity.Department;
import com.zjty.tynotes.pas.entity.Role;
import com.zjty.tynotes.pas.entity.User;
import com.zjty.tynotes.pas.service.IDepartmentService; import com.zjty.tynotes.pas.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @Author: mcj * @Author: mcj
...@@ -24,6 +25,10 @@ public class DepartmentServiceImpl implements IDepartmentService { ...@@ -24,6 +25,10 @@ public class DepartmentServiceImpl implements IDepartmentService {
@Autowired @Autowired
private DepartmentDao departmentDao; private DepartmentDao departmentDao;
@Autowired
private RoleDao roleDao;
@Autowired
private PasUserDao pasUserDao;
@Override @Override
public List<Department> findAll() { public List<Department> findAll() {
...@@ -54,6 +59,32 @@ public class DepartmentServiceImpl implements IDepartmentService { ...@@ -54,6 +59,32 @@ public class DepartmentServiceImpl implements IDepartmentService {
return departmentList; return departmentList;
} }
@Override
public boolean deleteDepartment(String id) {
List<Role> roles = roleDao.findAllByDepartmentId(id);
List<User> users = pasUserDao.findAllByDepartmentId(id);
if(roles!=null && roles.size()!=0 && users!=null && users.size()!=0){
departmentDao.deleteById(id);
return true;
}
return false;
}
@Override
public boolean updateDepartment(Department department) {
Optional<Department> optional = departmentDao.findById(department.getId());
if(optional.isPresent()){
Department department1 = optional.get();
department1.setDescription(department.getDescription());
department1.setLevel(department.getLevel());
department1.setName(department.getName());
department1.setParentId(department.getParentId());
departmentDao.save(department1);
return true;
}
return false;
}
public void getDepartments(List<Department> departments) { public void getDepartments(List<Department> departments) {
for (Department department : departments) { for (Department department : departments) {
List<Department> departmentList = departmentDao.findAllByParentId(department.getId()); List<Department> departmentList = departmentDao.findAllByParentId(department.getId());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论