|
|
@@ -4,6 +4,9 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.mzt.logapi.context.LogRecordContext;
|
|
|
+import com.mzt.logapi.service.impl.DiffParseFunction;
|
|
|
+import com.mzt.logapi.starter.annotation.LogRecord;
|
|
|
import com.poteviohealth.cgp.sso.framework.common.enums.CommonStatusEnum;
|
|
|
import com.poteviohealth.cgp.sso.framework.common.pojo.PageResult;
|
|
|
import com.poteviohealth.cgp.sso.framework.common.util.object.BeanUtils;
|
|
|
@@ -13,20 +16,16 @@ import com.poteviohealth.cgp.sso.module.system.controller.admin.dept.vo.dept.Dep
|
|
|
import com.poteviohealth.cgp.sso.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
|
|
|
import com.poteviohealth.cgp.sso.module.system.dal.dataobject.dept.DeptDO;
|
|
|
import com.poteviohealth.cgp.sso.module.system.dal.dataobject.sequence.SequenceDO;
|
|
|
-import com.poteviohealth.cgp.sso.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
import com.poteviohealth.cgp.sso.module.system.dal.mysql.dept.DeptMapper;
|
|
|
import com.poteviohealth.cgp.sso.module.system.dal.mysql.sequence.SequenceMapper;
|
|
|
import com.poteviohealth.cgp.sso.module.system.dal.mysql.user.AdminUserMapper;
|
|
|
import com.poteviohealth.cgp.sso.module.system.dal.redis.RedisKeyConstants;
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
|
-import com.poteviohealth.cgp.sso.module.system.enums.permission.RoleTypeEnum;
|
|
|
-import com.poteviohealth.cgp.sso.module.system.service.user.AdminUserService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
-import org.springframework.security.core.parameters.P;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
@@ -37,6 +36,7 @@ import java.util.*;
|
|
|
import static com.poteviohealth.cgp.sso.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static com.poteviohealth.cgp.sso.framework.common.util.collection.CollectionUtils.convertSet;
|
|
|
import static com.poteviohealth.cgp.sso.module.system.enums.ErrorCodeConstants.*;
|
|
|
+import static com.poteviohealth.cgp.sso.module.system.enums.LogRecordConstants.*;
|
|
|
|
|
|
/**
|
|
|
* 部门 Service 实现类
|
|
|
@@ -61,6 +61,8 @@ public class DeptServiceImpl implements DeptService {
|
|
|
@Override
|
|
|
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
|
|
|
allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存
|
|
|
+ @LogRecord(type = SYSTEM_DEPT_TYPE, subType = SYSTEM_DEPT_CREATE_SUB_TYPE, bizNo = "{{#dept.id}}",
|
|
|
+ success = SYSTEM_DEPT_CREATE_SUCCESS)
|
|
|
public Long createDept(DeptSaveReqVO createReqVO) {
|
|
|
if (createReqVO.getParentId() == null) {
|
|
|
createReqVO.setParentId(DeptDO.PARENT_ID_ROOT);
|
|
|
@@ -92,6 +94,9 @@ public class DeptServiceImpl implements DeptService {
|
|
|
// 插入部门
|
|
|
DeptDO dept = BeanUtils.toBean(createReqVO, DeptDO.class);
|
|
|
deptMapper.insert(dept);
|
|
|
+
|
|
|
+ // 3. 记录操作日志上下文
|
|
|
+ LogRecordContext.putVariable("dept", dept);
|
|
|
return dept.getId();
|
|
|
}
|
|
|
|
|
|
@@ -138,6 +143,8 @@ public class DeptServiceImpl implements DeptService {
|
|
|
@Override
|
|
|
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
|
|
|
allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存
|
|
|
+ @LogRecord(type = SYSTEM_DEPT_TYPE, subType = SYSTEM_DEPT_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
|
|
|
+ success = SYSTEM_DEPT_UPDATE_SUCCESS)
|
|
|
public void updateDept(DeptSaveReqVO updateReqVO) {
|
|
|
if (updateReqVO.getParentId() == null) {
|
|
|
updateReqVO.setParentId(DeptDO.PARENT_ID_ROOT);
|
|
|
@@ -161,6 +168,9 @@ public class DeptServiceImpl implements DeptService {
|
|
|
updateReqVO.setCode(null);
|
|
|
// 更新部门
|
|
|
DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
|
|
|
+ // 3. 记录操作日志上下文
|
|
|
+ LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(deptDO, DeptSaveReqVO.class));
|
|
|
+ LogRecordContext.putVariable("dept", updateObj);
|
|
|
deptMapper.updateById(updateObj);
|
|
|
}
|
|
|
|
|
|
@@ -181,6 +191,8 @@ public class DeptServiceImpl implements DeptService {
|
|
|
@Override
|
|
|
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
|
|
|
allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存
|
|
|
+ @LogRecord(type = SYSTEM_DEPT_TYPE, subType = SYSTEM_DEPT_DELETE_SUB_TYPE, bizNo = "{{#id}}",
|
|
|
+ success = SYSTEM_DEPT_DELETE_SUCCESS)
|
|
|
public void deleteDept(Long id) {
|
|
|
// 校验是否存在
|
|
|
validateDeptExists(id);
|
|
|
@@ -191,8 +203,11 @@ public class DeptServiceImpl implements DeptService {
|
|
|
if (CollectionUtils.isNotEmpty(adminUserMapper.selectListByDeptIds(Collections.singletonList(id)))){
|
|
|
throw exception(DEPT_EXITS_USERS);
|
|
|
}
|
|
|
+ DeptDO dept = deptMapper.selectById(id);
|
|
|
// 删除部门
|
|
|
deptMapper.deleteById(id);
|
|
|
+ // 3. 记录操作日志上下文
|
|
|
+ LogRecordContext.putVariable("dept", dept);
|
|
|
}
|
|
|
|
|
|
@VisibleForTesting
|