|
@@ -4,17 +4,24 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.google.common.base.CaseFormat;
|
|
|
+import com.persagy.fm.common.model.RequiredParamsStorage;
|
|
|
import com.persagy.fm.common.model.dto.Sort;
|
|
|
+import com.persagy.fm.common.response.FmResponseContent;
|
|
|
+import com.persagy.fm.saas.account.constant.enums.AccountBelongEnum;
|
|
|
+import com.persagy.fm.saas.role.client.SaasRoleClient;
|
|
|
import com.persagy.fm.saas.role.model.ConvertSaasRoleTool;
|
|
|
import com.persagy.fm.saas.role.model.SaasRole;
|
|
|
import com.persagy.fm.saas.role.model.dto.AddSaasRoleDTO;
|
|
|
+import com.persagy.fm.saas.role.model.dto.DeleteSaasRoleDTO;
|
|
|
import com.persagy.fm.saas.role.model.dto.PageQuerySaasRoleDTO;
|
|
|
import com.persagy.fm.saas.role.model.dto.UpdateSaasRoleDTO;
|
|
|
import com.persagy.fm.saas.role.service.ISaasRoleService;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -25,6 +32,8 @@ import java.util.List;
|
|
|
*/
|
|
|
@Service
|
|
|
public class SaasRoleServiceImpl implements ISaasRoleService {
|
|
|
+ @Autowired
|
|
|
+ SaasRoleClient saasRoleClient;
|
|
|
|
|
|
/**
|
|
|
* 创建
|
|
@@ -38,7 +47,8 @@ public class SaasRoleServiceImpl implements ISaasRoleService {
|
|
|
SaasRole saasRole = ConvertSaasRoleTool.INSTANCE.convertAddDto2Entity(addSaasRoleDTO);
|
|
|
// 设置默认值
|
|
|
setDefaultValue(saasRole);
|
|
|
- return saasRole.getId();
|
|
|
+ FmResponseContent<String> response = saasRoleClient.createSaasRole(saasRole);
|
|
|
+ return response.getContent();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -49,27 +59,12 @@ public class SaasRoleServiceImpl implements ISaasRoleService {
|
|
|
* @version V1.0 2021/3/12 12:29 下午
|
|
|
*/
|
|
|
private void setDefaultValue(SaasRole saasRole) {
|
|
|
- // todo 其他默认的属性
|
|
|
-
|
|
|
+ saasRole.setAccountBelong(AccountBelongEnum.BUSINESS.getType());
|
|
|
+ saasRole.setAppId(RequiredParamsStorage.getAppId());
|
|
|
+ saasRole.setGroupCode(RequiredParamsStorage.getGroupCode());
|
|
|
+ saasRole.setRoleCode(String.valueOf(System.currentTimeMillis()));
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * 详情
|
|
|
-// *
|
|
|
-// * @param id 主键
|
|
|
-// * @return 部门do类
|
|
|
-// * @author lixing
|
|
|
-// * @version V1.0 2021-03-22 19:04:17
|
|
|
-// */
|
|
|
-// @Override
|
|
|
-// public SaasRole querySaasRoleDetail(String id) {
|
|
|
-// SaasRole saasRole = null;
|
|
|
-// if (saasRole == null) {
|
|
|
-// throw new IllegalArgumentException("查看SaasRole详情时发生异常,找不到要查看的记录,id=" + id);
|
|
|
-// }
|
|
|
-// return saasRole;
|
|
|
-// }
|
|
|
-
|
|
|
/**
|
|
|
* 更新
|
|
|
*
|
|
@@ -78,8 +73,33 @@ public class SaasRoleServiceImpl implements ISaasRoleService {
|
|
|
*/
|
|
|
@Override
|
|
|
public void updateSaasRole(UpdateSaasRoleDTO updateSaasRoleDTO) {
|
|
|
- SaasRole saasRole = null;
|
|
|
+ // 查询要更新的对象
|
|
|
+ SaasRole saasRole = getSaasRole(updateSaasRoleDTO.getId());
|
|
|
+ if (saasRole == null) {
|
|
|
+ throw new IllegalArgumentException("找不到要更新的数据,id: " + updateSaasRoleDTO.getId());
|
|
|
+ }
|
|
|
+ // 将更新的属性赋值给查询到的对象
|
|
|
saasRole = ConvertSaasRoleTool.INSTANCE.convertUpdateDto2Entity(saasRole, updateSaasRoleDTO);
|
|
|
+
|
|
|
+ saasRoleClient.updateSaasRole(saasRole);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取运维平台角色对象
|
|
|
+ *
|
|
|
+ * @param roleId 角色id
|
|
|
+ * @return 角色对象
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/3/24 3:47 下午
|
|
|
+ */
|
|
|
+ private SaasRole getSaasRole(String roleId) {
|
|
|
+ PageQuerySaasRoleDTO pageQuerySaasRoleDTO = new PageQuerySaasRoleDTO();
|
|
|
+ pageQuerySaasRoleDTO.setId(roleId);
|
|
|
+ FmResponseContent<List<SaasRole>> listFmResponseContent = saasRoleClient.queryRolePageList(pageQuerySaasRoleDTO);
|
|
|
+ if (listFmResponseContent.getCount() <= 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return listFmResponseContent.getContent().get(0);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -95,7 +115,7 @@ public class SaasRoleServiceImpl implements ISaasRoleService {
|
|
|
throw new IllegalArgumentException("删除SaasRole时发生异常,主键为空");
|
|
|
}
|
|
|
|
|
|
- SaasRole saasRole = null;
|
|
|
+ SaasRole saasRole = getSaasRole(id);
|
|
|
|
|
|
if (saasRole == null) {
|
|
|
throw new IllegalArgumentException("删除SaasRole时发生异常,找不到要删除的数据,id:" + id);
|
|
@@ -114,8 +134,11 @@ public class SaasRoleServiceImpl implements ISaasRoleService {
|
|
|
@Override
|
|
|
public void deleteSaasRole(String id) {
|
|
|
// 校验是否可删除
|
|
|
- SaasRole saasRole = checkDeletable(id);
|
|
|
-
|
|
|
+ checkDeletable(id);
|
|
|
+ // 删除角色
|
|
|
+ DeleteSaasRoleDTO deleteSaasRoleDTO = new DeleteSaasRoleDTO();
|
|
|
+ deleteSaasRoleDTO.setId(id);
|
|
|
+ saasRoleClient.deleteSaasRole(deleteSaasRoleDTO);
|
|
|
}
|
|
|
|
|
|
// /**
|
|
@@ -181,27 +204,15 @@ public class SaasRoleServiceImpl implements ISaasRoleService {
|
|
|
*/
|
|
|
@Override
|
|
|
public IPage<SaasRole> pageQuerySaasRole(PageQuerySaasRoleDTO pageQuerySaasRoleDTO) {
|
|
|
- QueryWrapper<SaasRole> queryWrapper = new QueryWrapper<>();
|
|
|
- // 这里认为pageQueryDTO是经过校验的,肯定包含分页信息
|
|
|
- IPage<SaasRole> pageParam = new Page<>(pageQuerySaasRoleDTO.getPage(), pageQuerySaasRoleDTO.getSize(), true);
|
|
|
- // 排序信息
|
|
|
- if (!CollectionUtils.isEmpty(pageQuerySaasRoleDTO.getOrders())) {
|
|
|
- List<Sort> orders = pageQuerySaasRoleDTO.getOrders();
|
|
|
- for (Sort sort : orders) {
|
|
|
- // 将驼峰转换为下划线格式
|
|
|
- sort.setColumn(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, sort.getColumn()));
|
|
|
- queryWrapper.orderBy(true, sort.isAsc(), sort.getColumn());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQuerySaasRoleDTO.getRoleName())) {
|
|
|
- queryWrapper.like(SaasRole.PROP_ROLE_NAME, pageQuerySaasRoleDTO.getRoleName());
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQuerySaasRoleDTO.getRoleType())) {
|
|
|
- queryWrapper.eq(SaasRole.PROP_ROLE_TYPE, pageQuerySaasRoleDTO.getRoleType());
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
+ // 调用运维平台分页查询接口
|
|
|
+ FmResponseContent<List<SaasRole>> saasResponse = saasRoleClient.queryRolePageList(pageQuerySaasRoleDTO);
|
|
|
+ Integer count = saasResponse.getCount();
|
|
|
+ List<SaasRole> content = saasResponse.getContent();
|
|
|
+
|
|
|
+ // 将返回结果封装为IPage对象
|
|
|
+ IPage<SaasRole> result = new Page<>();
|
|
|
+ result.setRecords(content);
|
|
|
+ result.setTotal(Long.parseLong(count.toString()));
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|