diff --git a/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysDept.java b/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysDept.java index f5f4e04..b61f349 100644 --- a/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysDept.java +++ b/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysDept.java @@ -6,6 +6,8 @@ import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; 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.ToStringStyle; import com.hxhq.common.core.web.domain.BaseEntity; @@ -29,6 +31,7 @@ public class SysDept extends BaseEntity private String ancestors; /** 部门名称 */ + @Compare(name="名称",nameEn = "Name") private String deptName; /** 显示顺序 */ @@ -56,6 +59,7 @@ public class SysDept extends BaseEntity private Integer type; /** 缩写 */ + @Compare(name="缩写",nameEn = "Abbreviation") private String abbr; /** jc */ diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysDeptServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysDeptServiceImpl.java index 5494b24..74d5094 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysDeptServiceImpl.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysDeptServiceImpl.java @@ -7,7 +7,11 @@ import java.util.List; import java.util.stream.Collectors; import cn.hutool.core.util.ArrayUtil; +import com.hxhq.business.domain.SystemLog; 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.mapper.SysDeptMapper; import com.hxhq.system.mapper.SysRoleMapper; @@ -40,6 +44,9 @@ public class SysDeptServiceImpl implements ISysDeptService @Autowired private SysRoleMapper roleMapper; + @Autowired + private ISystemLogService systemLogService; + /** * 查询部门管理数据 * @@ -223,7 +230,10 @@ public class SysDeptServiceImpl implements ISysDeptService throw new ServiceException("部门停用,不允许新增"); } 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); } + + List logList = getModifyLogList(dept,oldDept); + if(logList.size()>0){ + systemLogService.saveBatch(logList); + } return result; } @@ -295,7 +310,10 @@ public class SysDeptServiceImpl implements ISysDeptService @Override 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 @@ -368,4 +386,55 @@ public class SysDeptServiceImpl implements ISysDeptService { return getChildList(list, t).size() > 0 ? true : false; } + + /** + * 获取修改日志 + * @param info + * @param old + * @return + */ + private List getModifyLogList(SysDept info, SysDept old){ + List list = new ArrayList<>(); + + List 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; + } }