refactor: 代码优化重构
This commit is contained in:
@@ -23,51 +23,47 @@ public interface DictService extends IService<Dict> {
|
||||
* 字典分页列表
|
||||
*
|
||||
* @param queryParams 分页查询对象
|
||||
* @return
|
||||
* @return 字典分页列表
|
||||
*/
|
||||
Page<DictPageVO> getDictPage(DictPageQuery queryParams);
|
||||
|
||||
|
||||
/**
|
||||
* 获取字典表单详情
|
||||
*
|
||||
* @param id 字典ID
|
||||
* @return
|
||||
* @return 字典表单
|
||||
*/
|
||||
DictForm getDictForm(Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 新增字典
|
||||
*
|
||||
* @param dictForm 字典表单
|
||||
* @return
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean saveDict(DictForm dictForm);
|
||||
|
||||
|
||||
/**
|
||||
* 修改字典
|
||||
*
|
||||
* @param id 字典ID
|
||||
* @param dictForm 字典表单
|
||||
* @return
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean updateDict(Long id, DictForm dictForm);
|
||||
|
||||
/**
|
||||
* 删除字典
|
||||
*
|
||||
* @param idsStr 字典ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
* @param ids 字典ID集合
|
||||
*/
|
||||
void deleteDictByIds(String idsStr);
|
||||
void deleteDictByIds(List<String> ids);
|
||||
|
||||
|
||||
/**
|
||||
* 获取字典列表
|
||||
* 获取字典列表(包含字典数据)
|
||||
*
|
||||
* @return
|
||||
* @return 字典列表
|
||||
*/
|
||||
List<DictVO> getAllDictWithData();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.youlai.boot.system.model.entity.Dept;
|
||||
import com.youlai.boot.system.model.form.DeptForm;
|
||||
import com.youlai.boot.system.model.query.DeptQuery;
|
||||
import com.youlai.boot.system.model.vo.DeptVO;
|
||||
import com.youlai.boot.common.constant.SymbolConstant;
|
||||
import com.youlai.boot.common.constant.SystemConstants;
|
||||
import com.youlai.boot.common.enums.StatusEnum;
|
||||
import com.youlai.boot.common.model.Option;
|
||||
@@ -237,7 +236,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
||||
public boolean deleteByIds(String ids) {
|
||||
// 删除部门及子部门
|
||||
if (StrUtil.isNotBlank(ids)) {
|
||||
String[] menuIds = ids.split(SymbolConstant.COMMA);
|
||||
String[] menuIds = ids.split(",");
|
||||
for (String deptId : menuIds) {
|
||||
this.update(new LambdaUpdateWrapper<Dept>()
|
||||
.eq(Dept::getId, deptId)
|
||||
@@ -265,7 +264,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
||||
} else {
|
||||
Dept parent = this.getById(parentId);
|
||||
if (parent != null) {
|
||||
treePath = parent.getTreePath() + SymbolConstant.COMMA + parent.getId();
|
||||
treePath = parent.getTreePath() + "," + parent.getId();
|
||||
}
|
||||
}
|
||||
return treePath;
|
||||
|
||||
@@ -85,7 +85,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements Di
|
||||
public DictForm getDictForm(Long id) {
|
||||
// 获取字典
|
||||
Dict entity = this.getById(id);
|
||||
if(entity==null){
|
||||
if (entity == null) {
|
||||
throw new BusinessException("字典不存在");
|
||||
}
|
||||
return dictConverter.toForm(entity);
|
||||
@@ -108,7 +108,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements Di
|
||||
.eq(Dict::getDictCode, dictCode)
|
||||
.ne(Dict::getId, id)
|
||||
);
|
||||
if(count>0){
|
||||
if (count > 0) {
|
||||
throw new BusinessException("字典编码已存在");
|
||||
}
|
||||
|
||||
@@ -122,14 +122,8 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements Di
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteDictByIds(String ids) {
|
||||
|
||||
Assert.isTrue(StrUtil.isNotBlank(ids), "请选择需要删除的字典");
|
||||
|
||||
List<String> idList = Arrays.stream(ids.split(","))
|
||||
.toList();
|
||||
|
||||
for (String id : idList) {
|
||||
public void deleteDictByIds(List<String> ids) {
|
||||
for (String id : ids) {
|
||||
Dict dict = this.getById(id);
|
||||
if (dict != null) {
|
||||
boolean removeResult = this.removeById(id);
|
||||
@@ -145,13 +139,13 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements Di
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有字典和字典数据
|
||||
*/
|
||||
@Override
|
||||
public List<DictVO> getAllDictWithData() {
|
||||
return this.baseMapper.getAllDictWithData();
|
||||
}
|
||||
/**
|
||||
* 获取字典列表(包含字典数据)
|
||||
*/
|
||||
@Override
|
||||
public List<DictVO> getAllDictWithData() {
|
||||
return this.baseMapper.getAllDictWithData();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,13 +7,12 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.boot.common.constant.SymbolConstant;
|
||||
import com.youlai.boot.common.exception.BusinessException;
|
||||
import com.youlai.boot.core.security.util.SecurityUtils;
|
||||
import com.youlai.boot.shared.websocket.service.OnlineUserService;
|
||||
import com.youlai.boot.system.converter.NoticeConverter;
|
||||
import com.youlai.boot.system.enums.NoticePublishStatusEnum;
|
||||
import com.youlai.boot.system.enums.NoticeTargetTypeEnum;
|
||||
import com.youlai.boot.system.enums.NoticeTargetEnum;
|
||||
import com.youlai.boot.system.mapper.NoticeMapper;
|
||||
import com.youlai.boot.system.model.bo.NoticeBO;
|
||||
import com.youlai.boot.system.model.dto.NoticeDTO;
|
||||
@@ -95,7 +94,7 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
@Override
|
||||
public boolean saveNotice(NoticeForm formData) {
|
||||
|
||||
if (NoticeTargetTypeEnum.SPECIFIED.getValue().equals(formData.getTargetType())) {
|
||||
if (NoticeTargetEnum.SPECIFIED.getValue().equals(formData.getTargetType())) {
|
||||
List<String> targetUserIdList = formData.getTargetUserIds();
|
||||
if (CollectionUtil.isEmpty(targetUserIdList)) {
|
||||
throw new BusinessException("推送指定用户不能为空");
|
||||
@@ -115,7 +114,7 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
*/
|
||||
@Override
|
||||
public boolean updateNotice(Long id, NoticeForm formData) {
|
||||
if (NoticeTargetTypeEnum.SPECIFIED.getValue().equals(formData.getTargetType())) {
|
||||
if (NoticeTargetEnum.SPECIFIED.getValue().equals(formData.getTargetType())) {
|
||||
List<String> targetUserIdList = formData.getTargetUserIds();
|
||||
if (CollectionUtil.isEmpty(targetUserIdList)) {
|
||||
throw new BusinessException("推送指定用户不能为空");
|
||||
@@ -140,7 +139,7 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
}
|
||||
|
||||
// 逻辑删除
|
||||
List<Long> idList = Arrays.stream(ids.split(SymbolConstant.COMMA))
|
||||
List<Long> idList = Arrays.stream(ids.split(","))
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
boolean isRemoved = this.removeByIds(idList);
|
||||
@@ -171,7 +170,7 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
|
||||
Integer targetType = notice.getTargetType();
|
||||
String targetUserIds = notice.getTargetUserIds();
|
||||
if (NoticeTargetTypeEnum.SPECIFIED.getValue().equals(targetType)
|
||||
if (NoticeTargetEnum.SPECIFIED.getValue().equals(targetType)
|
||||
&& StrUtil.isBlank(targetUserIds)) {
|
||||
throw new BusinessException("推送指定用户不能为空");
|
||||
}
|
||||
@@ -189,7 +188,7 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
|
||||
// 添加新的用户通知数据
|
||||
List<String> targetUserIdList = null;
|
||||
if (NoticeTargetTypeEnum.SPECIFIED.getValue().equals(targetType)) {
|
||||
if (NoticeTargetEnum.SPECIFIED.getValue().equals(targetType)) {
|
||||
targetUserIdList = Arrays.asList(targetUserIds.split(","));
|
||||
}
|
||||
|
||||
@@ -197,7 +196,7 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
new LambdaQueryWrapper<User>()
|
||||
// 如果是指定用户,则筛选出指定用户
|
||||
.in(
|
||||
NoticeTargetTypeEnum.SPECIFIED.getValue().equals(targetType),
|
||||
NoticeTargetEnum.SPECIFIED.getValue().equals(targetType),
|
||||
User::getId,
|
||||
targetUserIdList
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user