feat: app功能基本实现
This commit is contained in:
+154
-7
@@ -1,6 +1,9 @@
|
||||
package com.agileboot.domain.collaboration.record;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.collaboration.record.command.AddCollaborationRecordCommand;
|
||||
import com.agileboot.domain.collaboration.record.command.CollaborationExpenditureCommand;
|
||||
import com.agileboot.domain.collaboration.record.command.CollaborationFileCommand;
|
||||
@@ -32,6 +35,8 @@ import com.agileboot.domain.collaboration.record.model.CollaborationRecordModel;
|
||||
import com.agileboot.domain.collaboration.record.model.CollaborationRecordModelFactory;
|
||||
import com.agileboot.domain.collaboration.record.query.CollaborationRecordQuery;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.infrastructure.user.AuthenticationUtils;
|
||||
import com.agileboot.infrastructure.user.web.SystemLoginUser;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.math.BigDecimal;
|
||||
@@ -42,6 +47,7 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -57,6 +63,8 @@ public class CollaborationRecordApplicationService {
|
||||
private static final String PURCHASE_FEE = "拍单费用";
|
||||
private static final String DELIVERY_FEE = "快递费用";
|
||||
private static final String REMUNERATION_FEE = "稿费";
|
||||
private static final String TASK_STATUS_COMPLETED = "COMPLETED";
|
||||
private static final String TASK_STATUS_INCOMPLETE = "INCOMPLETE";
|
||||
|
||||
private final CollaborationRecordModelFactory recordModelFactory;
|
||||
private final CollaborationRecordService recordService;
|
||||
@@ -66,7 +74,10 @@ public class CollaborationRecordApplicationService {
|
||||
private final CollaborationFileService fileService;
|
||||
|
||||
public PageDTO<CollaborationRecordDTO> getRecordList(CollaborationRecordQuery query) {
|
||||
Page<CollaborationRecordEntity> page = recordService.page(query.toPage(), query.toQueryWrapper());
|
||||
if (hasComputedFilters(query)) {
|
||||
return getComputedFilteredRecordList(query);
|
||||
}
|
||||
Page<CollaborationRecordEntity> page = recordService.page(query.toPage(), getScopedRecordWrapper(query));
|
||||
List<CollaborationRecordDTO> records = page.getRecords().stream()
|
||||
.map(this::buildRecordDTO)
|
||||
.collect(Collectors.toList());
|
||||
@@ -74,7 +85,7 @@ public class CollaborationRecordApplicationService {
|
||||
}
|
||||
|
||||
public CollaborationRecordDetailDTO getRecordInfo(Long recordId) {
|
||||
CollaborationRecordModel model = recordModelFactory.loadById(recordId);
|
||||
CollaborationRecordModel model = loadRecordInScope(recordId);
|
||||
CollaborationRecordDetailDTO dto = new CollaborationRecordDetailDTO(model);
|
||||
fillDetailChildren(dto, recordId);
|
||||
fillRecordStats(dto, recordId);
|
||||
@@ -85,14 +96,16 @@ public class CollaborationRecordApplicationService {
|
||||
public void addRecord(AddCollaborationRecordCommand command) {
|
||||
CollaborationRecordModel model = recordModelFactory.create();
|
||||
model.loadFromAddCommand(command);
|
||||
model.setCompleteDate(getRecordCompleteDate(command.getTasks(), CollaborationTaskCommand::getReleaseDate));
|
||||
model.saveRecord();
|
||||
saveChildren(model.getRecordId(), command);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateRecord(UpdateCollaborationRecordCommand command) {
|
||||
CollaborationRecordModel model = recordModelFactory.loadById(command.getRecordId());
|
||||
CollaborationRecordModel model = loadRecordInScope(command.getRecordId());
|
||||
model.loadFromUpdateCommand(command);
|
||||
model.setCompleteDate(getRecordCompleteDate(command.getTasks(), CollaborationTaskCommand::getReleaseDate));
|
||||
model.updateRecord();
|
||||
replaceChildren(command.getRecordId(), command);
|
||||
}
|
||||
@@ -103,6 +116,7 @@ public class CollaborationRecordApplicationService {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
checkAllRecordsInScope(ids);
|
||||
taskService.removeByRecordIds(ids);
|
||||
expenditureService.removeByRecordIds(ids);
|
||||
settlementService.removeByRecordIds(ids);
|
||||
@@ -124,6 +138,108 @@ public class CollaborationRecordApplicationService {
|
||||
return statistics;
|
||||
}
|
||||
|
||||
private QueryWrapper<CollaborationRecordEntity> getScopedRecordWrapper(CollaborationRecordQuery query) {
|
||||
QueryWrapper<CollaborationRecordEntity> wrapper = query.toQueryWrapper();
|
||||
applyCurrentCreatorScope(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private PageDTO<CollaborationRecordDTO> getComputedFilteredRecordList(CollaborationRecordQuery query) {
|
||||
List<CollaborationRecordDTO> records = recordService.list(getScopedRecordWrapper(query)).stream()
|
||||
.map(this::buildRecordDTO)
|
||||
.filter(record -> matchesComputedFilters(record, query))
|
||||
.collect(Collectors.toList());
|
||||
return new PageDTO<>(pageRecords(records, query), (long) records.size());
|
||||
}
|
||||
|
||||
private List<CollaborationRecordDTO> pageRecords(List<CollaborationRecordDTO> records, CollaborationRecordQuery query) {
|
||||
Page<CollaborationRecordEntity> page = query.toPage();
|
||||
int start = (int) Math.min((page.getCurrent() - 1) * page.getSize(), records.size());
|
||||
int end = (int) Math.min(start + page.getSize(), records.size());
|
||||
return records.subList(start, end);
|
||||
}
|
||||
|
||||
private boolean hasComputedFilters(CollaborationRecordQuery query) {
|
||||
return StrUtil.isNotEmpty(query.getSettlementStatus()) || StrUtil.isNotEmpty(query.getTaskStatus());
|
||||
}
|
||||
|
||||
private boolean matchesComputedFilters(CollaborationRecordDTO record, CollaborationRecordQuery query) {
|
||||
return matchesSettlementStatus(record, query.getSettlementStatus())
|
||||
&& matchesTaskStatus(record, query.getTaskStatus());
|
||||
}
|
||||
|
||||
private boolean matchesSettlementStatus(CollaborationRecordDTO record, String status) {
|
||||
if (StrUtil.isEmpty(status)) {
|
||||
return true;
|
||||
}
|
||||
return status.equals(getRecordSettlementStatus(record));
|
||||
}
|
||||
|
||||
private String getRecordSettlementStatus(CollaborationRecordDTO record) {
|
||||
return SettlementStatusEnum.aggregate(Arrays.asList(
|
||||
getSettlementStatusValue(record.getPurchaseSettlementStatus()),
|
||||
getSettlementStatusValue(record.getDeliverySettlementStatus()),
|
||||
getSettlementStatusValue(record.getRemunerationSettlementStatus())
|
||||
));
|
||||
}
|
||||
|
||||
private String getSettlementStatusValue(SettlementStatusDTO status) {
|
||||
return status == null ? SettlementStatusEnum.NONE.getValue() : status.getStatus();
|
||||
}
|
||||
|
||||
private boolean matchesTaskStatus(CollaborationRecordDTO record, String status) {
|
||||
if (StrUtil.isEmpty(status)) {
|
||||
return true;
|
||||
}
|
||||
boolean isCompleted = isRecordCompleted(record);
|
||||
if (TASK_STATUS_COMPLETED.equals(status)) {
|
||||
return isCompleted;
|
||||
}
|
||||
return TASK_STATUS_INCOMPLETE.equals(status) && !isCompleted;
|
||||
}
|
||||
|
||||
private boolean isRecordCompleted(CollaborationRecordDTO record) {
|
||||
Integer tasksNum = record.getTasksNum();
|
||||
Integer completedTasksNum = record.getCompletedTasksNum();
|
||||
return tasksNum != null && tasksNum > 0 && tasksNum.equals(completedTasksNum);
|
||||
}
|
||||
|
||||
private CollaborationRecordModel loadRecordInScope(Long recordId) {
|
||||
CollaborationRecordEntity entity = recordService.getOne(buildScopedRecordIdWrapper(recordId));
|
||||
if (entity == null) {
|
||||
throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, recordId, "合作记录");
|
||||
}
|
||||
return new CollaborationRecordModel(entity, recordService);
|
||||
}
|
||||
|
||||
private QueryWrapper<CollaborationRecordEntity> buildScopedRecordIdWrapper(Long recordId) {
|
||||
QueryWrapper<CollaborationRecordEntity> wrapper = new QueryWrapper<CollaborationRecordEntity>()
|
||||
.eq("record_id", recordId);
|
||||
applyCurrentCreatorScope(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private void checkAllRecordsInScope(Set<Long> ids) {
|
||||
QueryWrapper<CollaborationRecordEntity> wrapper = new QueryWrapper<CollaborationRecordEntity>()
|
||||
.in("record_id", ids);
|
||||
applyCurrentCreatorScope(wrapper);
|
||||
if (recordService.count(wrapper) != ids.size()) {
|
||||
throw new ApiException(ErrorCode.Business.PERMISSION_NOT_ALLOWED_TO_OPERATE);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyCurrentCreatorScope(QueryWrapper<CollaborationRecordEntity> wrapper) {
|
||||
Long creatorId = getCurrentCreatorScope();
|
||||
if (creatorId != null) {
|
||||
wrapper.eq("creator_id", creatorId);
|
||||
}
|
||||
}
|
||||
|
||||
private Long getCurrentCreatorScope() {
|
||||
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
|
||||
return loginUser.isAdmin() ? null : loginUser.getUserId();
|
||||
}
|
||||
|
||||
private CollaborationRecordDTO buildRecordDTO(CollaborationRecordEntity entity) {
|
||||
CollaborationRecordDTO dto = new CollaborationRecordDTO(entity);
|
||||
fillRecordStats(dto, entity.getRecordId());
|
||||
@@ -151,11 +267,25 @@ public class CollaborationRecordApplicationService {
|
||||
List<CollaborationSettlementEntity> settlements = settlementService.listByRecordId(recordId);
|
||||
dto.setTasksNum(tasks.size());
|
||||
dto.setCompletedTasksNum((int) tasks.stream().filter(item -> item.getReleaseDate() != null).count());
|
||||
dto.setCompleteDate(getRecordCompleteDate(tasks, CollaborationTaskEntity::getReleaseDate));
|
||||
dto.setPurchaseSettlementStatus(getStatus(dto.getPurchasePrice(), settlements, PURCHASE_FEE));
|
||||
dto.setDeliverySettlementStatus(getStatus(sumExpenditure(expenditures, DELIVERY_FEE), settlements, DELIVERY_FEE));
|
||||
dto.setRemunerationSettlementStatus(getStatus(dto.getRemuneration(), settlements, REMUNERATION_FEE));
|
||||
}
|
||||
|
||||
private <T> Date getRecordCompleteDate(List<T> tasks, Function<T, Date> getReleaseDate) {
|
||||
if (tasks == null || tasks.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (tasks.stream().anyMatch(item -> getReleaseDate.apply(item) == null)) {
|
||||
return null;
|
||||
}
|
||||
return tasks.stream()
|
||||
.map(getReleaseDate)
|
||||
.max(Date::compareTo)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private SettlementStatusDTO getStatus(
|
||||
BigDecimal expectedAmount, List<CollaborationSettlementEntity> settlements, String purpose) {
|
||||
List<CollaborationSettlementEntity> matched = filterSettlements(settlements, purpose);
|
||||
@@ -335,9 +465,11 @@ public class CollaborationRecordApplicationService {
|
||||
}
|
||||
|
||||
private BigDecimal sumPurchasePrice(Date[] range) {
|
||||
List<CollaborationRecordEntity> records = recordService.list(new QueryWrapper<CollaborationRecordEntity>()
|
||||
QueryWrapper<CollaborationRecordEntity> wrapper = new QueryWrapper<CollaborationRecordEntity>()
|
||||
.ge("purchase_date", range[0])
|
||||
.le("purchase_date", range[1]));
|
||||
.le("purchase_date", range[1]);
|
||||
applyCurrentCreatorScope(wrapper);
|
||||
List<CollaborationRecordEntity> records = recordService.list(wrapper);
|
||||
return records.stream()
|
||||
.map(CollaborationRecordEntity::getPurchasePrice)
|
||||
.map(this::defaultAmount)
|
||||
@@ -345,8 +477,11 @@ public class CollaborationRecordApplicationService {
|
||||
}
|
||||
|
||||
private BigDecimal sumExpenditure(Date[] range) {
|
||||
List<CollaborationExpenditureEntity> expenditures = expenditureService.list(
|
||||
new QueryWrapper<CollaborationExpenditureEntity>().ge("spend_date", range[0]).le("spend_date", range[1]));
|
||||
QueryWrapper<CollaborationExpenditureEntity> wrapper = new QueryWrapper<CollaborationExpenditureEntity>()
|
||||
.ge("spend_date", range[0])
|
||||
.le("spend_date", range[1]);
|
||||
applyChildRecordScope(wrapper);
|
||||
List<CollaborationExpenditureEntity> expenditures = expenditureService.list(wrapper);
|
||||
return expenditures.stream()
|
||||
.map(CollaborationExpenditureEntity::getAmount)
|
||||
.map(this::defaultAmount)
|
||||
@@ -358,9 +493,21 @@ public class CollaborationRecordApplicationService {
|
||||
.ge("settle_date", range[0])
|
||||
.le("settle_date", range[1])
|
||||
.eq(purpose != null, "purpose", purpose);
|
||||
applyChildRecordScope(wrapper);
|
||||
return sumSettlement(settlementService.list(wrapper));
|
||||
}
|
||||
|
||||
private void applyChildRecordScope(QueryWrapper<?> wrapper) {
|
||||
Long creatorId = getCurrentCreatorScope();
|
||||
if (creatorId != null) {
|
||||
wrapper.inSql("record_id", buildCreatorRecordSubQuery(creatorId));
|
||||
}
|
||||
}
|
||||
|
||||
private String buildCreatorRecordSubQuery(Long creatorId) {
|
||||
return "select record_id from collaboration_record where deleted = 0 and creator_id = " + creatorId;
|
||||
}
|
||||
|
||||
private BigDecimal sumExpenditure(List<CollaborationExpenditureEntity> expenditures, String purpose) {
|
||||
return expenditures.stream()
|
||||
.filter(item -> purpose.equals(item.getPurpose()))
|
||||
|
||||
+30
@@ -1,5 +1,8 @@
|
||||
package com.agileboot.domain.collaboration.record.enumtype;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
@@ -24,4 +27,31 @@ public enum SettlementStatusEnum {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public static String aggregate(Collection<String> statuses) {
|
||||
if (statuses == null || statuses.isEmpty()) {
|
||||
return NONE.value;
|
||||
}
|
||||
List<String> effectiveStatuses = statuses.stream()
|
||||
.filter(SettlementStatusEnum::isEffectiveStatus)
|
||||
.collect(Collectors.toList());
|
||||
if (effectiveStatuses.isEmpty()) {
|
||||
return NONE.value;
|
||||
}
|
||||
if (isSameStatus(effectiveStatuses, SETTLED)) {
|
||||
return SETTLED.value;
|
||||
}
|
||||
if (isSameStatus(effectiveStatuses, UNSETTLED)) {
|
||||
return UNSETTLED.value;
|
||||
}
|
||||
return PARTIAL.value;
|
||||
}
|
||||
|
||||
private static boolean isEffectiveStatus(String status) {
|
||||
return status != null && !NONE.value.equals(status);
|
||||
}
|
||||
|
||||
private static boolean isSameStatus(List<String> statuses, SettlementStatusEnum expected) {
|
||||
return statuses.stream().allMatch(status -> expected.value.equals(status));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public class CollaborationRecordModel extends CollaborationRecordEntity {
|
||||
if (command == null) {
|
||||
return;
|
||||
}
|
||||
BeanUtil.copyProperties(command, this, "recordId");
|
||||
BeanUtil.copyProperties(command, this, "recordId", "completeDate");
|
||||
loadDefaultValues();
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -23,6 +23,10 @@ public class CollaborationRecordQuery extends AbstractPageQuery<CollaborationRec
|
||||
|
||||
private String cooperationPlatform;
|
||||
|
||||
private String settlementStatus;
|
||||
|
||||
private String taskStatus;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||
private Date purchaseBeginTime;
|
||||
|
||||
|
||||
-8
@@ -4,8 +4,6 @@ import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.agileboot.infrastructure.cache.guava.AbstractGuavaCacheTemplate;
|
||||
import com.agileboot.infrastructure.cache.redis.RedisCacheTemplate;
|
||||
import com.agileboot.infrastructure.user.web.SystemLoginUser;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptEntity;
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.agileboot.domain.system.role.db.SysRoleEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import javax.annotation.PostConstruct;
|
||||
@@ -22,8 +20,6 @@ public class CacheCenter {
|
||||
|
||||
public static AbstractGuavaCacheTemplate<String> configCache;
|
||||
|
||||
public static AbstractGuavaCacheTemplate<SysDeptEntity> deptCache;
|
||||
|
||||
public static RedisCacheTemplate<String> captchaCache;
|
||||
|
||||
public static RedisCacheTemplate<SystemLoginUser> loginUserCache;
|
||||
@@ -32,21 +28,17 @@ public class CacheCenter {
|
||||
|
||||
public static RedisCacheTemplate<SysRoleEntity> roleCache;
|
||||
|
||||
public static RedisCacheTemplate<SysPostEntity> postCache;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
GuavaCacheService guavaCache = SpringUtil.getBean(GuavaCacheService.class);
|
||||
RedisCacheService redisCache = SpringUtil.getBean(RedisCacheService.class);
|
||||
|
||||
configCache = guavaCache.configCache;
|
||||
deptCache = guavaCache.deptCache;
|
||||
|
||||
captchaCache = redisCache.captchaCache;
|
||||
loginUserCache = redisCache.loginUserCache;
|
||||
userCache = redisCache.userCache;
|
||||
roleCache = redisCache.roleCache;
|
||||
postCache = redisCache.postCache;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Vendored
-12
@@ -2,9 +2,7 @@ package com.agileboot.domain.common.cache;
|
||||
|
||||
|
||||
import com.agileboot.infrastructure.cache.guava.AbstractGuavaCacheTemplate;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptEntity;
|
||||
import com.agileboot.domain.system.config.db.SysConfigService;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -19,8 +17,6 @@ public class GuavaCacheService {
|
||||
|
||||
private final SysConfigService configService;
|
||||
|
||||
private final SysDeptService deptService;
|
||||
|
||||
public final AbstractGuavaCacheTemplate<String> configCache = new AbstractGuavaCacheTemplate<String>() {
|
||||
@Override
|
||||
public String getObjectFromDb(Object id) {
|
||||
@@ -28,12 +24,4 @@ public class GuavaCacheService {
|
||||
}
|
||||
};
|
||||
|
||||
public final AbstractGuavaCacheTemplate<SysDeptEntity> deptCache = new AbstractGuavaCacheTemplate<SysDeptEntity>() {
|
||||
@Override
|
||||
public SysDeptEntity getObjectFromDb(Object id) {
|
||||
return deptService.getById(id.toString());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
Vendored
-14
@@ -5,10 +5,8 @@ import com.agileboot.infrastructure.cache.RedisUtil;
|
||||
import com.agileboot.infrastructure.cache.redis.CacheKeyEnum;
|
||||
import com.agileboot.infrastructure.cache.redis.RedisCacheTemplate;
|
||||
import com.agileboot.infrastructure.user.web.SystemLoginUser;
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.agileboot.domain.system.role.db.SysRoleEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import com.agileboot.domain.system.post.db.SysPostService;
|
||||
import com.agileboot.domain.system.role.db.SysRoleService;
|
||||
import com.agileboot.domain.system.user.db.SysUserService;
|
||||
import java.io.Serializable;
|
||||
@@ -30,8 +28,6 @@ public class RedisCacheService {
|
||||
public RedisCacheTemplate<SysUserEntity> userCache;
|
||||
public RedisCacheTemplate<SysRoleEntity> roleCache;
|
||||
|
||||
public RedisCacheTemplate<SysPostEntity> postCache;
|
||||
|
||||
// public RedisCacheTemplate<RoleInfo> roleModelInfoCache;
|
||||
|
||||
@PostConstruct
|
||||
@@ -66,16 +62,6 @@ public class RedisCacheService {
|
||||
//
|
||||
// };
|
||||
|
||||
postCache = new RedisCacheTemplate<SysPostEntity>(redisUtil, CacheKeyEnum.POST_ENTITY_KEY) {
|
||||
@Override
|
||||
public SysPostEntity getObjectFromDb(Object id) {
|
||||
SysPostService postService = SpringUtil.getBean(SysPostService.class);
|
||||
return postService.getById((Serializable) id);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
-1
@@ -14,6 +14,5 @@ public class TreeSelectedDTO {
|
||||
|
||||
private List<Long> checkedKeys;
|
||||
private List<Tree<Long>> menus;
|
||||
private List<Tree<Long>> depts;
|
||||
|
||||
}
|
||||
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
package com.agileboot.domain.system.dept;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import com.agileboot.domain.system.dept.command.AddDeptCommand;
|
||||
import com.agileboot.domain.system.dept.command.UpdateDeptCommand;
|
||||
import com.agileboot.domain.system.dept.dto.DeptDTO;
|
||||
import com.agileboot.domain.system.dept.model.DeptModel;
|
||||
import com.agileboot.domain.system.dept.model.DeptModelFactory;
|
||||
import com.agileboot.domain.system.dept.query.DeptQuery;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptEntity;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptService;
|
||||
import com.agileboot.domain.system.role.db.SysRoleService;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 部门服务
|
||||
* @author valarchie
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeptApplicationService {
|
||||
|
||||
private final SysDeptService deptService;
|
||||
|
||||
private final SysRoleService roleService;
|
||||
|
||||
private final DeptModelFactory deptModelFactory;
|
||||
|
||||
|
||||
public List<DeptDTO> getDeptList(DeptQuery query) {
|
||||
List<SysDeptEntity> list = deptService.list(query.toQueryWrapper());
|
||||
return list.stream().map(DeptDTO::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public DeptDTO getDeptInfo(Long id) {
|
||||
SysDeptEntity byId = deptService.getById(id);
|
||||
return new DeptDTO(byId);
|
||||
}
|
||||
|
||||
public List<Tree<Long>> getDeptTree() {
|
||||
List<SysDeptEntity> list = deptService.list();
|
||||
|
||||
return TreeUtil.build(list, 0L, (dept, tree) -> {
|
||||
tree.setId(dept.getDeptId());
|
||||
tree.setParentId(dept.getParentId());
|
||||
tree.putExtra("label", dept.getDeptName());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void addDept(AddDeptCommand addCommand) {
|
||||
DeptModel deptModel = deptModelFactory.create();
|
||||
deptModel.loadAddCommand(addCommand);
|
||||
|
||||
deptModel.checkDeptNameUnique();
|
||||
deptModel.generateAncestors();
|
||||
|
||||
deptModel.insert();
|
||||
}
|
||||
|
||||
public void updateDept(UpdateDeptCommand updateCommand) {
|
||||
DeptModel deptModel = deptModelFactory.loadById(updateCommand.getDeptId());
|
||||
deptModel.loadUpdateCommand(updateCommand);
|
||||
|
||||
deptModel.checkDeptNameUnique();
|
||||
deptModel.checkParentIdConflict();
|
||||
deptModel.checkStatusAllowChange();
|
||||
deptModel.generateAncestors();
|
||||
|
||||
deptModel.updateById();
|
||||
}
|
||||
|
||||
public void removeDept(Long deptId) {
|
||||
DeptModel deptModel = deptModelFactory.loadById(deptId);
|
||||
|
||||
deptModel.checkHasChildDept();
|
||||
deptModel.checkDeptAssignedToUsers();
|
||||
|
||||
deptModel.deleteById();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
package com.agileboot.domain.system.dept.command;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.PositiveOrZero;
|
||||
import javax.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@Data
|
||||
public class AddDeptCommand {
|
||||
|
||||
/**
|
||||
* 父部门ID
|
||||
*/
|
||||
@NotNull
|
||||
@PositiveOrZero
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
@NotBlank(message = "部门名称不能为空")
|
||||
@Size(max = 30, message = "部门名称长度不能超过30个字符")
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 显示顺序
|
||||
*/
|
||||
@NotNull(message = "显示顺序不能为空")
|
||||
private Integer orderNum;
|
||||
|
||||
/**
|
||||
* 负责人
|
||||
*/
|
||||
private String leaderName;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
@Size(max = 11, message = "联系电话长度不能超过11个字符")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@Email(message = "邮箱格式不正确")
|
||||
@Size(max = 50, message = "邮箱长度不能超过50个字符")
|
||||
private String email;
|
||||
|
||||
|
||||
private Integer status;
|
||||
|
||||
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package com.agileboot.domain.system.dept.command;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.PositiveOrZero;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class UpdateDeptCommand extends AddDeptCommand {
|
||||
|
||||
@NotNull
|
||||
@PositiveOrZero
|
||||
private Long deptId;
|
||||
|
||||
}
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
package com.agileboot.domain.system.dept.db;
|
||||
|
||||
import com.agileboot.common.core.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.io.Serializable;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门表
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2022-10-02
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("sys_dept")
|
||||
@ApiModel(value = "SysDeptEntity对象", description = "部门表")
|
||||
public class SysDeptEntity extends BaseEntity<SysDeptEntity> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("部门id")
|
||||
@TableId(value = "dept_id", type = IdType.AUTO)
|
||||
private Long deptId;
|
||||
|
||||
@ApiModelProperty("父部门id")
|
||||
@TableField("parent_id")
|
||||
private Long parentId;
|
||||
|
||||
@ApiModelProperty("祖级列表")
|
||||
@TableField("ancestors")
|
||||
private String ancestors;
|
||||
|
||||
@ApiModelProperty("部门名称")
|
||||
@TableField("dept_name")
|
||||
private String deptName;
|
||||
|
||||
@ApiModelProperty("显示顺序")
|
||||
@TableField("order_num")
|
||||
private Integer orderNum;
|
||||
|
||||
@TableField("leader_id")
|
||||
private Long leaderId;
|
||||
|
||||
@ApiModelProperty("负责人")
|
||||
@TableField("leader_name")
|
||||
private String leaderName;
|
||||
|
||||
@ApiModelProperty("联系电话")
|
||||
@TableField("phone")
|
||||
private String phone;
|
||||
|
||||
@ApiModelProperty("邮箱")
|
||||
@TableField("email")
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty("部门状态(0正常 1停用)")
|
||||
@TableField("`status`")
|
||||
private Integer status;
|
||||
|
||||
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
return this.deptId;
|
||||
}
|
||||
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package com.agileboot.domain.system.dept.db;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2022-06-16
|
||||
*/
|
||||
public interface SysDeptMapper extends BaseMapper<SysDeptEntity> {
|
||||
|
||||
}
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
package com.agileboot.domain.system.dept.db;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2022-06-16
|
||||
*/
|
||||
public interface SysDeptService extends IService<SysDeptEntity> {
|
||||
|
||||
|
||||
/**
|
||||
* 检测部门名称是否一致
|
||||
*
|
||||
* @param deptName 部门名称
|
||||
* @param deptId 部门id
|
||||
* @param parentId 父级部门id
|
||||
* @return 校验结果
|
||||
*/
|
||||
boolean isDeptNameDuplicated(String deptName, Long deptId, Long parentId);
|
||||
|
||||
/**
|
||||
* 检测部门底下是否还有正在使用中的子部门
|
||||
* @param deptId 部门id
|
||||
* @param enabled 部门是否开启
|
||||
* @return 结果
|
||||
*/
|
||||
boolean hasChildrenDept(Long deptId, Boolean enabled);
|
||||
|
||||
/**
|
||||
* 是否是目标部门的子部门
|
||||
* @param parentId 目标部门id
|
||||
* @param childId 子部门id
|
||||
* @return 校验结果
|
||||
*/
|
||||
boolean isChildOfTheDept(Long parentId, Long childId);
|
||||
|
||||
/**
|
||||
* 检测该部门是否已有用户使用
|
||||
* @param deptId 部门id
|
||||
* @return 校验结果
|
||||
*/
|
||||
boolean isDeptAssignedToUsers(Long deptId);
|
||||
|
||||
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
package com.agileboot.domain.system.dept.db;
|
||||
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2022-06-16
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDeptEntity> implements SysDeptService {
|
||||
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isDeptNameDuplicated(String deptName, Long deptId, Long parentId) {
|
||||
QueryWrapper<SysDeptEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("dept_name", deptName)
|
||||
.ne(deptId != null, "dept_id", deptId)
|
||||
.eq(parentId != null, "parent_id", parentId);
|
||||
|
||||
return this.baseMapper.exists(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasChildrenDept(Long deptId, Boolean enabled) {
|
||||
QueryWrapper<SysDeptEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(enabled != null, "status", 1)
|
||||
.and(o -> o.eq("parent_id", deptId).or()
|
||||
.apply("FIND_IN_SET (" + deptId + " , ancestors)")
|
||||
);
|
||||
return this.baseMapper.exists(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isChildOfTheDept(Long parentId, Long childId) {
|
||||
QueryWrapper<SysDeptEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.apply("dept_id = '" + childId + "' and FIND_IN_SET ( " + parentId + " , ancestors)");
|
||||
return this.baseMapper.exists(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isDeptAssignedToUsers(Long deptId) {
|
||||
QueryWrapper<SysUserEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("dept_id", deptId);
|
||||
return userMapper.exists(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
-51
@@ -1,51 +0,0 @@
|
||||
package com.agileboot.domain.system.dept.dto;
|
||||
|
||||
import com.agileboot.common.enums.common.StatusEnum;
|
||||
import com.agileboot.common.enums.BasicEnumUtil;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptEntity;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@Data
|
||||
public class DeptDTO {
|
||||
|
||||
public DeptDTO(SysDeptEntity entity) {
|
||||
if (entity != null) {
|
||||
this.id = entity.getDeptId();
|
||||
this.parentId = entity.getParentId();
|
||||
this.deptName = entity.getDeptName();
|
||||
this.orderNum = entity.getOrderNum();
|
||||
this.leaderName = entity.getLeaderName();
|
||||
this.email = entity.getEmail();
|
||||
this.phone = entity.getPhone();
|
||||
this.status = entity.getStatus();
|
||||
this.createTime = entity.getCreateTime();
|
||||
this.statusStr = BasicEnumUtil.getDescriptionByValue(StatusEnum.class, entity.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Long id;
|
||||
|
||||
private Long parentId;
|
||||
|
||||
private String deptName;
|
||||
|
||||
private Integer orderNum;
|
||||
|
||||
private String leaderName;
|
||||
|
||||
private String phone;
|
||||
|
||||
private String email;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private String statusStr;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
-106
@@ -1,106 +0,0 @@
|
||||
package com.agileboot.domain.system.dept.model;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.system.dept.command.AddDeptCommand;
|
||||
import com.agileboot.domain.system.dept.command.UpdateDeptCommand;
|
||||
import com.agileboot.common.enums.common.StatusEnum;
|
||||
import com.agileboot.common.enums.BasicEnumUtil;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptEntity;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptService;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
public class DeptModel extends SysDeptEntity {
|
||||
|
||||
private final SysDeptService deptService;
|
||||
|
||||
public DeptModel(SysDeptService deptService) {
|
||||
this.deptService = deptService;
|
||||
}
|
||||
|
||||
public DeptModel(SysDeptEntity entity, SysDeptService deptService) {
|
||||
if (entity != null) {
|
||||
// 如果大数据量的话 可以用MapStruct优化
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
}
|
||||
this.deptService = deptService;
|
||||
}
|
||||
|
||||
public void loadAddCommand(AddDeptCommand addCommand) {
|
||||
this.setParentId(addCommand.getParentId());
|
||||
this.setDeptName(addCommand.getDeptName());
|
||||
this.setOrderNum(addCommand.getOrderNum());
|
||||
this.setLeaderName(addCommand.getLeaderName());
|
||||
this.setPhone(addCommand.getPhone());
|
||||
this.setEmail(addCommand.getEmail());
|
||||
this.setStatus(addCommand.getStatus());
|
||||
}
|
||||
|
||||
public void loadUpdateCommand(UpdateDeptCommand updateCommand) {
|
||||
loadAddCommand(updateCommand);
|
||||
setStatus(Convert.toInt(updateCommand.getStatus(), 0));
|
||||
}
|
||||
|
||||
public void checkDeptNameUnique() {
|
||||
if (deptService.isDeptNameDuplicated(getDeptName(), getDeptId(), getParentId())) {
|
||||
throw new ApiException(ErrorCode.Business.DEPT_NAME_IS_NOT_UNIQUE, getDeptName());
|
||||
}
|
||||
}
|
||||
|
||||
public void checkParentIdConflict() {
|
||||
if (Objects.equals(getParentId(), getDeptId())) {
|
||||
throw new ApiException(ErrorCode.Business.DEPT_PARENT_ID_IS_NOT_ALLOWED_SELF);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkHasChildDept() {
|
||||
if (deptService.hasChildrenDept(getDeptId(), null)) {
|
||||
throw new ApiException(ErrorCode.Business.DEPT_EXIST_CHILD_DEPT_NOT_ALLOW_DELETE);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkDeptAssignedToUsers() {
|
||||
if (deptService.isDeptAssignedToUsers(getDeptId())) {
|
||||
throw new ApiException(ErrorCode.Business.DEPT_EXIST_LINK_USER_NOT_ALLOW_DELETE);
|
||||
}
|
||||
}
|
||||
|
||||
public void generateAncestors() {
|
||||
|
||||
// 处理 getParentId 可能为 null 的情况
|
||||
if (getParentId() == null || getParentId() == 0) {
|
||||
setAncestors(String.valueOf(getParentId() == null ? 0 : getParentId()));
|
||||
return;
|
||||
}
|
||||
|
||||
SysDeptEntity parentDept = deptService.getById(getParentId());
|
||||
|
||||
// 检查 parentDept 是否为 null 或者状态为禁用
|
||||
if (parentDept == null || StatusEnum.DISABLE.equals(
|
||||
BasicEnumUtil.fromValue(StatusEnum.class, parentDept.getStatus()))) {
|
||||
throw new ApiException(ErrorCode.Business.DEPT_PARENT_DEPT_NO_EXIST_OR_DISABLED);
|
||||
}
|
||||
|
||||
// 处理 parentDept.getAncestors() 可能为 null 的情况
|
||||
String ancestors = parentDept.getAncestors() == null ? "" : parentDept.getAncestors();
|
||||
setAncestors(ancestors + "," + getParentId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DDD 有些阻抗 如果为了追求性能的话 还是得通过 数据库的方式来判断
|
||||
*/
|
||||
public void checkStatusAllowChange() {
|
||||
if (StatusEnum.DISABLE.getValue().equals(getStatus()) &&
|
||||
deptService.hasChildrenDept(getDeptId(), true)) {
|
||||
throw new ApiException(ErrorCode.Business.DEPT_STATUS_ID_IS_NOT_ALLOWED_CHANGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package com.agileboot.domain.system.dept.model;
|
||||
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.system.dept.command.AddDeptCommand;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptEntity;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 部门模型工厂
|
||||
* @author valarchie
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class DeptModelFactory {
|
||||
|
||||
private final SysDeptService deptService;
|
||||
|
||||
public DeptModel loadById(Long deptId) {
|
||||
SysDeptEntity byId = deptService.getById(deptId);
|
||||
if (byId == null) {
|
||||
throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, deptId, "部门");
|
||||
}
|
||||
return new DeptModel(byId, deptService);
|
||||
}
|
||||
|
||||
public DeptModel create() {
|
||||
return new DeptModel(deptService);
|
||||
}
|
||||
|
||||
public DeptModel loadFromAddCommand(AddDeptCommand addCommand, DeptModel model) {
|
||||
model.setParentId(addCommand.getParentId());
|
||||
model.setDeptName(addCommand.getDeptName());
|
||||
model.setOrderNum(addCommand.getOrderNum());
|
||||
model.setLeaderName(addCommand.getLeaderName());
|
||||
model.setPhone(addCommand.getPhone());
|
||||
model.setEmail(addCommand.getEmail());
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.agileboot.domain.system.dept.query;
|
||||
|
||||
import com.agileboot.common.core.page.AbstractQuery;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptEntity;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class DeptQuery extends AbstractQuery<SysDeptEntity> {
|
||||
|
||||
private Long deptId;
|
||||
|
||||
private Long parentId;
|
||||
|
||||
|
||||
@Override
|
||||
public QueryWrapper<SysDeptEntity> addQueryCondition() {
|
||||
// TODO parentId 这个似乎没使用
|
||||
return new QueryWrapper<SysDeptEntity>()
|
||||
// .eq(status != null, "status", status)
|
||||
.eq(parentId != null, "parent_id", parentId);
|
||||
// .like(StrUtil.isNotEmpty(deptName), "dept_name", deptName);
|
||||
// .and(deptId != null && isExcludeCurrentDept, o ->
|
||||
// o.ne("dept_id", deptId)
|
||||
// .or()
|
||||
// .apply("FIND_IN_SET (dept_id , ancestors)")
|
||||
// );
|
||||
}
|
||||
}
|
||||
-8
@@ -73,14 +73,6 @@ public class SysOperationLogEntity extends Model<SysOperationLogEntity> {
|
||||
@TableField("operator_location")
|
||||
private String operatorLocation;
|
||||
|
||||
@ApiModelProperty("部门ID")
|
||||
@TableField("dept_id")
|
||||
private Long deptId;
|
||||
|
||||
@ApiModelProperty("部门名称")
|
||||
@TableField("dept_name")
|
||||
private String deptName;
|
||||
|
||||
@ApiModelProperty("请求参数")
|
||||
@TableField("operation_param")
|
||||
private String operationParam;
|
||||
|
||||
-6
@@ -69,12 +69,6 @@ public class OperationLogDTO {
|
||||
@ExcelColumn(name = "ip地点")
|
||||
private String operatorLocation;
|
||||
|
||||
@ExcelColumn(name = "部门ID")
|
||||
private Long deptId;
|
||||
|
||||
@ExcelColumn(name = "部门")
|
||||
private String deptName;
|
||||
|
||||
@ExcelColumn(name = "操作参数")
|
||||
private String operationParam;
|
||||
|
||||
|
||||
+2
-2
@@ -105,7 +105,7 @@ public class MenuApplicationService {
|
||||
//默认为id可以不设置
|
||||
config.setIdKey("menuId");
|
||||
return TreeUtil.build(menus, 0L, config, (menu, tree) -> {
|
||||
// 也可以使用 tree.setId(dept.getId());等一些默认值
|
||||
// 也可以使用 tree.setId(menu.getId());等一些默认值
|
||||
tree.setId(menu.getMenuId());
|
||||
tree.setParentId(menu.getParentId());
|
||||
tree.putExtra("label", menu.getMenuName());
|
||||
@@ -132,7 +132,7 @@ public class MenuApplicationService {
|
||||
config.setIdKey("menuId");
|
||||
|
||||
return TreeUtil.build(noButtonMenus, 0L, config, (menu, tree) -> {
|
||||
// 也可以使用 tree.setId(dept.getId());等一些默认值
|
||||
// 也可以使用 tree.setId(menu.getId());等一些默认值
|
||||
tree.setId(menu.getMenuId());
|
||||
tree.setParentId(menu.getParentId());
|
||||
// TODO 可以取meta中的rank来排序
|
||||
|
||||
-13
@@ -1,8 +1,6 @@
|
||||
package com.agileboot.domain.system.monitor.dto;
|
||||
|
||||
import com.agileboot.domain.common.cache.CacheCenter;
|
||||
import com.agileboot.infrastructure.user.web.SystemLoginUser;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -18,11 +16,6 @@ public class OnlineUserDTO {
|
||||
*/
|
||||
private String tokenId;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
@@ -66,12 +59,6 @@ public class OnlineUserDTO {
|
||||
this.browser = user.getLoginInfo().getBrowser();
|
||||
this.operationSystem = user.getLoginInfo().getOperationSystem();
|
||||
this.loginTime = user.getLoginInfo().getLoginTime();
|
||||
|
||||
SysDeptEntity deptEntity = CacheCenter.deptCache.get(user.getDeptId() + "");
|
||||
|
||||
if (deptEntity != null) {
|
||||
this.deptName = deptEntity.getDeptName();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-85
@@ -1,85 +0,0 @@
|
||||
package com.agileboot.domain.system.post;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.system.post.command.AddPostCommand;
|
||||
import com.agileboot.domain.system.post.command.UpdatePostCommand;
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.agileboot.domain.system.post.db.SysPostService;
|
||||
import com.agileboot.domain.system.post.dto.PostDTO;
|
||||
import com.agileboot.domain.system.post.model.PostModel;
|
||||
import com.agileboot.domain.system.post.model.PostModelFactory;
|
||||
import com.agileboot.domain.system.post.query.PostQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PostApplicationService {
|
||||
|
||||
private final PostModelFactory postModelFactory;
|
||||
|
||||
private final SysPostService postService;
|
||||
|
||||
public PageDTO<PostDTO> getPostList(PostQuery query) {
|
||||
Page<SysPostEntity> page = postService.page(query.toPage(), query.toQueryWrapper());
|
||||
List<PostDTO> records = page.getRecords().stream().map(PostDTO::new).collect(Collectors.toList());
|
||||
return new PageDTO<>(records, page.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询满足条件的所有岗位,不分页
|
||||
* @param query 查询条件
|
||||
* @return 满足查询条件的岗位列表
|
||||
* @author Kevin Zhang
|
||||
* @date 2023-10-02
|
||||
*/
|
||||
public List<PostDTO> getPostListAll(PostQuery query) {
|
||||
List<SysPostEntity> all = postService.list(query.toQueryWrapper());
|
||||
List<PostDTO> records = all.stream().map(PostDTO::new).collect(Collectors.toList());
|
||||
return records;
|
||||
}
|
||||
|
||||
public PostDTO getPostInfo(Long postId) {
|
||||
SysPostEntity byId = postService.getById(postId);
|
||||
return new PostDTO(byId);
|
||||
}
|
||||
|
||||
public void addPost(AddPostCommand addCommand) {
|
||||
PostModel postModel = postModelFactory.create();
|
||||
postModel.loadFromAddCommand(addCommand);
|
||||
|
||||
postModel.checkPostNameUnique();
|
||||
postModel.checkPostCodeUnique();
|
||||
|
||||
postModel.insert();
|
||||
}
|
||||
|
||||
public void updatePost(UpdatePostCommand updateCommand) {
|
||||
PostModel postModel = postModelFactory.loadById(updateCommand.getPostId());
|
||||
postModel.loadFromUpdateCommand(updateCommand);
|
||||
|
||||
postModel.checkPostNameUnique();
|
||||
postModel.checkPostCodeUnique();
|
||||
|
||||
postModel.updateById();
|
||||
}
|
||||
|
||||
|
||||
public void deletePost(BulkOperationCommand<Long> deleteCommand) {
|
||||
for (Long id : deleteCommand.getIds()) {
|
||||
PostModel postModel = postModelFactory.loadById(id);
|
||||
postModel.checkCanBeDelete();
|
||||
}
|
||||
|
||||
postService.removeBatchByIds(deleteCommand.getIds());
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.agileboot.domain.system.post.command;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.PositiveOrZero;
|
||||
import javax.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@Data
|
||||
public class AddPostCommand {
|
||||
|
||||
@NotBlank(message = "岗位编码不能为空")
|
||||
@Size(max = 64, message = "岗位编码长度不能超过64个字符")
|
||||
protected String postCode;
|
||||
|
||||
/**
|
||||
* 岗位名称
|
||||
*/
|
||||
@NotBlank(message = "岗位名称不能为空")
|
||||
@Size(max = 64, message = "岗位名称长度不能超过64个字符")
|
||||
protected String postName;
|
||||
|
||||
/**
|
||||
* 岗位排序
|
||||
*/
|
||||
@NotNull(message = "显示顺序不能为空")
|
||||
protected Integer postSort;
|
||||
|
||||
protected String remark;
|
||||
|
||||
@PositiveOrZero
|
||||
protected String status;
|
||||
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package com.agileboot.domain.system.post.command;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Positive;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class UpdatePostCommand extends AddPostCommand {
|
||||
|
||||
@NotNull(message = "岗位ID不能为空")
|
||||
@Positive
|
||||
private Long postId;
|
||||
|
||||
}
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
package com.agileboot.domain.system.post.db;
|
||||
|
||||
import com.agileboot.common.core.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.io.Serializable;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 岗位信息表
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2022-10-02
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("sys_post")
|
||||
@ApiModel(value = "SysPostEntity对象", description = "岗位信息表")
|
||||
public class SysPostEntity extends BaseEntity<SysPostEntity> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("岗位ID")
|
||||
@TableId(value = "post_id", type = IdType.AUTO)
|
||||
private Long postId;
|
||||
|
||||
@ApiModelProperty("岗位编码")
|
||||
@TableField("post_code")
|
||||
private String postCode;
|
||||
|
||||
@ApiModelProperty("岗位名称")
|
||||
@TableField("post_name")
|
||||
private String postName;
|
||||
|
||||
@ApiModelProperty("显示顺序")
|
||||
@TableField("post_sort")
|
||||
private Integer postSort;
|
||||
|
||||
@ApiModelProperty("状态(1正常 0停用)")
|
||||
@TableField("`status`")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty("备注")
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
return this.postId;
|
||||
}
|
||||
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package com.agileboot.domain.system.post.db;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 岗位信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2022-06-16
|
||||
*/
|
||||
public interface SysPostMapper extends BaseMapper<SysPostEntity> {
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.agileboot.domain.system.post.db;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 岗位信息表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2022-06-16
|
||||
*/
|
||||
public interface SysPostService extends IService<SysPostEntity> {
|
||||
|
||||
/**
|
||||
* 校验岗位名称
|
||||
* @param postId 职位Id
|
||||
* @param postName 职位名称
|
||||
* @return 结果
|
||||
*/
|
||||
boolean isPostNameDuplicated(Long postId, String postName);
|
||||
|
||||
/**
|
||||
* 校验岗位编码
|
||||
* @param postId 职位id
|
||||
* @param postCode 职位代码
|
||||
* @return 结果
|
||||
*/
|
||||
boolean isPostCodeDuplicated(Long postId, String postCode);
|
||||
|
||||
|
||||
/**
|
||||
* 检测职位是否分配给用户
|
||||
*
|
||||
* @param postId 职位id
|
||||
* @return 校验结果
|
||||
*/
|
||||
boolean isAssignedToUsers(Long postId);
|
||||
|
||||
}
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
package com.agileboot.domain.system.post.db;
|
||||
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 岗位信息表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2022-06-16
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPostEntity> implements SysPostService {
|
||||
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 校验岗位名称是否唯一
|
||||
*
|
||||
* @param postName 岗位名称
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean isPostNameDuplicated(Long postId, String postName) {
|
||||
QueryWrapper<SysPostEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.ne(postId != null, "post_id", postId)
|
||||
.eq("post_name", postName);
|
||||
return baseMapper.exists(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPostCodeDuplicated(Long postId, String postCode) {
|
||||
QueryWrapper<SysPostEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.ne(postId != null, "post_id", postId)
|
||||
.eq("post_code", postCode);
|
||||
return baseMapper.exists(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAssignedToUsers(Long postId) {
|
||||
QueryWrapper<SysUserEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("post_id", postId);
|
||||
return userMapper.exists(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
package com.agileboot.domain.system.post.dto;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.agileboot.common.annotation.ExcelColumn;
|
||||
import com.agileboot.common.enums.common.StatusEnum;
|
||||
import com.agileboot.common.enums.BasicEnumUtil;
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import java.util.Date;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class PostDTO {
|
||||
|
||||
public PostDTO(SysPostEntity entity) {
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
statusStr = BasicEnumUtil.getDescriptionByValue(StatusEnum.class, entity.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
@ExcelColumn(name = "岗位ID")
|
||||
private Long postId;
|
||||
|
||||
|
||||
@ExcelColumn(name = "岗位编码")
|
||||
private String postCode;
|
||||
|
||||
@ExcelColumn(name = "岗位名称")
|
||||
private String postName;
|
||||
|
||||
|
||||
@ExcelColumn(name = "岗位排序")
|
||||
private Integer postSort;
|
||||
|
||||
@ExcelColumn(name = "备注")
|
||||
private String remark;
|
||||
|
||||
private Integer status;
|
||||
|
||||
@ExcelColumn(name = "状态")
|
||||
private String statusStr;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
package com.agileboot.domain.system.post.model;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.system.post.command.AddPostCommand;
|
||||
import com.agileboot.domain.system.post.command.UpdatePostCommand;
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.agileboot.domain.system.post.db.SysPostService;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class PostModel extends SysPostEntity {
|
||||
|
||||
private SysPostService postService;
|
||||
|
||||
public PostModel(SysPostService postService) {
|
||||
this.postService = postService;
|
||||
}
|
||||
|
||||
public PostModel(SysPostEntity entity, SysPostService postService) {
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
}
|
||||
this.postService = postService;
|
||||
}
|
||||
|
||||
public void loadFromAddCommand(AddPostCommand addCommand) {
|
||||
if (addCommand != null) {
|
||||
BeanUtil.copyProperties(addCommand, this, "postId");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void loadFromUpdateCommand(UpdatePostCommand command) {
|
||||
if (command != null) {
|
||||
loadFromAddCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void checkCanBeDelete() {
|
||||
if (postService.isAssignedToUsers(this.getPostId())) {
|
||||
throw new ApiException(ErrorCode.Business.POST_ALREADY_ASSIGNED_TO_USER_CAN_NOT_BE_DELETED);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkPostNameUnique() {
|
||||
if (postService.isPostNameDuplicated(getPostId(), getPostName())) {
|
||||
throw new ApiException(ErrorCode.Business.POST_NAME_IS_NOT_UNIQUE, getPostName());
|
||||
}
|
||||
}
|
||||
|
||||
public void checkPostCodeUnique() {
|
||||
if (postService.isPostCodeDuplicated(getPostId(), getPostCode())) {
|
||||
throw new ApiException(ErrorCode.Business.POST_CODE_IS_NOT_UNIQUE, getPostCode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.agileboot.domain.system.post.model;
|
||||
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode.Business;
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.agileboot.domain.system.post.db.SysPostService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class PostModelFactory {
|
||||
|
||||
private final SysPostService postService;
|
||||
|
||||
public PostModel loadById(Long postId) {
|
||||
SysPostEntity byId = postService.getById(postId);
|
||||
if (byId == null) {
|
||||
throw new ApiException(Business.COMMON_OBJECT_NOT_FOUND, postId, "职位");
|
||||
}
|
||||
return new PostModel(byId, postService);
|
||||
}
|
||||
|
||||
public PostModel create() {
|
||||
return new PostModel(postService);
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package com.agileboot.domain.system.post.query;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class PostQuery extends AbstractPageQuery<SysPostEntity> {
|
||||
|
||||
private String postCode;
|
||||
private String postName;
|
||||
private Integer status;
|
||||
|
||||
@Override
|
||||
public QueryWrapper<SysPostEntity> addQueryCondition() {
|
||||
QueryWrapper<SysPostEntity> queryWrapper = new QueryWrapper<SysPostEntity>()
|
||||
.eq(status != null, "status", status)
|
||||
.eq(StrUtil.isNotEmpty(postCode), "post_code", postCode)
|
||||
.like(StrUtil.isNotEmpty(postName), "post_name", postName);
|
||||
// 当前端没有选择排序字段时,则使用post_sort字段升序排序(在父类AbstractQuery中默认为升序)
|
||||
if (StrUtil.isEmpty(this.getOrderColumn())) {
|
||||
this.setOrderColumn("post_sort");
|
||||
}
|
||||
this.setTimeRangeColumn("create_time");
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
||||
-16
@@ -1,11 +1,9 @@
|
||||
package com.agileboot.domain.system.role;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.domain.common.cache.CacheCenter;
|
||||
import com.agileboot.domain.system.role.command.AddRoleCommand;
|
||||
import com.agileboot.domain.system.role.command.UpdateDataScopeCommand;
|
||||
import com.agileboot.domain.system.role.command.UpdateRoleCommand;
|
||||
import com.agileboot.domain.system.role.command.UpdateStatusCommand;
|
||||
import com.agileboot.domain.system.role.dto.RoleDTO;
|
||||
@@ -56,9 +54,6 @@ public class RoleApplicationService {
|
||||
public RoleDTO getRoleInfo(Long roleId) {
|
||||
SysRoleEntity byId = roleService.getById(roleId);
|
||||
RoleDTO roleDTO = new RoleDTO(byId);
|
||||
List<Long> selectedDeptList = StrUtil.split(byId.getDeptIdSet(), ",")
|
||||
.stream().filter(StrUtil::isNotEmpty).map(Long::new).collect(Collectors.toList());
|
||||
roleDTO.setSelectedDeptList(selectedDeptList);
|
||||
roleDTO.setSelectedMenuList(menuService.getMenuIdsByRoleId(roleId));
|
||||
return roleDTO;
|
||||
}
|
||||
@@ -105,17 +100,6 @@ public class RoleApplicationService {
|
||||
roleModel.updateById();
|
||||
}
|
||||
|
||||
public void updateDataScope(UpdateDataScopeCommand command) {
|
||||
RoleModel roleModel = roleModelFactory.loadById(command.getRoleId());
|
||||
|
||||
roleModel.setDeptIds(command.getDeptIds());
|
||||
roleModel.setDataScope(command.getDataScope());
|
||||
roleModel.generateDeptIdSet();
|
||||
|
||||
roleModel.updateById();
|
||||
}
|
||||
|
||||
|
||||
public PageDTO<UserDTO> getAllocatedUserList(AllocatedRoleQuery query) {
|
||||
Page<SysUserEntity> page = userService.getUserListByRole(query);
|
||||
List<UserDTO> dtoList = page.getRecords().stream().map(UserDTO::new).collect(Collectors.toList());
|
||||
|
||||
-1
@@ -40,7 +40,6 @@ public class AddRoleCommand {
|
||||
private String remark;
|
||||
|
||||
|
||||
@ExcelColumn(name = "数据范围")
|
||||
private String dataScope;
|
||||
|
||||
@PositiveOrZero
|
||||
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package com.agileboot.domain.system.role.command;
|
||||
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Positive;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@Data
|
||||
public class UpdateDataScopeCommand {
|
||||
|
||||
@NotNull
|
||||
@Positive
|
||||
private Long roleId;
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private List<Long> deptIds;
|
||||
|
||||
private Integer dataScope;
|
||||
|
||||
|
||||
}
|
||||
+1
-5
@@ -43,14 +43,10 @@ public class SysRoleEntity extends BaseEntity<SysRoleEntity> {
|
||||
@TableField("role_sort")
|
||||
private Integer roleSort;
|
||||
|
||||
@ApiModelProperty("数据范围(1:全部数据权限 2:自定数据权限 3: 本部门数据权限 4: 本部门及以下数据权限 5: 本人权限)")
|
||||
@ApiModelProperty("数据范围(1:全部数据权限 5: 本人权限)")
|
||||
@TableField("data_scope")
|
||||
private Integer dataScope;
|
||||
|
||||
@ApiModelProperty("角色所拥有的部门数据权限")
|
||||
@TableField("dept_id_set")
|
||||
private String deptIdSet;
|
||||
|
||||
@ApiModelProperty("角色状态(1正常 0停用)")
|
||||
@TableField("`status`")
|
||||
private Integer status;
|
||||
|
||||
+7
@@ -32,6 +32,13 @@ public interface SysRoleService extends IService<SysRoleEntity> {
|
||||
*/
|
||||
boolean isRoleKeyDuplicated(Long roleId, String roleKey);
|
||||
|
||||
/**
|
||||
* 根据角色标识获取可用角色
|
||||
* @param roleKey 角色标识
|
||||
* @return 角色信息
|
||||
*/
|
||||
SysRoleEntity getEnabledRoleByKey(String roleKey);
|
||||
|
||||
|
||||
/**
|
||||
* 检测角色是否分配给用户
|
||||
|
||||
+9
@@ -3,6 +3,7 @@ package com.agileboot.domain.system.role.db;
|
||||
import com.agileboot.domain.system.menu.db.SysMenuEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserMapper;
|
||||
import com.agileboot.common.enums.common.StatusEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import java.util.List;
|
||||
@@ -39,6 +40,14 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRoleEntity
|
||||
return this.baseMapper.exists(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysRoleEntity getEnabledRoleByKey(String roleKey) {
|
||||
QueryWrapper<SysRoleEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("role_key", roleKey)
|
||||
.eq("status", StatusEnum.ENABLE.getValue());
|
||||
return getOne(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignedToUsers(Long roleId) {
|
||||
QueryWrapper<SysUserEntity> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
-2
@@ -45,6 +45,4 @@ public class RoleDTO {
|
||||
private Integer dataScope;
|
||||
|
||||
private List<Long> selectedMenuList;
|
||||
|
||||
private List<Long> selectedDeptList;
|
||||
}
|
||||
|
||||
+5
-17
@@ -1,10 +1,10 @@
|
||||
package com.agileboot.domain.system.role.model;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.common.exception.error.ErrorCode.Business;
|
||||
import com.agileboot.infrastructure.user.web.DataScopeEnum;
|
||||
import com.agileboot.domain.system.role.command.AddRoleCommand;
|
||||
import com.agileboot.domain.system.role.command.UpdateRoleCommand;
|
||||
import com.agileboot.common.enums.common.StatusEnum;
|
||||
@@ -14,7 +14,6 @@ import com.agileboot.domain.system.role.db.SysRoleMenuService;
|
||||
import com.agileboot.domain.system.role.db.SysRoleService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -30,8 +29,6 @@ public class RoleModel extends SysRoleEntity {
|
||||
|
||||
private List<Long> menuIds;
|
||||
|
||||
private List<Long> deptIds;
|
||||
|
||||
private SysRoleService roleService;
|
||||
private SysRoleMenuService roleMenuService;
|
||||
|
||||
@@ -51,6 +48,7 @@ public class RoleModel extends SysRoleEntity {
|
||||
public void loadAddCommand(AddRoleCommand command) {
|
||||
if (command != null) {
|
||||
BeanUtil.copyProperties(command, this, "roleId");
|
||||
fillDefaultDataScope();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,22 +82,12 @@ public class RoleModel extends SysRoleEntity {
|
||||
}
|
||||
}
|
||||
|
||||
public void generateDeptIdSet() {
|
||||
if (deptIds == null) {
|
||||
setDeptIdSet("");
|
||||
return;
|
||||
private void fillDefaultDataScope() {
|
||||
if (getDataScope() == null) {
|
||||
setDataScope(DataScopeEnum.ONLY_SELF.getValue());
|
||||
}
|
||||
|
||||
if (deptIds.size() > new HashSet<>(deptIds).size()) {
|
||||
throw new ApiException(ErrorCode.Business.ROLE_DATA_SCOPE_DUPLICATED_DEPT);
|
||||
}
|
||||
|
||||
String deptIdSet = StrUtil.join(",", deptIds);
|
||||
setDeptIdSet(deptIdSet);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean insert() {
|
||||
super.insert();
|
||||
|
||||
-6
@@ -1,7 +1,5 @@
|
||||
package com.agileboot.domain.system.role.model;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.system.role.db.SysRoleEntity;
|
||||
@@ -36,13 +34,9 @@ public class RoleModelFactory {
|
||||
queryWrapper.eq(SysRoleMenuEntity::getRoleId, roleId);
|
||||
List<Long> menuIds = roleMenuService.list(queryWrapper).stream().map(SysRoleMenuEntity::getMenuId)
|
||||
.collect(Collectors.toList());
|
||||
List<Long> deptIds = StrUtil.split(byId.getDeptIdSet(), ",").stream()
|
||||
.map(Convert::toLong).collect( Collectors.toList());
|
||||
|
||||
RoleModel roleModel = new RoleModel(byId, roleService, roleMenuService);
|
||||
|
||||
roleModel.setMenuIds(menuIds);
|
||||
roleModel.setDeptIds(deptIds);
|
||||
|
||||
return roleModel;
|
||||
}
|
||||
|
||||
+83
-10
@@ -1,14 +1,21 @@
|
||||
package com.agileboot.domain.system.user;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.common.enums.common.ConfigKeyEnum;
|
||||
import com.agileboot.common.enums.common.GenderEnum;
|
||||
import com.agileboot.common.enums.common.UserStatusEnum;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.common.cache.CacheCenter;
|
||||
import com.agileboot.domain.common.cache.GuavaCacheService;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.common.dto.CurrentLoginUserDTO;
|
||||
import com.agileboot.domain.system.post.dto.PostDTO;
|
||||
import com.agileboot.domain.system.role.dto.RoleDTO;
|
||||
import com.agileboot.domain.system.user.command.AddUserCommand;
|
||||
import com.agileboot.domain.system.user.command.ChangeStatusCommand;
|
||||
import com.agileboot.domain.system.user.command.RegisterUserCommand;
|
||||
import com.agileboot.domain.system.user.command.ResetPasswordCommand;
|
||||
import com.agileboot.domain.system.user.command.UpdateProfileCommand;
|
||||
import com.agileboot.domain.system.user.command.UpdateUserAvatarCommand;
|
||||
@@ -22,12 +29,12 @@ import com.agileboot.domain.system.user.model.UserModel;
|
||||
import com.agileboot.domain.system.user.model.UserModelFactory;
|
||||
import com.agileboot.domain.system.user.query.SearchUserQuery;
|
||||
import com.agileboot.infrastructure.user.web.SystemLoginUser;
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.agileboot.domain.system.role.db.SysRoleEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import com.agileboot.domain.system.post.db.SysPostService;
|
||||
import com.agileboot.domain.system.role.db.SysRoleService;
|
||||
import com.agileboot.domain.system.user.db.SysUserService;
|
||||
import com.agileboot.infrastructure.user.AuthenticationUtils;
|
||||
import com.agileboot.infrastructure.user.web.DataScopeEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.List;
|
||||
@@ -42,16 +49,19 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class UserApplicationService {
|
||||
|
||||
private static final String DEFAULT_REGISTER_ROLE_KEY = "common";
|
||||
|
||||
private final SysUserService userService;
|
||||
|
||||
private final SysRoleService roleService;
|
||||
|
||||
private final SysPostService postService;
|
||||
|
||||
private final UserModelFactory userModelFactory;
|
||||
|
||||
private final GuavaCacheService guavaCacheService;
|
||||
|
||||
|
||||
public PageDTO<UserDTO> getUserList(SearchUserQuery<SearchUserDO> query) {
|
||||
applyOnlySelfScope(query);
|
||||
Page<SearchUserDO> userPage = userService.getUserList(query);
|
||||
List<UserDTO> userDTOList = userPage.getRecords().stream().map(UserDTO::new).collect(Collectors.toList());
|
||||
return new PageDTO<>(userDTOList, userPage.getTotal());
|
||||
@@ -60,10 +70,9 @@ public class UserApplicationService {
|
||||
public UserProfileDTO getUserProfile(Long userId) {
|
||||
|
||||
SysUserEntity userEntity = userService.getById(userId);
|
||||
SysPostEntity postEntity = userService.getPostOfUser(userId);
|
||||
SysRoleEntity roleEntity = userService.getRoleOfUser(userId);
|
||||
|
||||
return new UserProfileDTO(userEntity, postEntity, roleEntity);
|
||||
return new UserProfileDTO(userEntity, roleEntity);
|
||||
}
|
||||
|
||||
|
||||
@@ -102,14 +111,11 @@ public class UserApplicationService {
|
||||
LambdaQueryWrapper<SysRoleEntity> roleQuery = new LambdaQueryWrapper<SysRoleEntity>()
|
||||
.orderByAsc(SysRoleEntity::getRoleSort);
|
||||
List<RoleDTO> roleDtoList = roleService.list(roleQuery).stream().map(RoleDTO::new).collect(Collectors.toList());
|
||||
List<PostDTO> postDtoList = postService.list().stream().map(PostDTO::new).collect(Collectors.toList());
|
||||
detailDTO.setRoleOptions(roleDtoList);
|
||||
detailDTO.setPostOptions(postDtoList);
|
||||
|
||||
if (userEntity != null) {
|
||||
detailDTO.setUser(new UserDTO(userEntity));
|
||||
detailDTO.setRoleId(userEntity.getRoleId());
|
||||
detailDTO.setPostId(userEntity.getPostId());
|
||||
}
|
||||
return detailDTO;
|
||||
}
|
||||
@@ -127,6 +133,20 @@ public class UserApplicationService {
|
||||
model.insert();
|
||||
}
|
||||
|
||||
public void registerUser(RegisterUserCommand command) {
|
||||
checkRegisterIsOpen();
|
||||
checkRegisterPassword(command);
|
||||
|
||||
UserModel model = userModelFactory.create();
|
||||
loadRegisterCommand(model, command);
|
||||
|
||||
model.checkUsernameIsUnique();
|
||||
model.checkPhoneNumberIsUnique();
|
||||
model.checkEmailIsUnique();
|
||||
model.resetPassword(command.getPassword());
|
||||
model.insert();
|
||||
}
|
||||
|
||||
public void updateUser(UpdateUserCommand command) {
|
||||
UserModel model = userModelFactory.loadById(command.getUserId());
|
||||
model.loadUpdateUserCommand(command);
|
||||
@@ -182,5 +202,58 @@ public class UserApplicationService {
|
||||
CacheCenter.userCache.delete(userModel.getUserId());
|
||||
}
|
||||
|
||||
private void checkRegisterIsOpen() {
|
||||
Boolean isRegisterUserOn = Convert.toBool(guavaCacheService.configCache.get(ConfigKeyEnum.REGISTER.getValue()));
|
||||
if (!Boolean.TRUE.equals(isRegisterUserOn)) {
|
||||
throw new ApiException(ErrorCode.Business.USER_REGISTER_IS_CLOSED);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkRegisterPassword(RegisterUserCommand command) {
|
||||
if (!StrUtil.equals(command.getPassword(), command.getConfirmPassword())) {
|
||||
throw new ApiException(ErrorCode.Business.USER_REGISTER_PASSWORD_NOT_MATCH);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyOnlySelfScope(SearchUserQuery<SearchUserDO> query) {
|
||||
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
|
||||
if (loginUser == null || loginUser.getRoleInfo() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (DataScopeEnum.ONLY_SELF.equals(loginUser.getRoleInfo().getDataScope())) {
|
||||
query.setUserId(loginUser.getUserId());
|
||||
}
|
||||
}
|
||||
|
||||
private void loadRegisterCommand(UserModel model, RegisterUserCommand command) {
|
||||
SysRoleEntity role = getDefaultRegisterRole();
|
||||
model.setUsername(command.getUsername());
|
||||
model.setNickname(getRegisterNickname(command));
|
||||
model.setEmail(command.getEmail());
|
||||
model.setPhoneNumber(command.getPhoneNumber());
|
||||
model.setRoleId(role.getRoleId());
|
||||
model.setStatus(UserStatusEnum.NORMAL.getValue());
|
||||
model.setUserType(0);
|
||||
model.setSex(GenderEnum.UNKNOWN.getValue());
|
||||
model.setIsAdmin(false);
|
||||
model.setRemark("自助注册用户");
|
||||
}
|
||||
|
||||
private SysRoleEntity getDefaultRegisterRole() {
|
||||
SysRoleEntity role = roleService.getEnabledRoleByKey(DEFAULT_REGISTER_ROLE_KEY);
|
||||
if (role == null) {
|
||||
throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, DEFAULT_REGISTER_ROLE_KEY, "普通角色");
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
private String getRegisterNickname(RegisterUserCommand command) {
|
||||
if (StrUtil.isNotBlank(command.getNickname())) {
|
||||
return command.getNickname();
|
||||
}
|
||||
return command.getUsername();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
-6
@@ -9,9 +9,6 @@ import lombok.Data;
|
||||
@Data
|
||||
public class AddUserCommand {
|
||||
|
||||
@ExcelColumn(name = "部门ID")
|
||||
private Long deptId;
|
||||
|
||||
@ExcelColumn(name = "用户名")
|
||||
private String username;
|
||||
|
||||
@@ -39,9 +36,6 @@ public class AddUserCommand {
|
||||
@ExcelColumn(name = "角色ID")
|
||||
private Long roleId;
|
||||
|
||||
@ExcelColumn(name = "职位ID")
|
||||
private Long postId;
|
||||
|
||||
@ExcelColumn(name = "备注")
|
||||
private String remark;
|
||||
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.agileboot.domain.system.user.command;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 自助注册用户请求。
|
||||
*
|
||||
* @author codex
|
||||
*/
|
||||
@Data
|
||||
public class RegisterUserCommand {
|
||||
|
||||
@NotBlank(message = "账号不能为空")
|
||||
@Size(max = 64, message = "账号长度不能超过64个字符")
|
||||
private String username;
|
||||
|
||||
@Size(max = 32, message = "昵称长度不能超过32个字符")
|
||||
private String nickname;
|
||||
|
||||
@Email(message = "邮箱格式不正确")
|
||||
@Size(max = 128, message = "邮箱长度不能超过128个字符")
|
||||
private String email;
|
||||
|
||||
@Size(max = 18, message = "手机号长度不能超过18个字符")
|
||||
private String phoneNumber;
|
||||
|
||||
@NotBlank(message = "密码不能为空")
|
||||
private String password;
|
||||
|
||||
@NotBlank(message = "确认密码不能为空")
|
||||
private String confirmPassword;
|
||||
|
||||
private String captchaCode;
|
||||
|
||||
private String captchaCodeKey;
|
||||
|
||||
}
|
||||
+4
-1
@@ -1,5 +1,6 @@
|
||||
package com.agileboot.domain.system.user.command;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -9,7 +10,9 @@ import lombok.Data;
|
||||
public class UpdateUserPasswordCommand {
|
||||
|
||||
private Long userId;
|
||||
@NotBlank(message = "密码不能为空")
|
||||
private String newPassword;
|
||||
private String oldPassword;
|
||||
@NotBlank(message = "确认密码不能为空")
|
||||
private String confirmPassword;
|
||||
|
||||
}
|
||||
|
||||
+1
-4
@@ -7,11 +7,8 @@ import lombok.EqualsAndHashCode;
|
||||
* 如果Entity的字段和复杂查询不匹配时 自定义类来接收
|
||||
* @author valarchie
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SearchUserDO extends SysUserEntity {
|
||||
|
||||
private String deptName;
|
||||
private String deptLeader;
|
||||
|
||||
}
|
||||
|
||||
-8
@@ -32,18 +32,10 @@ public class SysUserEntity extends BaseEntity<SysUserEntity> {
|
||||
@TableId(value = "user_id", type = IdType.AUTO)
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("职位id")
|
||||
@TableField("post_id")
|
||||
private Long postId;
|
||||
|
||||
@ApiModelProperty("角色id")
|
||||
@TableField("role_id")
|
||||
private Long roleId;
|
||||
|
||||
@ApiModelProperty("部门ID")
|
||||
@TableField("dept_id")
|
||||
private Long deptId;
|
||||
|
||||
@ApiModelProperty("用户账号")
|
||||
@TableField("username")
|
||||
private String username;
|
||||
|
||||
+2
-18
@@ -1,6 +1,5 @@
|
||||
package com.agileboot.domain.system.user.db;
|
||||
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.agileboot.domain.system.role.db.SysRoleEntity;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@@ -35,19 +34,6 @@ public interface SysUserMapper extends BaseMapper<SysUserEntity> {
|
||||
+ " AND u.user_id = #{userId}")
|
||||
List<SysRoleEntity> getRolesByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 查询用户所属岗位组
|
||||
*
|
||||
* @param userId 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
@Select("SELECT p.* "
|
||||
+ "FROM sys_post p "
|
||||
+ " LEFT JOIN sys_user u ON p.post_id = u.post_id "
|
||||
+ "WHERE u.user_id = #{userId} "
|
||||
+ " AND p.deleted = 0")
|
||||
List<SysPostEntity> getPostsByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询权限
|
||||
*
|
||||
@@ -71,10 +57,9 @@ public interface SysUserMapper extends BaseMapper<SysUserEntity> {
|
||||
* @param queryWrapper 条件选择器
|
||||
* @return 分页处理后的用户列表
|
||||
*/
|
||||
@Select("SELECT DISTINCT u.user_id, u.dept_id, u.username, u.nick_name, u.email "
|
||||
@Select("SELECT DISTINCT u.user_id, u.username, u.nick_name, u.email "
|
||||
+ " , u.phone_number, u.status, u.create_time "
|
||||
+ "FROM sys_user u "
|
||||
+ " LEFT JOIN sys_dept d ON u.dept_id = d.dept_id "
|
||||
+ " LEFT JOIN sys_role r ON r.role_id = u.role_id"
|
||||
+ " ${ew.customSqlSegment}")
|
||||
Page<SysUserEntity> getUserListByRole(Page<SysUserEntity> page,
|
||||
@@ -86,9 +71,8 @@ public interface SysUserMapper extends BaseMapper<SysUserEntity> {
|
||||
* @param queryWrapper 查询对象
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Select("SELECT u.*, d.dept_name, d.leader_name as dept_leader "
|
||||
@Select("SELECT u.* "
|
||||
+ "FROM sys_user u "
|
||||
+ " LEFT JOIN sys_dept d ON u.dept_id = d.dept_id "
|
||||
+ "${ew.customSqlSegment}")
|
||||
Page<SearchUserDO> getUserList(Page<SearchUserDO> page,
|
||||
@Param(Constants.WRAPPER) Wrapper<SearchUserDO> queryWrapper);
|
||||
|
||||
-8
@@ -1,7 +1,6 @@
|
||||
package com.agileboot.domain.system.user.db;
|
||||
|
||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.agileboot.domain.system.role.db.SysRoleEntity;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
@@ -49,13 +48,6 @@ public interface SysUserService extends IService<SysUserEntity> {
|
||||
*/
|
||||
SysRoleEntity getRoleOfUser(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户的岗位
|
||||
* @param userId 用户id
|
||||
* @return 用户岗位
|
||||
*/
|
||||
SysPostEntity getPostOfUser(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户的权限列表
|
||||
* @param userId 用户id
|
||||
|
||||
-8
@@ -1,7 +1,6 @@
|
||||
package com.agileboot.domain.system.user.db;
|
||||
|
||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.agileboot.domain.system.role.db.SysRoleEntity;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -55,13 +54,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SysPostEntity getPostOfUser(Long userId) {
|
||||
List<SysPostEntity> list = baseMapper.getPostsByUserId(userId);
|
||||
return list.isEmpty() ? null : list.get(0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<String> getMenuPermissionsForUser(Long userId) {
|
||||
return baseMapper.getMenuPermsByUserId(userId);
|
||||
|
||||
+1
-25
@@ -4,11 +4,9 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import com.agileboot.common.annotation.ExcelColumn;
|
||||
import com.agileboot.common.annotation.ExcelSheet;
|
||||
import com.agileboot.domain.common.cache.CacheCenter;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptEntity;
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.agileboot.domain.system.role.db.SysRoleEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import com.agileboot.domain.system.user.db.SearchUserDO;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -23,11 +21,6 @@ public class UserDTO {
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
|
||||
SysDeptEntity dept = CacheCenter.deptCache.get(entity.getDeptId() + "");
|
||||
if (dept != null) {
|
||||
this.deptName = dept.getDeptName();
|
||||
}
|
||||
|
||||
SysUserEntity creator = CacheCenter.userCache.getObjectById(entity.getCreatorId());
|
||||
if (creator != null) {
|
||||
this.creatorName = creator.getUsername();
|
||||
@@ -38,11 +31,6 @@ public class UserDTO {
|
||||
this.roleName = roleEntity != null ? roleEntity.getRoleName() : "";
|
||||
}
|
||||
|
||||
if (entity.getPostId() != null) {
|
||||
SysPostEntity post = CacheCenter.postCache.getObjectById(entity.getRoleId());
|
||||
this.postName = post != null ? post.getPostName() : "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,24 +49,12 @@ public class UserDTO {
|
||||
@ExcelColumn(name = "用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ExcelColumn(name = "职位ID")
|
||||
private Long postId;
|
||||
|
||||
@ExcelColumn(name = "职位名称")
|
||||
private String postName;
|
||||
|
||||
@ExcelColumn(name = "角色ID")
|
||||
private Long roleId;
|
||||
|
||||
@ExcelColumn(name = "角色名称")
|
||||
private String roleName;
|
||||
|
||||
@ExcelColumn(name = "部门ID")
|
||||
private Long deptId;
|
||||
|
||||
@ExcelColumn(name = "部门名称")
|
||||
private String deptName;
|
||||
|
||||
@ExcelColumn(name = "用户名")
|
||||
private String username;
|
||||
|
||||
|
||||
-8
@@ -1,6 +1,5 @@
|
||||
package com.agileboot.domain.system.user.dto;
|
||||
|
||||
import com.agileboot.domain.system.post.dto.PostDTO;
|
||||
import com.agileboot.domain.system.role.dto.RoleDTO;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -19,13 +18,6 @@ public class UserDetailDTO {
|
||||
*/
|
||||
private List<RoleDTO> roleOptions;
|
||||
|
||||
/**
|
||||
* 返回所有posts
|
||||
*/
|
||||
private List<PostDTO> postOptions;
|
||||
|
||||
private Long postId;
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private Set<String> permissions;
|
||||
|
||||
+1
-7
@@ -1,6 +1,5 @@
|
||||
package com.agileboot.domain.system.user.dto;
|
||||
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.agileboot.domain.system.role.db.SysRoleEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import lombok.Data;
|
||||
@@ -11,15 +10,11 @@ import lombok.Data;
|
||||
@Data
|
||||
public class UserProfileDTO {
|
||||
|
||||
public UserProfileDTO(SysUserEntity userEntity, SysPostEntity postEntity, SysRoleEntity roleEntity) {
|
||||
public UserProfileDTO(SysUserEntity userEntity, SysRoleEntity roleEntity) {
|
||||
if (userEntity != null) {
|
||||
this.user = new UserDTO(userEntity);
|
||||
}
|
||||
|
||||
if (postEntity != null) {
|
||||
this.postName = postEntity.getPostName();
|
||||
}
|
||||
|
||||
if (roleEntity != null) {
|
||||
this.roleName = roleEntity.getRoleName();
|
||||
}
|
||||
@@ -27,6 +22,5 @@ public class UserProfileDTO {
|
||||
|
||||
private UserDTO user;
|
||||
private String roleName;
|
||||
private String postName;
|
||||
|
||||
}
|
||||
|
||||
+10
-25
@@ -6,8 +6,6 @@ import com.agileboot.common.config.AgileBootConfig;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.common.exception.error.ErrorCode.Business;
|
||||
import com.agileboot.domain.system.dept.model.DeptModelFactory;
|
||||
import com.agileboot.domain.system.post.model.PostModelFactory;
|
||||
import com.agileboot.domain.system.role.model.RoleModelFactory;
|
||||
import com.agileboot.domain.system.user.command.AddUserCommand;
|
||||
import com.agileboot.domain.system.user.command.UpdateProfileCommand;
|
||||
@@ -32,26 +30,18 @@ public class UserModel extends SysUserEntity {
|
||||
|
||||
private SysUserService userService;
|
||||
|
||||
private PostModelFactory postModelFactory;
|
||||
|
||||
private DeptModelFactory deptModelFactory;
|
||||
|
||||
private RoleModelFactory roleModelFactory;
|
||||
|
||||
public UserModel(SysUserEntity entity, SysUserService userService, PostModelFactory postModelFactory,
|
||||
DeptModelFactory deptModelFactory, RoleModelFactory roleModelFactory) {
|
||||
this(userService, postModelFactory, deptModelFactory, roleModelFactory);
|
||||
public UserModel(SysUserEntity entity, SysUserService userService, RoleModelFactory roleModelFactory) {
|
||||
this(userService, roleModelFactory);
|
||||
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
public UserModel(SysUserService userService, PostModelFactory postModelFactory,
|
||||
DeptModelFactory deptModelFactory, RoleModelFactory roleModelFactory) {
|
||||
public UserModel(SysUserService userService, RoleModelFactory roleModelFactory) {
|
||||
this.userService = userService;
|
||||
this.postModelFactory = postModelFactory;
|
||||
this.deptModelFactory = deptModelFactory;
|
||||
this.roleModelFactory = roleModelFactory;
|
||||
}
|
||||
|
||||
@@ -92,19 +82,9 @@ public class UserModel extends SysUserEntity {
|
||||
}
|
||||
|
||||
public void checkFieldRelatedEntityExist() {
|
||||
|
||||
if (getPostId() != null) {
|
||||
postModelFactory.loadById(getPostId());
|
||||
}
|
||||
|
||||
if (getDeptId() != null) {
|
||||
deptModelFactory.loadById(getDeptId());
|
||||
}
|
||||
|
||||
if (getRoleId() != null) {
|
||||
roleModelFactory.loadById(getRoleId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -123,8 +103,13 @@ public class UserModel extends SysUserEntity {
|
||||
|
||||
|
||||
public void modifyPassword(UpdateUserPasswordCommand command) {
|
||||
if (!AuthenticationUtils.matchesPassword(command.getOldPassword(), getPassword())) {
|
||||
throw new ApiException(ErrorCode.Business.USER_PASSWORD_IS_NOT_CORRECT);
|
||||
if (command == null || StrUtil.isBlank(command.getNewPassword())
|
||||
|| StrUtil.isBlank(command.getConfirmPassword())) {
|
||||
throw new ApiException(ErrorCode.Business.USER_PASSWORD_IS_EMPTY);
|
||||
}
|
||||
|
||||
if (!StrUtil.equals(command.getNewPassword(), command.getConfirmPassword())) {
|
||||
throw new ApiException(ErrorCode.Business.USER_REGISTER_PASSWORD_NOT_MATCH);
|
||||
}
|
||||
|
||||
if (AuthenticationUtils.matchesPassword(command.getNewPassword(), getPassword())) {
|
||||
|
||||
+2
-8
@@ -2,8 +2,6 @@ package com.agileboot.domain.system.user.model;
|
||||
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.system.dept.model.DeptModelFactory;
|
||||
import com.agileboot.domain.system.post.model.PostModelFactory;
|
||||
import com.agileboot.domain.system.role.model.RoleModelFactory;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserService;
|
||||
@@ -20,10 +18,6 @@ public class UserModelFactory {
|
||||
|
||||
private final SysUserService userService;
|
||||
|
||||
private final PostModelFactory postModelFactory;
|
||||
|
||||
private final DeptModelFactory deptModelFactory;
|
||||
|
||||
private final RoleModelFactory roleModelFactory;
|
||||
|
||||
public UserModel loadById(Long userId) {
|
||||
@@ -31,11 +25,11 @@ public class UserModelFactory {
|
||||
if (byId == null) {
|
||||
throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, userId, "用户");
|
||||
}
|
||||
return new UserModel(byId, userService, postModelFactory, deptModelFactory, roleModelFactory);
|
||||
return new UserModel(byId, userService, roleModelFactory);
|
||||
}
|
||||
|
||||
public UserModel create() {
|
||||
return new UserModel(userService, postModelFactory, deptModelFactory, roleModelFactory);
|
||||
return new UserModel(userService, roleModelFactory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-7
@@ -18,7 +18,6 @@ public class SearchUserQuery<T> extends AbstractPageQuery<T> {
|
||||
protected String username;
|
||||
protected Integer status;
|
||||
protected String phoneNumber;
|
||||
protected Long deptId;
|
||||
|
||||
@Override
|
||||
public QueryWrapper<T> addQueryCondition() {
|
||||
@@ -28,12 +27,7 @@ public class SearchUserQuery<T> extends AbstractPageQuery<T> {
|
||||
.like(StrUtil.isNotEmpty(phoneNumber), "u.phone_number", phoneNumber)
|
||||
.eq(userId != null, "u.user_id", userId)
|
||||
.eq(status != null, "u.status", status)
|
||||
.eq("u.deleted", 0)
|
||||
.and(deptId != null, o ->
|
||||
o.eq("u.dept_id", deptId)
|
||||
.or()
|
||||
.apply("u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(" + deptId
|
||||
+ ", ancestors))"));
|
||||
.eq("u.deleted", 0);
|
||||
|
||||
// 设置排序字段
|
||||
this.timeRangeColumn = "u.create_time";
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.agileboot.domain.collaboration.record.enumtype;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SettlementStatusEnumTest {
|
||||
|
||||
@Test
|
||||
void aggregateShouldIgnoreNoneStatus() {
|
||||
String status = SettlementStatusEnum.aggregate(Arrays.asList("NONE", "SETTLED"));
|
||||
|
||||
Assertions.assertEquals("SETTLED", status);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aggregateShouldReturnPartialWhenStatusesAreMixed() {
|
||||
String status = SettlementStatusEnum.aggregate(Arrays.asList("SETTLED", "UNSETTLED"));
|
||||
|
||||
Assertions.assertEquals("PARTIAL", status);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aggregateShouldReturnNoneWhenNoEffectiveStatusExists() {
|
||||
String status = SettlementStatusEnum.aggregate(Collections.singletonList("NONE"));
|
||||
|
||||
Assertions.assertEquals("NONE", status);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aggregateShouldReturnNoneWhenStatusListIsEmpty() {
|
||||
String status = SettlementStatusEnum.aggregate(Collections.emptyList());
|
||||
|
||||
Assertions.assertEquals("NONE", status);
|
||||
}
|
||||
|
||||
}
|
||||
-157
@@ -1,157 +0,0 @@
|
||||
package com.agileboot.domain.system.dept.model;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode.Business;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptEntity;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptService;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
|
||||
class DeptModelTest {
|
||||
|
||||
private static final Long DEPT_ID = 1L;
|
||||
private static final Long PARENT_ID = 2L;
|
||||
|
||||
private final SysDeptService deptService = mock(SysDeptService.class);
|
||||
|
||||
private final DeptModelFactory deptModelFactory = new DeptModelFactory(deptService);
|
||||
|
||||
@Test
|
||||
void testCheckDeptNameUnique() {
|
||||
DeptModel deptModel = deptModelFactory.create();
|
||||
deptModel.setDeptName("dept 1");
|
||||
when(
|
||||
deptService.isDeptNameDuplicated(ArgumentMatchers.any(), ArgumentMatchers.any(),
|
||||
ArgumentMatchers.any())).thenReturn(true);
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, deptModel::checkDeptNameUnique);
|
||||
Assertions.assertEquals(Business.DEPT_NAME_IS_NOT_UNIQUE, exception.getErrorCode());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testCheckParentIdConflict() {
|
||||
DeptModel deptModel = deptModelFactory.create();
|
||||
Long sameId = 1L;
|
||||
deptModel.setDeptId(sameId);
|
||||
deptModel.setParentId(sameId);
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, deptModel::checkParentIdConflict);
|
||||
|
||||
Assertions.assertEquals(Business.DEPT_PARENT_ID_IS_NOT_ALLOWED_SELF, exception.getErrorCode());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testCheckHasChildDept() {
|
||||
DeptModel deptModel = deptModelFactory.create();
|
||||
deptModel.setDeptId(DEPT_ID);
|
||||
when(deptService.hasChildrenDept((DEPT_ID), eq(null))).thenReturn(true);
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, deptModel::checkHasChildDept);
|
||||
|
||||
Assertions.assertEquals(Business.DEPT_EXIST_CHILD_DEPT_NOT_ALLOW_DELETE, exception.getErrorCode());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testCheckDeptAssignedToUsers() {
|
||||
DeptModel deptModel = deptModelFactory.create();
|
||||
deptModel.setDeptId(DEPT_ID);
|
||||
when(deptService.isDeptAssignedToUsers(DEPT_ID)).thenReturn(true);
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class,
|
||||
deptModel::checkDeptAssignedToUsers);
|
||||
|
||||
Assertions.assertEquals(Business.DEPT_EXIST_LINK_USER_NOT_ALLOW_DELETE, exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateAncestorsWhenParentIdZero() {
|
||||
DeptModel deptModel = deptModelFactory.create();
|
||||
deptModel.setParentId(0L);
|
||||
|
||||
deptModel.generateAncestors();
|
||||
|
||||
Assertions.assertEquals(deptModel.getAncestors(), deptModel.getParentId().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateAncestorsWhenParentDeptNotExist() {
|
||||
DeptModel deptModel = deptModelFactory.create();
|
||||
deptModel.setParentId(PARENT_ID);
|
||||
when(deptService.getById(PARENT_ID)).thenReturn(null);
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, deptModel::generateAncestors);
|
||||
|
||||
Assertions.assertEquals(Business.DEPT_PARENT_DEPT_NO_EXIST_OR_DISABLED, exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateAncestorsWhenParentDeptDisabled() {
|
||||
DeptModel deptModel = deptModelFactory.create();
|
||||
deptModel.setParentId(PARENT_ID);
|
||||
SysDeptEntity parentDept = new SysDeptEntity();
|
||||
parentDept.setStatus(0);
|
||||
|
||||
when(deptService.getById(PARENT_ID)).thenReturn(parentDept);
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, deptModel::generateAncestors);
|
||||
Assertions.assertEquals(Business.DEPT_PARENT_DEPT_NO_EXIST_OR_DISABLED, exception.getErrorCode());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGenerateAncestorsSuccessful() {
|
||||
DeptModel deptModel = deptModelFactory.create();
|
||||
deptModel.setParentId(PARENT_ID);
|
||||
SysDeptEntity parentDept = new SysDeptEntity();
|
||||
parentDept.setStatus(1);
|
||||
parentDept.setAncestors("1,100");
|
||||
when(deptService.getById(PARENT_ID)).thenReturn(parentDept);
|
||||
deptModel.generateAncestors();
|
||||
|
||||
Assertions.assertEquals("1,100,2", deptModel.getAncestors());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testCheckStatusAllowChangeWhenDisableButHasChildDept() {
|
||||
DeptModel deptModel = deptModelFactory.create();
|
||||
deptModel.setDeptId(DEPT_ID);
|
||||
deptModel.setStatus(0);
|
||||
when(deptService.hasChildrenDept(DEPT_ID, true)).thenReturn(true);
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, deptModel::checkStatusAllowChange);
|
||||
|
||||
Assertions.assertEquals(Business.DEPT_STATUS_ID_IS_NOT_ALLOWED_CHANGE, exception.getErrorCode());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testCheckStatusAllowChangeWhenDisableButNoChildDept() {
|
||||
DeptModel deptModel = deptModelFactory.create();
|
||||
deptModel.setDeptId(DEPT_ID);
|
||||
deptModel.setStatus(0);
|
||||
when(deptService.hasChildrenDept(DEPT_ID, true)).thenReturn(false);
|
||||
|
||||
Assertions.assertDoesNotThrow(deptModel::checkStatusAllowChange);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testCheckStatusAllowChangeWhenEnableAndHasChildDept() {
|
||||
DeptModel deptModel = deptModelFactory.create();
|
||||
deptModel.setDeptId(DEPT_ID);
|
||||
deptModel.setStatus(1);
|
||||
when(deptService.hasChildrenDept(DEPT_ID, true)).thenReturn(true);
|
||||
Assertions.assertDoesNotThrow(deptModel::checkStatusAllowChange);
|
||||
}
|
||||
|
||||
}
|
||||
-86
@@ -1,86 +0,0 @@
|
||||
package com.agileboot.domain.system.post.model;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode.Business;
|
||||
import com.agileboot.domain.system.post.db.SysPostService;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
class PostModelTest {
|
||||
|
||||
private final SysPostService postService = mock(SysPostService.class);
|
||||
|
||||
private final PostModelFactory postModelFactory = new PostModelFactory(postService);
|
||||
|
||||
private static final long POST_ID = 1L;
|
||||
|
||||
@AfterEach
|
||||
public void clean() {
|
||||
Mockito.reset(postService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckCanBeDeleteWhenFailed() {
|
||||
PostModel postModel = postModelFactory.create();
|
||||
postModel.setPostId(POST_ID);
|
||||
|
||||
when(postService.isAssignedToUsers(POST_ID)).thenReturn(true);
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, postModel::checkCanBeDelete);
|
||||
Assertions.assertEquals(Business.POST_ALREADY_ASSIGNED_TO_USER_CAN_NOT_BE_DELETED, exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckCanBeDeleteWhenSuccessful() {
|
||||
PostModel postModel = postModelFactory.create();
|
||||
postModel.setPostId(POST_ID);
|
||||
|
||||
when(postService.isAssignedToUsers(POST_ID)).thenReturn(true);
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, postModel::checkCanBeDelete);
|
||||
Assertions.assertEquals(Business.POST_ALREADY_ASSIGNED_TO_USER_CAN_NOT_BE_DELETED, exception.getErrorCode());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testCheckPostNameUnique() {
|
||||
PostModel postWithSameName = postModelFactory.create();
|
||||
postWithSameName.setPostId(POST_ID);
|
||||
postWithSameName.setPostName("post 1");
|
||||
PostModel postWithNewName = postModelFactory.create();
|
||||
postWithNewName.setPostName("post 2");
|
||||
postWithNewName.setPostId(POST_ID);
|
||||
|
||||
when(postService.isPostNameDuplicated(POST_ID, eq("post 1"))).thenReturn(true);
|
||||
when(postService.isPostNameDuplicated(POST_ID, eq("post 2"))).thenReturn(false);
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, postWithSameName::checkPostNameUnique);
|
||||
Assertions.assertEquals(Business.POST_NAME_IS_NOT_UNIQUE, exception.getErrorCode());
|
||||
Assertions.assertDoesNotThrow(postWithNewName::checkPostNameUnique);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckPostCodeUnique() {
|
||||
PostModel postWithSameCode = postModelFactory.create();
|
||||
postWithSameCode.setPostId(POST_ID);
|
||||
postWithSameCode.setPostCode("code 1");
|
||||
PostModel postWithNewCode = postModelFactory.create();
|
||||
postWithNewCode.setPostId(POST_ID);
|
||||
postWithNewCode.setPostCode("code 2");
|
||||
|
||||
when(postService.isPostCodeDuplicated(POST_ID, "code 1")).thenReturn(true);
|
||||
when(postService.isPostCodeDuplicated(POST_ID, "code 2")).thenReturn(false);
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, postWithSameCode::checkPostCodeUnique);
|
||||
Assertions.assertEquals(Business.POST_CODE_IS_NOT_UNIQUE, exception.getErrorCode());
|
||||
Assertions.assertDoesNotThrow(postWithNewCode::checkPostCodeUnique);
|
||||
}
|
||||
|
||||
}
|
||||
-33
@@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode.Business;
|
||||
import com.agileboot.domain.system.role.db.SysRoleMenuService;
|
||||
@@ -69,36 +68,4 @@ class RoleModelTest {
|
||||
Assertions.assertDoesNotThrow(roleWithNewKey::checkRoleKeyUnique);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateDeptIdSetWhenNull() {
|
||||
RoleModel roleModel = roleModelFactory.create();
|
||||
roleModel.setDeptIds(null);
|
||||
roleModel.generateDeptIdSet();
|
||||
|
||||
Assertions.assertEquals("", roleModel.getDeptIdSet());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGenerateDeptIdSetWhenDuplicated() {
|
||||
RoleModel roleModel = roleModelFactory.create();
|
||||
roleModel.setDeptIds(ListUtil.of(1L,1L,2L,3L));
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, roleModel::generateDeptIdSet);
|
||||
|
||||
Assertions.assertEquals(Business.ROLE_DATA_SCOPE_DUPLICATED_DEPT, exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateDeptIdSetWhenSuccessful() {
|
||||
RoleModel roleModel = roleModelFactory.create();
|
||||
roleModel.setDeptIds(ListUtil.of(1L,2L,3L));
|
||||
roleModel.generateDeptIdSet();
|
||||
|
||||
Assertions.assertEquals("1,2,3", roleModel.getDeptIdSet());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+17
-13
@@ -6,8 +6,6 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode.Business;
|
||||
import com.agileboot.domain.system.dept.model.DeptModelFactory;
|
||||
import com.agileboot.domain.system.post.model.PostModelFactory;
|
||||
import com.agileboot.domain.system.role.model.RoleModelFactory;
|
||||
import com.agileboot.domain.system.user.command.UpdateUserPasswordCommand;
|
||||
import com.agileboot.infrastructure.user.AuthenticationUtils;
|
||||
@@ -19,12 +17,9 @@ import org.junit.jupiter.api.Test;
|
||||
class UserModelTest {
|
||||
|
||||
private final SysUserService userService = mock(SysUserService.class);
|
||||
private final PostModelFactory postModelFactory = mock(PostModelFactory.class);
|
||||
private final DeptModelFactory deptModelFactory = mock(DeptModelFactory.class);
|
||||
private final RoleModelFactory roleModelFactory = mock(RoleModelFactory.class);
|
||||
|
||||
private final UserModelFactory userModelFactory = new UserModelFactory(userService, postModelFactory,
|
||||
deptModelFactory, roleModelFactory);
|
||||
private final UserModelFactory userModelFactory = new UserModelFactory(userService, roleModelFactory);
|
||||
|
||||
private static final long USER_ID = 1L;
|
||||
private static final long ADMIN_USER_ID = 1L;
|
||||
@@ -121,9 +116,9 @@ class UserModelTest {
|
||||
UserModel userModel = userModelFactory.create();
|
||||
userModel.setPassword("$2a$10$rb1wRoEIkLbIknREEN1LH.FGs4g0oOS5t6l5LQ793nRaFO.SPHDHy");
|
||||
UpdateUserPasswordCommand passwordCommand = new UpdateUserPasswordCommand();
|
||||
passwordCommand.setOldPassword("admin123");
|
||||
String newPassword = "admin456";
|
||||
passwordCommand.setNewPassword(newPassword);
|
||||
passwordCommand.setConfirmPassword(newPassword);
|
||||
|
||||
userModel.modifyPassword(passwordCommand);
|
||||
|
||||
@@ -131,16 +126,25 @@ class UserModelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testModifyPasswordWhenPasswordWrong() {
|
||||
void testModifyPasswordWhenConfirmPasswordNotMatch() {
|
||||
UserModel userModel = userModelFactory.create();
|
||||
userModel.setPassword("$2a$10$rb1wRoEIkLbIknREEN1LH.FGs4g0oOS5t6l5LQ793nRaFO.SPHDHy");
|
||||
UpdateUserPasswordCommand passwordCommand = new UpdateUserPasswordCommand();
|
||||
passwordCommand.setOldPassword("admin999");
|
||||
String newPassword = "admin456";
|
||||
passwordCommand.setNewPassword(newPassword);
|
||||
passwordCommand.setNewPassword("admin456");
|
||||
passwordCommand.setConfirmPassword("admin789");
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, () -> userModel.modifyPassword(passwordCommand));
|
||||
Assertions.assertEquals(Business.USER_PASSWORD_IS_NOT_CORRECT, exception.getErrorCode());
|
||||
Assertions.assertEquals(Business.USER_REGISTER_PASSWORD_NOT_MATCH, exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testModifyPasswordWhenPasswordIsEmpty() {
|
||||
UserModel userModel = userModelFactory.create();
|
||||
UpdateUserPasswordCommand passwordCommand = new UpdateUserPasswordCommand();
|
||||
passwordCommand.setConfirmPassword("admin456");
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, () -> userModel.modifyPassword(passwordCommand));
|
||||
Assertions.assertEquals(Business.USER_PASSWORD_IS_EMPTY, exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,9 +152,9 @@ class UserModelTest {
|
||||
UserModel userModel = userModelFactory.create();
|
||||
userModel.setPassword("$2a$10$rb1wRoEIkLbIknREEN1LH.FGs4g0oOS5t6l5LQ793nRaFO.SPHDHy");
|
||||
UpdateUserPasswordCommand passwordCommand = new UpdateUserPasswordCommand();
|
||||
passwordCommand.setOldPassword("admin123");
|
||||
String newPassword = "admin123";
|
||||
passwordCommand.setNewPassword(newPassword);
|
||||
passwordCommand.setConfirmPassword(newPassword);
|
||||
|
||||
ApiException exception = assertThrows(ApiException.class, () -> userModel.modifyPassword(passwordCommand));
|
||||
Assertions.assertEquals(Business.USER_NEW_PASSWORD_IS_THE_SAME_AS_OLD, exception.getErrorCode());
|
||||
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
package com.agileboot.integrationTest.db;
|
||||
|
||||
import com.agileboot.integrationTest.IntegrationTestApplication;
|
||||
import com.agileboot.domain.system.dept.db.SysDeptService;
|
||||
import javax.annotation.Resource;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@SpringBootTest(classes = IntegrationTestApplication.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
class SysDeptServiceImplTest {
|
||||
|
||||
@Resource
|
||||
SysDeptService deptService;
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
void testIsDeptNameDuplicated() {
|
||||
boolean addWithSame = deptService.isDeptNameDuplicated("AgileBoot科技", null, null);
|
||||
boolean updateWithSame = deptService.isDeptNameDuplicated("AgileBoot科技", 1L, null);
|
||||
boolean addSameInParent = deptService.isDeptNameDuplicated("深圳总公司", null, 1L);
|
||||
|
||||
Assertions.assertTrue(addWithSame);
|
||||
Assertions.assertFalse(updateWithSame);
|
||||
Assertions.assertTrue(addSameInParent);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
void testHasChildDept() {
|
||||
boolean hasChild = deptService.hasChildrenDept(3L, null);
|
||||
boolean hasDisableChild = deptService.hasChildrenDept(3L, false);
|
||||
|
||||
Assertions.assertTrue(hasChild);
|
||||
Assertions.assertTrue(hasDisableChild);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
void testIsChildOfTheDept() {
|
||||
boolean isIndirectChild = deptService.isChildOfTheDept(1L, 10L);
|
||||
boolean isDirectChild = deptService.isChildOfTheDept(3L, 10L);
|
||||
boolean isNotChild = deptService.isChildOfTheDept(5L, 10L);
|
||||
|
||||
Assertions.assertTrue(isIndirectChild);
|
||||
Assertions.assertTrue(isDirectChild);
|
||||
Assertions.assertFalse(isNotChild);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
void testIsDeptAssignedToUsers() {
|
||||
boolean notAssigned = deptService.isDeptAssignedToUsers(1L);
|
||||
boolean isAssigned = deptService.isDeptAssignedToUsers(4L);
|
||||
|
||||
Assertions.assertFalse(notAssigned);
|
||||
Assertions.assertTrue(isAssigned);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+11
-12
@@ -1,6 +1,5 @@
|
||||
package com.agileboot.integrationTest.db;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.agileboot.integrationTest.IntegrationTestApplication;
|
||||
import com.agileboot.domain.system.menu.db.SysMenuEntity;
|
||||
import com.agileboot.domain.system.menu.db.SysMenuService;
|
||||
@@ -17,25 +16,28 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
@RunWith(SpringRunner.class)
|
||||
class SysMenuServiceImplTest {
|
||||
|
||||
private static final int COMMON_ROLE_COLLABORATION_MENU_COUNT = 7;
|
||||
|
||||
@Resource
|
||||
SysMenuService menuService;
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
void testGetMenuListByUserId() {
|
||||
List<SysMenuEntity> menusMissingLastMenu = menuService.getMenuListByUserId(2L);
|
||||
List<SysMenuEntity> allMenus = menuService.list();
|
||||
List<SysMenuEntity> registerUserMenus = menuService.getMenuListByUserId(2L);
|
||||
|
||||
Assertions.assertEquals(allMenus.size(), menusMissingLastMenu.size() + 1);
|
||||
Assertions.assertEquals(COMMON_ROLE_COLLABORATION_MENU_COUNT, registerUserMenus.size());
|
||||
Assertions.assertTrue(registerUserMenus.stream().allMatch(menu -> menu.getMenuId() >= 3000L));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
void testGetMenuIdsByRoleId() {
|
||||
List<Long> menusMissingLastMenu = menuService.getMenuIdsByRoleId(2L);
|
||||
List<SysMenuEntity> allMenus = menuService.list();
|
||||
List<Long> registerUserMenuIds = menuService.getMenuIdsByRoleId(2L);
|
||||
|
||||
Assertions.assertEquals(allMenus.size(), menusMissingLastMenu.size() + 1);
|
||||
Assertions.assertEquals(COMMON_ROLE_COLLABORATION_MENU_COUNT, registerUserMenuIds.size());
|
||||
Assertions.assertTrue(registerUserMenuIds.contains(3000L));
|
||||
Assertions.assertTrue(registerUserMenuIds.contains(3006L));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,11 +65,8 @@ class SysMenuServiceImplTest {
|
||||
@Test
|
||||
@Rollback
|
||||
void testIsMenuAssignToRole() {
|
||||
List<SysMenuEntity> allMenus = menuService.list();
|
||||
|
||||
boolean isAssignToRole = menuService.isMenuAssignToRoles(CollUtil.getFirst(allMenus).getMenuId());
|
||||
// role2 默认不给最后一个权限 所以最后一个菜单无权限
|
||||
boolean isNotAssignToRole = menuService.isMenuAssignToRoles(CollUtil.getLast(allMenus).getMenuId());
|
||||
boolean isAssignToRole = menuService.isMenuAssignToRoles(3000L);
|
||||
boolean isNotAssignToRole = menuService.isMenuAssignToRoles(1L);
|
||||
|
||||
Assertions.assertFalse(isNotAssignToRole);
|
||||
Assertions.assertTrue(isAssignToRole);
|
||||
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
package com.agileboot.integrationTest.db;
|
||||
|
||||
import com.agileboot.integrationTest.IntegrationTestApplication;
|
||||
import com.agileboot.domain.system.post.db.SysPostService;
|
||||
import javax.annotation.Resource;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@SpringBootTest(classes = IntegrationTestApplication.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
class SysPostServiceImplTest {
|
||||
|
||||
@Resource
|
||||
SysPostService postService;
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
void testIsPostNameDuplicated() {
|
||||
boolean addWithSame = postService.isPostNameDuplicated(null, "董事长");
|
||||
boolean updateWithSame = postService.isPostNameDuplicated(1L, "董事长");
|
||||
boolean addWithoutSame = postService.isPostNameDuplicated(null, "董事长1");
|
||||
|
||||
Assertions.assertTrue(addWithSame);
|
||||
Assertions.assertFalse(updateWithSame);
|
||||
Assertions.assertFalse(addWithoutSame);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
void testIsPostCodeDuplicated() {
|
||||
boolean addWithSame = postService.isPostCodeDuplicated(null, "ceo");
|
||||
boolean updateWithSame = postService.isPostCodeDuplicated(1L, "ceo");
|
||||
boolean addWithoutSame = postService.isPostCodeDuplicated(null, "ceo1");
|
||||
|
||||
Assertions.assertTrue(addWithSame);
|
||||
Assertions.assertFalse(updateWithSame);
|
||||
Assertions.assertFalse(addWithoutSame);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
void testIsAssignedToUsers() {
|
||||
boolean assignedPost = postService.isAssignedToUsers(1L);
|
||||
boolean unassignedPost = postService.isAssignedToUsers(3L);
|
||||
|
||||
Assertions.assertTrue(assignedPost);
|
||||
Assertions.assertFalse(unassignedPost);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+5
-21
@@ -4,17 +4,12 @@ import com.agileboot.domain.system.role.query.AllocatedRoleQuery;
|
||||
import com.agileboot.domain.system.role.query.UnallocatedRoleQuery;
|
||||
import com.agileboot.domain.system.user.query.SearchUserQuery;
|
||||
import com.agileboot.integrationTest.IntegrationTestApplication;
|
||||
import com.agileboot.domain.system.menu.db.SysMenuEntity;
|
||||
import com.agileboot.domain.system.post.db.SysPostEntity;
|
||||
import com.agileboot.domain.system.role.db.SysRoleEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import com.agileboot.domain.system.user.db.SearchUserDO;
|
||||
import com.agileboot.domain.system.menu.db.SysMenuService;
|
||||
import com.agileboot.domain.system.user.db.SysUserService;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Resource;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -27,10 +22,10 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
@RunWith(SpringRunner.class)
|
||||
class SysUserServiceImplTest {
|
||||
|
||||
private static final int COMMON_ROLE_COLLABORATION_PERMISSION_COUNT = 6;
|
||||
|
||||
@Resource
|
||||
SysUserService userService;
|
||||
@Resource
|
||||
SysMenuService menuService;
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
@@ -76,24 +71,14 @@ class SysUserServiceImplTest {
|
||||
Assertions.assertEquals("admin", roleOfUser.getRoleKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
void testGetPostOfUser() {
|
||||
SysPostEntity postOfUser = userService.getPostOfUser(1L);
|
||||
|
||||
Assertions.assertEquals(1L, postOfUser.getPostId());
|
||||
Assertions.assertEquals("董事长", postOfUser.getPostName());
|
||||
Assertions.assertEquals("ceo", postOfUser.getPostCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
void testGetMenuPermissionsForUsers() {
|
||||
Set<String> permissionByUser = userService.getMenuPermissionsForUser(2L);
|
||||
List<SysMenuEntity> allMenus = menuService.list();
|
||||
Set<String> allPermissions = allMenus.stream().map(SysMenuEntity::getPermission).collect(Collectors.toSet());
|
||||
|
||||
Assertions.assertEquals(allPermissions.size() - 1, permissionByUser.size());
|
||||
Assertions.assertEquals(COMMON_ROLE_COLLABORATION_PERMISSION_COUNT, permissionByUser.size());
|
||||
Assertions.assertTrue(permissionByUser.contains("collaboration:record:list"));
|
||||
Assertions.assertTrue(permissionByUser.contains("collaboration:record:remove"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,7 +88,6 @@ class SysUserServiceImplTest {
|
||||
|
||||
Assertions.assertEquals(1L, admin.getUserId());
|
||||
Assertions.assertEquals(1L, admin.getRoleId());
|
||||
Assertions.assertEquals(1L, admin.getPostId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user