|
|
|
@ -2,18 +2,9 @@ package com.keyware.htey.controller.Department; |
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.keyware.htey.entity.department.Department; |
|
|
|
|
import com.keyware.htey.entity.user.AuditLog; |
|
|
|
|
import com.keyware.htey.entity.user.User; |
|
|
|
|
import com.keyware.htey.service.itf.AuditLogService; |
|
|
|
|
import com.keyware.htey.service.itf.DepartmentService; |
|
|
|
|
import com.keyware.htey.service.itf.UserService; |
|
|
|
|
import com.keyware.htey.utli.AjaxMessage; |
|
|
|
|
import com.keyware.htey.utli.Constant; |
|
|
|
|
import com.keyware.htey.utli.DateUtils; |
|
|
|
|
import com.keyware.htey.utli.IdComposeListUtil; |
|
|
|
|
import com.keyware.htey.utli.IdGenerator; |
|
|
|
|
import com.keyware.htey.utli.JsonUtils; |
|
|
|
|
import io.swagger.v3.oas.annotations.Operation; |
|
|
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponse; |
|
|
|
@ -21,7 +12,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
@ -44,10 +34,6 @@ import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
|
public class DepartmentController { |
|
|
|
|
@Autowired |
|
|
|
|
private DepartmentService departmentService; |
|
|
|
|
@Autowired |
|
|
|
|
private AuditLogService auditLogService; |
|
|
|
|
@Autowired |
|
|
|
|
private UserService userService; |
|
|
|
|
|
|
|
|
|
@GetMapping("/selectById") |
|
|
|
|
@ResponseBody |
|
|
|
@ -68,11 +54,6 @@ public class DepartmentController { |
|
|
|
|
@Operation(summary = "新增部门表", description = "返回新增部门信息") |
|
|
|
|
@ApiResponse(responseCode = "200", description = "成功新增部门信息") |
|
|
|
|
public boolean addDepartment(@RequestBody Department department) { |
|
|
|
|
Department oneDepartment = departmentService.getOne( |
|
|
|
|
new QueryWrapper<Department>().eq("id", department.getId())); |
|
|
|
|
if (oneDepartment != null) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return departmentService.save(department); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -81,8 +62,7 @@ public class DepartmentController { |
|
|
|
|
* @date 2025/1/7 |
|
|
|
|
* @description 修改部门 |
|
|
|
|
*/ |
|
|
|
|
@RequestMapping(value = {"/updateDepartment"}, |
|
|
|
|
method = {RequestMethod.POST}, |
|
|
|
|
@RequestMapping(value = {"/updateDepartment"}, method = {RequestMethod.POST}, |
|
|
|
|
produces = {"application/json; charset=utf-8"}) |
|
|
|
|
@ResponseBody |
|
|
|
|
@Operation(summary = "修改部门", description = "返回修改部门信息") |
|
|
|
@ -123,148 +103,34 @@ public class DepartmentController { |
|
|
|
|
// isSys = "sysadmin";
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
List<?> department = this.departmentService.getParentId(id, isSys, projectResource); |
|
|
|
|
List<Department> department = this.departmentService.getParentId(id, isSys, projectResource); |
|
|
|
|
return JsonUtils.arrayListToJsonString(department); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping( |
|
|
|
|
value = {"/select"}, |
|
|
|
|
method = {RequestMethod.POST}, |
|
|
|
|
produces = {"application/json; charset=utf-8"} |
|
|
|
|
) |
|
|
|
|
@RequestMapping(value = {"/select"}, method = {RequestMethod.POST}, produces = {"application/json; charset=utf-8"}) |
|
|
|
|
@ResponseBody |
|
|
|
|
@Operation(summary = "查询部门列表信息", description = "返回查询部门列表") |
|
|
|
|
@ApiResponse(responseCode = "200", description = "成功返回查询部门列表") |
|
|
|
|
public List<Department> select(@RequestBody Department department, @RequestParam(defaultValue = "0") int pageNum, |
|
|
|
|
@RequestParam(defaultValue = "10") int pageSize) { |
|
|
|
|
AuditLog auditLog = new AuditLog(); |
|
|
|
|
department.setPageSize(pageSize); |
|
|
|
|
department.setPageNum(pageNum); |
|
|
|
|
if ("请输入部门名称...".equals(department.getDeptName())) { |
|
|
|
|
department.setDeptName(null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//if ("sysadmin".equals(this.getUser_idFormSession("userId"))) {
|
|
|
|
|
// department.setIsSys("sysadmin");
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
department.setProjectSource(Constant.projectName); |
|
|
|
|
List<Department> departmentList = this.departmentService.selectByDeparmentInfo(department); |
|
|
|
|
//List<Department> parentNameList = new ArrayList<Department>();
|
|
|
|
|
//for(Department vo : departmentList){
|
|
|
|
|
// Integer selectUserCountByDeptId = userService.selectUserCountByDeptId(vo.getId());
|
|
|
|
|
// if(selectUserCountByDeptId != null)
|
|
|
|
|
// vo.setUserCount(selectUserCountByDeptId);
|
|
|
|
|
// Department selectByPrimaryKey = departmentService.selectByPrimaryKey(vo.getParentId());
|
|
|
|
|
// if(selectByPrimaryKey != null)
|
|
|
|
|
// vo.setParentName(selectByPrimaryKey.getDeptName());
|
|
|
|
|
// parentNameList.add(vo);
|
|
|
|
|
//
|
|
|
|
|
//}
|
|
|
|
|
String logName = "查询部门列表"; |
|
|
|
|
String logNameType = "部门管理"; |
|
|
|
|
//String comments = this.getUser_idFormSession("userName") + "查询部门列表,查询关键字为:" + department.getDeptName() ==
|
|
|
|
|
// null ? "" : department.getDeptName();
|
|
|
|
|
//todo 获取登录人信息
|
|
|
|
|
String comments = "查询部门列表,查询关键字为:" + department.getDeptName() == null ? "" |
|
|
|
|
: department.getDeptName(); |
|
|
|
|
auditLog.setLogName(logName); |
|
|
|
|
auditLog.setLogNameType(logNameType); |
|
|
|
|
auditLog.setComments(comments); |
|
|
|
|
auditLogService.addAuditLog(auditLog); |
|
|
|
|
return departmentList; |
|
|
|
|
return departmentService.selectList(department, pageNum, pageSize); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping( |
|
|
|
|
value = {"/checkDepartMentName"}, |
|
|
|
|
method = {RequestMethod.POST}, |
|
|
|
|
produces = {"application/json; charset=utf-8"} |
|
|
|
|
) |
|
|
|
|
@RequestMapping(value = {"/checkDepartMentName"}, method = {RequestMethod.POST}, |
|
|
|
|
produces = {"application/json; charset=utf-8"}) |
|
|
|
|
@ResponseBody |
|
|
|
|
@Operation(summary = "部门校验", description = "返回部门校验是否成功") |
|
|
|
|
@ApiResponse(responseCode = "200", description = "部门校验成功") |
|
|
|
|
public AjaxMessage checkDepartMentName(String name) { |
|
|
|
|
AjaxMessage ajaxMessage = new AjaxMessage(); |
|
|
|
|
if (StringUtils.hasText(name)) { |
|
|
|
|
List<Department> selectByDeparmentName = this.departmentService.selectByDeparmentName(name); |
|
|
|
|
if (selectByDeparmentName.size() > 0) { |
|
|
|
|
ajaxMessage.setCode("1"); |
|
|
|
|
ajaxMessage.setMessage("部门名称已存在"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ajaxMessage; |
|
|
|
|
return departmentService.checkDepartMentName(name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping( |
|
|
|
|
value = {"/add"}, |
|
|
|
|
method = {RequestMethod.POST}, |
|
|
|
|
produces = {"application/json; charset=utf-8"} |
|
|
|
|
) |
|
|
|
|
@RequestMapping(value = {"/add"}, method = {RequestMethod.POST}, produces = {"application/json; charset=utf-8"}) |
|
|
|
|
@ResponseBody |
|
|
|
|
@Operation(summary = "部门添加", description = "返回部门添加是否成功") |
|
|
|
|
@ApiResponse(responseCode = "200", description = "部门添加成功") |
|
|
|
|
public AjaxMessage add(@ModelAttribute Department department) { |
|
|
|
|
AjaxMessage ajaxMessage = new AjaxMessage(); |
|
|
|
|
AuditLog auditLog = new AuditLog(); |
|
|
|
|
try { |
|
|
|
|
Department departmentSelect = new Department(); |
|
|
|
|
departmentSelect.setDeptName(department.getDeptName()); |
|
|
|
|
List<Department> selectByDeparmentInfo = this.departmentService.selectByDeparmentInfoSelect( |
|
|
|
|
departmentSelect); |
|
|
|
|
if (selectByDeparmentInfo.size() > 0) { |
|
|
|
|
ajaxMessage.setCode("0"); |
|
|
|
|
ajaxMessage.setMessage("部门名称已存在"); |
|
|
|
|
return ajaxMessage; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Department departmentSelect1 = new Department(); |
|
|
|
|
departmentSelect1.setDeptNumber(department.getDeptNumber()); |
|
|
|
|
List<Department> selectByDeparmentInfo1 = this.departmentService.selectByDeparmentInfoSelect( |
|
|
|
|
departmentSelect1); |
|
|
|
|
if (selectByDeparmentInfo1.size() > 0) { |
|
|
|
|
ajaxMessage.setCode("0"); |
|
|
|
|
ajaxMessage.setMessage("部门编号已存在"); |
|
|
|
|
return ajaxMessage; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String deptId = IdGenerator.uuid32(); |
|
|
|
|
department.setId(deptId); |
|
|
|
|
department.setIsSys("0"); |
|
|
|
|
department.setDeptCreateTime(DateUtils.getDateTime()); |
|
|
|
|
department.setTotalWorkers(0); |
|
|
|
|
this.departmentService.insertSelective(department); |
|
|
|
|
User user = new User(); |
|
|
|
|
user.setId(department.getCharge()); |
|
|
|
|
user.setDepartId(deptId); |
|
|
|
|
this.userService.updateByPrimaryKeySelective(user); |
|
|
|
|
ajaxMessage.setCode("1"); |
|
|
|
|
ajaxMessage.setMessage("保存成功"); |
|
|
|
|
StringBuilder info = new StringBuilder(); |
|
|
|
|
info.append("部门简称:" + department.getDepartAbbrevia() + ";"); |
|
|
|
|
info.append("上级部门:" + department.getParentName() + ";"); |
|
|
|
|
info.append("部门负责:" + department.getChargeName() + ";"); |
|
|
|
|
info.append("部门接口人:" + department.getInterfacePersonName() + ";"); |
|
|
|
|
info.append("上级主管领导:" + department.getSuperLeaderName() + ";"); |
|
|
|
|
info.append("部门管理人:" + department.getManagerName() + ";"); |
|
|
|
|
info.append("部门描述:" + department.getComments() + ";"); |
|
|
|
|
String logName = "添加部门"; |
|
|
|
|
String logNameType = "部门管理"; |
|
|
|
|
/*String comments = this.getUser_idFormSession("userName") + "添加" + department.getDeptName() + "部门,详细信息:" |
|
|
|
|
+ info;*/ |
|
|
|
|
//todo 获取登录人信息
|
|
|
|
|
String comments = "添加" + department.getDeptName() + "部门,详细信息:" + info; |
|
|
|
|
auditLog.setLogName(logName); |
|
|
|
|
auditLog.setLogNameType(logNameType); |
|
|
|
|
auditLog.setComments(comments); |
|
|
|
|
auditLogService.addAuditLog(auditLog); |
|
|
|
|
} catch (Exception var10) { |
|
|
|
|
log.error("部门添加失败", var10); |
|
|
|
|
var10.printStackTrace(); |
|
|
|
|
ajaxMessage.setCode("0"); |
|
|
|
|
ajaxMessage.setMessage(Constant.ERROE_MESSAGE); |
|
|
|
|
} |
|
|
|
|
return ajaxMessage; |
|
|
|
|
return departmentService.add(department); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/edit", method = RequestMethod.POST, produces = "application/json; charset=utf-8") |
|
|
|
@ -272,105 +138,7 @@ public class DepartmentController { |
|
|
|
|
@Operation(summary = "部门修改", description = "返回部门修改是否成功") |
|
|
|
|
@ApiResponse(responseCode = "200", description = "部门添加修改") |
|
|
|
|
public AjaxMessage edit(@ModelAttribute Department department) { |
|
|
|
|
AjaxMessage ajaxMessage = new AjaxMessage(); |
|
|
|
|
AuditLog auditLog = new AuditLog(); |
|
|
|
|
try { |
|
|
|
|
Department oldDepartment = departmentService.selectByPrimaryKey(department.getId()); |
|
|
|
|
departmentService.updateByPrimaryKeySelective(department); |
|
|
|
|
ajaxMessage.setCode("1"); |
|
|
|
|
ajaxMessage.setMessage("保存成功"); |
|
|
|
|
|
|
|
|
|
StringBuilder info = new StringBuilder(); |
|
|
|
|
if (oldDepartment.getDepartAbbrevia() == null) {oldDepartment.setDepartAbbrevia("");} |
|
|
|
|
if (!oldDepartment.getDepartAbbrevia().equals(department.getDepartAbbrevia())) { |
|
|
|
|
info.append( |
|
|
|
|
"部门简称从" + oldDepartment.getDepartAbbrevia() + "修改为" + department.getDepartAbbrevia() + ";"); |
|
|
|
|
} |
|
|
|
|
if (oldDepartment.getParentId() == null) {oldDepartment.setParentId("");} |
|
|
|
|
if (!oldDepartment.getParentId().equals(department.getParentId())) { |
|
|
|
|
String oldName = "空"; |
|
|
|
|
String newName = "空"; |
|
|
|
|
if (StringUtils.hasText(oldDepartment.getParentId())) { |
|
|
|
|
Department department1 = departmentService.selectByPrimaryKey(oldDepartment.getParentId()); |
|
|
|
|
oldName = department1.getDeptName(); |
|
|
|
|
} |
|
|
|
|
if (StringUtils.hasText(department.getParentId())) { |
|
|
|
|
Department department1 = departmentService.selectByPrimaryKey(department.getParentId()); |
|
|
|
|
newName = department1.getDeptName(); |
|
|
|
|
} |
|
|
|
|
info.append("上级部门从" + oldName + "修改为" + newName + ";"); |
|
|
|
|
} |
|
|
|
|
if (oldDepartment.getCharge() == null) {oldDepartment.setCharge("");} |
|
|
|
|
if (!oldDepartment.getCharge().equals(department.getCharge())) { |
|
|
|
|
String oldName = "空"; |
|
|
|
|
if (StringUtils.hasText(oldDepartment.getCharge())) { |
|
|
|
|
User user = userService.selectByPrimaryKey(oldDepartment.getCharge()); |
|
|
|
|
oldName = user.getUserName(); |
|
|
|
|
} |
|
|
|
|
info.append("部门负责人从" + oldName + "修改为" + department.getChargeName() + ";"); |
|
|
|
|
} |
|
|
|
|
if (oldDepartment.getInterfacePerson() == null) {oldDepartment.setInterfacePerson("");} |
|
|
|
|
if (!oldDepartment.getInterfacePerson().equals(department.getInterfacePerson())) { |
|
|
|
|
String oldName = "空"; |
|
|
|
|
if (StringUtils.hasText(oldDepartment.getInterfacePerson())) { |
|
|
|
|
String interfacePerson = oldDepartment.getInterfacePerson(); |
|
|
|
|
String[] split = interfacePerson.split(","); |
|
|
|
|
for (String s : split) { |
|
|
|
|
User user = userService.selectByPrimaryKey(s); |
|
|
|
|
oldName += user.getUserName() + ","; |
|
|
|
|
} |
|
|
|
|
oldName = oldName.substring(0, oldName.length() - 1); |
|
|
|
|
} |
|
|
|
|
info.append("部门接口人从" + oldName + "修改为" + department.getInterfacePersonName() + ";"); |
|
|
|
|
} |
|
|
|
|
if (oldDepartment.getSuperLeader() == null) {oldDepartment.setSuperLeader("");} |
|
|
|
|
if (!oldDepartment.getSuperLeader().equals(department.getSuperLeader())) { |
|
|
|
|
String oldName = "空"; |
|
|
|
|
if (StringUtils.hasText(oldDepartment.getSuperLeader())) { |
|
|
|
|
String interfacePerson = oldDepartment.getSuperLeader(); |
|
|
|
|
String[] split = interfacePerson.split(","); |
|
|
|
|
for (String s : split) { |
|
|
|
|
User user = userService.selectByPrimaryKey(s); |
|
|
|
|
oldName += user.getUserName() + ","; |
|
|
|
|
} |
|
|
|
|
oldName = oldName.substring(0, oldName.length() - 1); |
|
|
|
|
} |
|
|
|
|
info.append("上级主管领导从" + oldName + "修改为" + department.getSuperLeaderName() + ";"); |
|
|
|
|
} |
|
|
|
|
if (oldDepartment.getManager() == null) {oldDepartment.setManager("");} |
|
|
|
|
if (!oldDepartment.getManager().equals(department.getManager())) { |
|
|
|
|
StringBuilder oldName = new StringBuilder("空"); |
|
|
|
|
if (StringUtils.hasText(oldDepartment.getManager())) { |
|
|
|
|
String interfacePerson = oldDepartment.getManager(); |
|
|
|
|
String[] split = interfacePerson.split(","); |
|
|
|
|
for (String s : split) { |
|
|
|
|
User user = userService.selectByPrimaryKey(s); |
|
|
|
|
oldName.append(user.getUserName()).append(","); |
|
|
|
|
} |
|
|
|
|
oldName = new StringBuilder(oldName.substring(0, oldName.length() - 1)); |
|
|
|
|
} |
|
|
|
|
info.append("部门管理人从" + oldName + "修改为" + department.getManagerName() + ";"); |
|
|
|
|
} |
|
|
|
|
if (oldDepartment.getComments() == null) {oldDepartment.setComments("");} |
|
|
|
|
if (!oldDepartment.getComments().equals(department.getComments())) { |
|
|
|
|
info.append("部门描述从" + oldDepartment.getComments() + "修改为" + department.getComments() + ";"); |
|
|
|
|
} |
|
|
|
|
String logName = "修改部门信息"; |
|
|
|
|
String logNameType = "部门管理"; |
|
|
|
|
/*String comments = getUser_idFormSession("userName")+"修改了"+department.getDeptName()+"部门详细信息:" + info;*/ |
|
|
|
|
//todo 获取登录人信息
|
|
|
|
|
String comments = "修改了" + department.getDeptName() + "部门详细信息:" + info; |
|
|
|
|
auditLog.setLogName(logName); |
|
|
|
|
auditLog.setLogNameType(logNameType); |
|
|
|
|
auditLog.setComments(comments); |
|
|
|
|
auditLogService.addAuditLog(auditLog); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("修改失败", e); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
ajaxMessage.setCode("0"); |
|
|
|
|
ajaxMessage.setMessage("系统错误,请联系管理员"); |
|
|
|
|
} |
|
|
|
|
return ajaxMessage; |
|
|
|
|
return departmentService.edit(department); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/delete", method = RequestMethod.POST, produces = "application/json; charset=utf-8") |
|
|
|
@ -378,27 +146,6 @@ public class DepartmentController { |
|
|
|
|
@Operation(summary = "部门删除", description = "返回部门删除是否成功") |
|
|
|
|
@ApiResponse(responseCode = "200", description = "部门删除修改") |
|
|
|
|
public String delete(@RequestBody List<Department> departments) { |
|
|
|
|
List<String> listId = IdComposeListUtil.listDepartmentId(departments); |
|
|
|
|
StringBuilder deparNames = new StringBuilder(); |
|
|
|
|
for (String id : listId) { |
|
|
|
|
Department selectByPrimaryKey = departmentService.selectByPrimaryKey(id); |
|
|
|
|
deparNames.append(selectByPrimaryKey.getDeptName()).append(","); |
|
|
|
|
} |
|
|
|
|
departmentService.deleteByPrimaryKey(listId); |
|
|
|
|
if (deparNames.length() > 0) { |
|
|
|
|
AuditLog auditLog = new AuditLog(); |
|
|
|
|
String logName = "删除部门"; |
|
|
|
|
String logNameType = "部门管理"; |
|
|
|
|
/*String comments = getUser_idFormSession("userName")+"删除了"+deparNames.substring(0, deparNames.length() |
|
|
|
|
-1)+"部门";*/ |
|
|
|
|
//todo 获取登录人信息
|
|
|
|
|
String comments = "删除了" + deparNames.substring(0, deparNames.length() - 1) + "部门"; |
|
|
|
|
auditLog.setLogName(logName); |
|
|
|
|
auditLog.setLogNameType(logNameType); |
|
|
|
|
auditLog.setComments(comments); |
|
|
|
|
auditLogService.addAuditLog(auditLog); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return "删除成功"; |
|
|
|
|
return departmentService.delete(departments); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|