Browse Source

feat: [操作日志] 部门操作日志

master
memorylkf 2 months ago
parent
commit
b15048d773
2 changed files with 75 additions and 2 deletions
  1. +4
    -0
      hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysDept.java
  2. +71
    -2
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysDeptServiceImpl.java

+ 4
- 0
hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysDept.java View File

@ -6,6 +6,8 @@ import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import com.hxhq.common.core.annotation.Compare;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.hxhq.common.core.web.domain.BaseEntity; import com.hxhq.common.core.web.domain.BaseEntity;
@ -29,6 +31,7 @@ public class SysDept extends BaseEntity
private String ancestors; private String ancestors;
/** 部门名称 */ /** 部门名称 */
@Compare(name="名称",nameEn = "Name")
private String deptName; private String deptName;
/** 显示顺序 */ /** 显示顺序 */
@ -56,6 +59,7 @@ public class SysDept extends BaseEntity
private Integer type; private Integer type;
/** 缩写 */ /** 缩写 */
@Compare(name="缩写",nameEn = "Abbreviation")
private String abbr; private String abbr;
/** jc */ /** jc */

+ 71
- 2
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysDeptServiceImpl.java View File

@ -7,7 +7,11 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import com.hxhq.business.domain.SystemLog;
import com.hxhq.business.enums.dept.DeptTypeEnum; import com.hxhq.business.enums.dept.DeptTypeEnum;
import com.hxhq.business.service.ISystemLogService;
import com.hxhq.business.utils.ObjectCompareUtil;
import com.hxhq.system.domain.SysMenu;
import com.hxhq.system.domain.vo.TreeSelect; import com.hxhq.system.domain.vo.TreeSelect;
import com.hxhq.system.mapper.SysDeptMapper; import com.hxhq.system.mapper.SysDeptMapper;
import com.hxhq.system.mapper.SysRoleMapper; import com.hxhq.system.mapper.SysRoleMapper;
@ -40,6 +44,9 @@ public class SysDeptServiceImpl implements ISysDeptService
@Autowired @Autowired
private SysRoleMapper roleMapper; private SysRoleMapper roleMapper;
@Autowired
private ISystemLogService systemLogService;
/** /**
* 查询部门管理数据 * 查询部门管理数据
* *
@ -223,7 +230,10 @@ public class SysDeptServiceImpl implements ISysDeptService
throw new ServiceException("部门停用,不允许新增"); throw new ServiceException("部门停用,不允许新增");
} }
dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
return deptMapper.insertDept(dept);
int row = deptMapper.insertDept(dept);
systemLogService.saveInfo(dept.getDeptName(),null,"新增部门","Create Department",null,null,SecurityUtils.getUserId(),SecurityUtils.getNickName(),SecurityUtils.getUsername(),null);
return row;
} }
/** /**
@ -251,6 +261,11 @@ public class SysDeptServiceImpl implements ISysDeptService
// 如果该部门是启用状态则启用该部门的所有上级部门 // 如果该部门是启用状态则启用该部门的所有上级部门
updateParentDeptStatusNormal(dept); updateParentDeptStatusNormal(dept);
} }
List<SystemLog> logList = getModifyLogList(dept,oldDept);
if(logList.size()>0){
systemLogService.saveBatch(logList);
}
return result; return result;
} }
@ -295,7 +310,10 @@ public class SysDeptServiceImpl implements ISysDeptService
@Override @Override
public int deleteDeptById(Long deptId) public int deleteDeptById(Long deptId)
{ {
return deptMapper.deleteDeptById(deptId);
SysDept sysDept = deptMapper.selectDeptById(deptId);
int row = deptMapper.deleteDeptById(deptId);
systemLogService.saveInfo(sysDept.getDeptName(),null,"删除部门","Remove Department",null,null,SecurityUtils.getUserId(),SecurityUtils.getNickName(),SecurityUtils.getUsername(),null);
return row;
} }
@Override @Override
@ -368,4 +386,55 @@ public class SysDeptServiceImpl implements ISysDeptService
{ {
return getChildList(list, t).size() > 0 ? true : false; return getChildList(list, t).size() > 0 ? true : false;
} }
/**
* 获取修改日志
* @param info
* @param old
* @return
*/
private List<SystemLog> getModifyLogList(SysDept info, SysDept old){
List<SystemLog> list = new ArrayList<>();
List<ObjectCompareUtil.FieldChange> fieldChanges = ObjectCompareUtil.compareObjects(old, info);
for (ObjectCompareUtil.FieldChange fieldChange : fieldChanges) {
SystemLog log = getLogInfo(old);
log.setJcnr(fieldChange.toString());
log.setJcnrEn(fieldChange.toEnString());
list.add(log);
}
if(!info.getType().equals(old.getType())){
SystemLog log = getLogInfo(old);
log.setJcnr("[{\"name\":\"字段名\",\"value\":\"状态\"},{\"name\":\"原值\",\"value\":\""+(old.getType().equals(DeptTypeEnum.dept.getValue())?"部门":old.getType().equals(DeptTypeEnum.subject.getValue())?"学科":"小组")+"\"},{\"name\":\"新值\",\"value\":\""+(info.getType().equals(DeptTypeEnum.dept.getValue())?"部门":info.getType().equals(DeptTypeEnum.subject.getValue())?"学科":"小组")+"\"}]");
log.setJcnrEn("[{\"name\":\"Field\",\"value\":\"Status\"},{\"name\":\"Old Value\",\"value\":\""+(old.getType().equals(DeptTypeEnum.dept.getValue())?"Department":old.getType().equals(DeptTypeEnum.subject.getValue())?"Discipline":"Team")+"\"},{\"name\":\"New Value\",\"value\":\""+(info.getType().equals(DeptTypeEnum.dept.getValue())?"Department":info.getType().equals(DeptTypeEnum.subject.getValue())?"Discipline":"Team")+"\"}]");
list.add(log);
}
if(!info.getParentId().equals(old.getParentId())){
SysDept oldParent = deptMapper.selectDeptById(old.getParentId());
SysDept newParent = deptMapper.selectDeptById(info.getParentId());
SystemLog log = getLogInfo(old);
log.setJcnr("[{\"name\":\"字段名\",\"value\":\"上级部门\"},{\"name\":\"原值\",\"value\":\""+oldParent.getDeptName()+"\"},{\"name\":\"新值\",\"value\":\""+newParent.getDeptName()+"\"}]");
log.setJcnrEn("[{\"name\":\"Field\",\"value\":\"Parent\"},{\"name\":\"Old Value\",\"value\":\""+oldParent.getDeptName()+"\"},{\"name\":\"New Value\",\"value\":\""+newParent.getDeptName()+"\"}]");
list.add(log);
}
return list;
}
/**
* 获取日志基础信息
* @return
*/
private SystemLog getLogInfo(SysDept sysDept){
SystemLog log = new SystemLog();
log.setName(sysDept.getDeptName());
log.setNameEn(sysDept.getDeptName());
log.setJcmc("编辑部门");
log.setJcmcEn("Edit Department");
log.setQmrId(SecurityUtils.getUserId());
log.setQmrMc(SecurityUtils.getNickName());
log.setQmrMcEn(SecurityUtils.getUsername());
return log;
}
} }

Loading…
Cancel
Save