package org.jeecg.modules.dnc.service.impl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.jeecg.modules.dnc.entity.ObjectButton;
|
import org.jeecg.modules.dnc.exception.ExceptionCast;
|
import org.jeecg.modules.dnc.mapper.ButtonMapper;
|
import org.jeecg.modules.dnc.response.CommonCode;
|
import org.jeecg.modules.dnc.response.QueryPageResponseResult;
|
import org.jeecg.modules.dnc.service.IButtonPermissionService;
|
import org.jeecg.modules.dnc.service.IButtonService;
|
import org.jeecg.modules.dnc.utils.ValidateUtil;
|
import org.jeecg.modules.dnc.entity.Button;
|
import org.jeecg.modules.dnc.entity.ButtonPermission;
|
import org.jeecg.modules.dnc.entity.MenuButton;
|
import org.jeecg.modules.dnc.service.IMenuButtonService;
|
import org.jeecg.modules.dnc.request.ButtonRequest;
|
import org.jeecg.modules.dnc.response.ButtonCode;
|
import org.jeecg.modules.dnc.service.IObjectButtonService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.List;
|
import java.util.Map;
|
|
@Service
|
public class ButtonServiceImpl extends ServiceImpl<ButtonMapper, Button> implements IButtonService {
|
@Autowired
|
private IButtonPermissionService buttonPermissionService;
|
@Autowired
|
private IMenuButtonService menuButtonService;
|
@Autowired
|
private IObjectButtonService objectButtonService;
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean addButton(Button button) {
|
if(button == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(!ValidateUtil.validateString(button.getButtonPerm()))
|
ExceptionCast.cast(ButtonCode.BTN_PERM_CODE_NONE);
|
if(!ValidateUtil.validateString(button.getButtonName()))
|
ExceptionCast.cast(ButtonCode.BTN_NAME_NONE);
|
if(!ValidateUtil.validateInteger(button.getButtonType()))
|
ExceptionCast.cast(ButtonCode.BTN_TYPE_NONE);
|
Button en = getByPermCode(button.getButtonPerm());
|
if(en != null)
|
ExceptionCast.cast(ButtonCode.BTN_PERM_CODE_EXIST);
|
return super.save(button);
|
}
|
|
@Override
|
public Button getByPermCode(String permCode){
|
if(!ValidateUtil.validateString(permCode))
|
return null;
|
List<Button> list = super.lambdaQuery().eq(Button::getButtonPerm, permCode).list();
|
if(list == null || list.isEmpty())
|
return null;
|
return list.get(0);
|
}
|
|
@Override
|
public List<Button> findByButtonType(Integer buttonType) {
|
if(!ValidateUtil.validateInteger(buttonType))
|
return null;
|
return super.lambdaQuery().eq(Button::getButtonType, buttonType).list();
|
}
|
|
@Override
|
public QueryPageResponseResult<Button> findByPageList(int page, int size, ButtonRequest buttonRequest) {
|
if(page < 1 || size < 1) {
|
ExceptionCast.cast(CommonCode.INVALID_PAGE);
|
}
|
IPage<Button> pageData = new Page<>(page, size);
|
LambdaQueryChainWrapper<Button> lambdaQuery = super.lambdaQuery();
|
if(buttonRequest != null) {
|
if(ValidateUtil.validateString(buttonRequest.getButtonName())) {
|
lambdaQuery.like(Button::getButtonName, buttonRequest.getButtonName());
|
}
|
if(ValidateUtil.validateString(buttonRequest.getButtonPerm())) {
|
lambdaQuery.like(Button::getButtonPerm, buttonRequest.getButtonPerm());
|
}
|
if(ValidateUtil.validateInteger(buttonRequest.getButtonType())) {
|
lambdaQuery.eq(Button::getButtonType, buttonRequest.getButtonType());
|
}
|
if(ValidateUtil.validateString(buttonRequest.getAscStr())) {
|
String[] ascArr = buttonRequest.getAscStr().split(",");
|
// ((Page<Button>) pageData).setAsc(ascArr);
|
}
|
if(ValidateUtil.validateString(buttonRequest.getDescStr())) {
|
String[] descStr = buttonRequest.getDescStr().split(",");
|
// ((Page<Button>) pageData).setDesc(descStr);
|
}
|
}
|
IPage<Button> userIPage = lambdaQuery.page(pageData);
|
return new QueryPageResponseResult<>(CommonCode.SUCCESS, userIPage);
|
}
|
|
@Override
|
public List<Button> getButtonPerms(String userId) {
|
return this.getBaseMapper().getButtonPerms(userId);
|
}
|
|
@Override
|
public List<Button> getMenuButtonPerms(String userId, String menuUrl) {
|
return this.getBaseMapper().getMenuButtonPerms(userId, menuUrl);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public List<Button> getObjectButtonPerms(String userId, String objectPerm) {
|
return this.getBaseMapper().getObjectButtonPerms(userId, objectPerm);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean editButton(String id, Button button) {
|
if(!ValidateUtil.validateString(id) || button == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
button.setButtonId(id);
|
Button en = getByPermCode(button.getButtonPerm());
|
if(en != null && !en.getButtonId().equals(button.getButtonId())) {
|
ExceptionCast.cast(ButtonCode.BTN_PERM_CODE_EXIST);
|
}
|
return super.updateById(button);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean deleteButtonById(String id) {
|
if(!ValidateUtil.validateString(id)) {
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
}
|
Button button = super.getById(id);
|
if(button == null)
|
ExceptionCast.cast(ButtonCode.BTN_NOT_EXIST);
|
List<ButtonPermission> buttonPermissionList = buttonPermissionService.findByButtonId(id);
|
if(buttonPermissionList != null && !buttonPermissionList.isEmpty())
|
ExceptionCast.cast(ButtonCode.BTN_ROLE_EXIST);
|
List<MenuButton> menuButtonList = menuButtonService.findByButtonId(id);
|
if(menuButtonList != null && !menuButtonList.isEmpty())
|
ExceptionCast.cast(ButtonCode.BTN_MENU_EXIST);
|
List<ObjectButton> objectButtonList = objectButtonService.findByButtonId(id);
|
if(objectButtonList != null && !objectButtonList.isEmpty())
|
ExceptionCast.cast(ButtonCode.BTN_OBJ_EXIST);
|
return super.removeById(id);
|
}
|
|
@Override
|
public List<Button> findPermsByRoleId(String roleId) {
|
if(!ValidateUtil.validateString(roleId))
|
return null;
|
List<Button> list = findByButtonType(1);
|
if(list == null || list.isEmpty())
|
return null;
|
Map<String, ButtonPermission> map = buttonPermissionService.getMapByRoleId(roleId);
|
if(map == null || map.isEmpty())
|
return list;
|
list.forEach(item -> {
|
if(map.containsKey(item.getButtonId())) {
|
item.setChecked(true);
|
}
|
});
|
return list;
|
}
|
|
@Override
|
public List<Button> findByMenuId(String menuId) {
|
if(!ValidateUtil.validateString(menuId))
|
return null;
|
List<Button> list = findByButtonType(2);
|
if(list == null || list.isEmpty())
|
return null;
|
Map<String, MenuButton> map = menuButtonService.getMapByMenuId(menuId);
|
if(map == null || map.isEmpty())
|
return list;
|
list.forEach(item -> {
|
if(map.containsKey(item.getButtonId())) {
|
item.setChecked(true);
|
item.setButtonAlias(map.get(item.getButtonId()).getButtonAlias());
|
item.setPermCode(map.get(item.getButtonId()).getPermCode());
|
}
|
});
|
return list;
|
}
|
|
@Override
|
public List<Button> findByObjectId(String objectId) {
|
if(!ValidateUtil.validateString(objectId))
|
return null;
|
List<Button> list = findByButtonType(2);
|
if(list == null || list.isEmpty())
|
return null;
|
Map<String, ObjectButton> map = objectButtonService.getMapByObjectId(objectId);
|
if(map == null || map.isEmpty())
|
return list;
|
list.forEach(item -> {
|
if(map.containsKey(item.getButtonId())) {
|
item.setChecked(true);
|
item.setButtonAlias(map.get(item.getButtonId()).getButtonAlias());
|
item.setPermCode(map.get(item.getButtonId()).getPermCode());
|
}
|
});
|
return list;
|
}
|
|
}
|