kongzy
2024-07-01 47a751cb301d05276ae5d75145d57b2d090fe4e1
src/main/java/com/nanometer/smartlab/service/BaseRoleServiceImpl.java
@@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * Created by johnny on 17/11/18.
@@ -79,12 +80,12 @@
    }
    @Transactional(propagation = Propagation.REQUIRED)
    public BaseRole getBaseRole(String id) {
    public BaseRole getBaseRole(Long id) {
        try {
            BaseRole baseRole = this.baseRoleDao.getBaseRole(id);
            List<BaseRolePage> baseRolePageList = this.baseRolePageService.getBaseRolePageList(id, null);
            if (baseRolePageList != null && baseRolePageList.size() > 0) {
                List<String> pageIdList = new ArrayList<String>();
                List<Long> pageIdList = new ArrayList<Long>();
                for (BaseRolePage baseRolePage : baseRolePageList) {
                    pageIdList.add(baseRolePage.getPageId());
                }
@@ -99,13 +100,13 @@
    }
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean isBaseRoleExist(String name, String editId) {
    public boolean isBaseRoleExist(String name, Long editId) {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            if (StringUtils.isNotBlank(name)) {
                params.put("name", name);
            }
            if (StringUtils.isNotBlank(editId)) {
            if (editId!=null) {
                params.put("editId", editId);
            }
            int count = this.baseRoleDao.getBaseRoleTotalCount(params);
@@ -119,21 +120,20 @@
    @Transactional(propagation = Propagation.REQUIRED)
    public BaseRole insertBaseRole(BaseRole baseRole) {
        try {
            if (baseRole.getId() == null) {
                baseRole.setId(IDUtils.uuid());
            }
            this.baseRoleDao.insertBaseRole(baseRole);
            if (baseRole.getPageIdList() != null) {
                BaseRolePage baseRolePage = null;
                for (String pageId : baseRole.getPageIdList()) {
                    baseRolePage = new BaseRolePage();
                    baseRolePage.setId(IDUtils.uuid());
                List<Long> pageIdList=baseRole.getPageIdList();
                List<BaseRolePage> baseRolePages=new ArrayList<>();
                for(int i=0;i<pageIdList.size();i++){
                    //前端id被处理成了字符串,映射到后台变成了char,进行数据强转
                    Long pageId = Long.valueOf(((Object) pageIdList.get(i)).toString());
                    BaseRolePage baseRolePage = new BaseRolePage();
                    baseRolePage.setRoleId(baseRole.getId());
                    baseRolePage.setPageId(pageId);
                    this.baseRolePageService.insertBaseRolePage(baseRolePage);
                    baseRolePages.add(baseRolePage);
                }
                this.baseRolePageService.batchInsertBaseRolePage(baseRolePages);
            }
            return baseRole;
        } catch (DuplicateKeyException ex) {
            logger.warn(ex.getMessage(), ex);
@@ -153,14 +153,17 @@
            int row = this.baseRoleDao.updateBaseRole(baseRole);
            this.baseRolePageService.deleteBaseRolePage(baseRole.getId());
            if (baseRole.getPageIdList() != null) {
                BaseRolePage baseRolePage = null;
                for (String pageId : baseRole.getPageIdList()) {
                    baseRolePage = new BaseRolePage();
                    baseRolePage.setId(IDUtils.uuid());
                List<Long> pageIdList=baseRole.getPageIdList();
                List<BaseRolePage> baseRolePages=new ArrayList<>();
                for(int i=0;i<pageIdList.size();i++){
                    //前端id被处理成了字符串,映射到后台变成了char,进行数据强转
                    Long pageId = Long.valueOf(((Object) pageIdList.get(i)).toString());
                    BaseRolePage baseRolePage = new BaseRolePage();
                    baseRolePage.setRoleId(baseRole.getId());
                    baseRolePage.setPageId(pageId);
                    this.baseRolePageService.insertBaseRolePage(baseRolePage);
                    baseRolePages.add(baseRolePage);
                }
                this.baseRolePageService.batchInsertBaseRolePage(baseRolePages);
            }
            if (row == 0) {
@@ -186,7 +189,7 @@
                return false;
            }
            List<String> ids = new ArrayList<String>();
            List<Long> ids = new ArrayList<Long>();
            for (BaseRole baseRole : baseRoleList) {
                ids.add(baseRole.getId());
            }
@@ -233,7 +236,7 @@
    }
    @Override
    public BaseRole getRoleByUserId(String id) {
    public BaseRole getRoleByUserId(Long id) {
        return baseRoleDao.getBaseRoleByUser(id);
    }
}