|
@@ -0,0 +1,170 @@
|
|
|
+package com.lantone.security.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.lantone.common.util.DateUtil;
|
|
|
+import com.lantone.common.util.ListUtil;
|
|
|
+import com.lantone.common.util.StringUtil;
|
|
|
+import com.lantone.dblayermbg.entity.DataAuth;
|
|
|
+import com.lantone.dblayermbg.entity.DataAuthDetail;
|
|
|
+import com.lantone.dblayermbg.entity.Role;
|
|
|
+import com.lantone.dblayermbg.entity.RoleServiceDataAuth;
|
|
|
+import com.lantone.dblayermbg.entity.ServiceDataAuth;
|
|
|
+import com.lantone.dblayermbg.facade.DataAuthDetailFacade;
|
|
|
+import com.lantone.dblayermbg.facade.DataAuthFacade;
|
|
|
+import com.lantone.dblayermbg.facade.RoleServiceDataAuthFacade;
|
|
|
+import com.lantone.dblayermbg.facade.ServiceDataAuthFacade;
|
|
|
+import com.lantone.dblayermbg.service.impl.DataAuthServiceImpl;
|
|
|
+import com.lantone.security.enums.CRUDEnum;
|
|
|
+import com.lantone.security.util.SysUserUtils;
|
|
|
+import com.lantone.security.vo.ServiceDataAuthVO;
|
|
|
+import com.lantone.security.vo.SysServiceVO;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ClassName: DataAuthHandleFacade
|
|
|
+ * @Description:数据权限操作facade
|
|
|
+ * @Author songxl
|
|
|
+ * @Date 2021/7/21
|
|
|
+ * @Version 1.0
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class DataAuthHandleFacade extends DataAuthServiceImpl {
|
|
|
+ @Autowired
|
|
|
+ private DataAuthFacade dataAuthFacade;
|
|
|
+ @Autowired
|
|
|
+ private ServiceDataAuthFacade serviceDataAuthFacade;
|
|
|
+ @Autowired
|
|
|
+ private RoleServiceDataAuthFacade roleServiceDataAuthFacade;
|
|
|
+ @Autowired
|
|
|
+ private DataAuthDetailFacade dataAuthDetailFacade;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author songxl
|
|
|
+ * @Description 数据权限新增or修改方法
|
|
|
+ * @Date 2021/7/21
|
|
|
+ * @Param [serviceDataAuthVO]
|
|
|
+ * @Return void
|
|
|
+ * @MethodName addOrUpdate
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void addOrUpdate(ServiceDataAuthVO serviceDataAuthVO) {
|
|
|
+ //1.入参校验
|
|
|
+ inputParamCheck(serviceDataAuthVO);
|
|
|
+ //2.执行增加、修改操作
|
|
|
+ if (CRUDEnum.ADD.getKey() == serviceDataAuthVO.getType()) {
|
|
|
+ try {
|
|
|
+ addDataAuth(serviceDataAuthVO);
|
|
|
+ }catch (Exception e)
|
|
|
+ {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ } else if (CRUDEnum.UPDATE.getKey() == serviceDataAuthVO.getType()) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "操作码错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author songxl
|
|
|
+ * @Description 添加数据权限
|
|
|
+ * @Date 2021/7/21
|
|
|
+ * @Param [serviceDataAuthVO]
|
|
|
+ * @Return void
|
|
|
+ * @MethodName addDataAuth
|
|
|
+ */
|
|
|
+ private void addDataAuth(ServiceDataAuthVO serviceDataAuthVO) {
|
|
|
+ //1.插入新建数据权限
|
|
|
+ DataAuth dataAuth = new DataAuth();
|
|
|
+ dataAuth.setCreateTime(DateUtil.now());
|
|
|
+ dataAuth.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
|
|
|
+ BeanUtils.copyProperties(dataAuth, serviceDataAuthVO.getDataAuthVO());
|
|
|
+ boolean dataAuthInsert = dataAuthFacade.save(dataAuth);
|
|
|
+ if (dataAuthInsert) {
|
|
|
+ //2.插入成功获取新生成的数据权限名称编号data_auth_id
|
|
|
+ Long dataAuthId = dataAuthFacade.list(new QueryWrapper<DataAuth>()
|
|
|
+ .eq("auth_name", dataAuth.getAuthName())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())).get(0).getId();
|
|
|
+
|
|
|
+ //3.插入新建数据权限与系统的关系
|
|
|
+ for (SysServiceVO sysServiceVO : serviceDataAuthVO.getDataAuthVO().getServiceVOS()) {
|
|
|
+ ServiceDataAuth serviceDataAuth = new ServiceDataAuth();
|
|
|
+ serviceDataAuth.setServiceId(sysServiceVO.getId());
|
|
|
+ serviceDataAuth.setDataAuthId(dataAuthId);
|
|
|
+ serviceDataAuth.setCreateTime(DateUtil.now());
|
|
|
+ serviceDataAuth.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
|
|
|
+ boolean serviceDataAuthInsert = serviceDataAuthFacade.save(serviceDataAuth);
|
|
|
+ if (serviceDataAuthInsert) {
|
|
|
+ //4.获取上一步插入时新生成的数据权限名称与系统关联编号service_data_auth _id
|
|
|
+ Long serviceDataAuthId = serviceDataAuthFacade.list(new QueryWrapper<ServiceDataAuth>()
|
|
|
+ .eq("service_id", sysServiceVO.getId())
|
|
|
+ .eq("data_auth_id", dataAuthId)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())).get(0).getId();
|
|
|
+
|
|
|
+ //5.插入数据权限系统关联表与角色管理sys_role_service_data_auth
|
|
|
+ for(Role role:serviceDataAuthVO.getRoles()){
|
|
|
+ RoleServiceDataAuth roleServiceDataAuth = new RoleServiceDataAuth();
|
|
|
+ roleServiceDataAuth.setRoleId(role.getId());
|
|
|
+ roleServiceDataAuth.setServiceDataAuthId(serviceDataAuthId);
|
|
|
+ roleServiceDataAuth.setCreateTime(DateUtil.now());
|
|
|
+ roleServiceDataAuth.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
|
|
|
+ if(!roleServiceDataAuthFacade.save(roleServiceDataAuth)){
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "角色对应服务数据权限关系插入失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //6.插入数据权限详细信息。sys_data_auth_detail
|
|
|
+ for(DataAuthDetail dataAuthDetail:sysServiceVO.getDataAuthDetailVOS()){
|
|
|
+ dataAuthDetail.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
|
|
|
+ dataAuthDetail.setCreateTime(DateUtil.now());
|
|
|
+ dataAuthDetail.setServiceDataAuthId(serviceDataAuthId);
|
|
|
+ if(!dataAuthDetailFacade.save(dataAuthDetail)){
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "数据权限明细插入失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "服务对应数据权限关系插入失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "数据权限插入失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author songxl
|
|
|
+ * @Description 入参校验
|
|
|
+ * @Date 2021/7/21
|
|
|
+ * @Param [serviceDataAuthVO]
|
|
|
+ * @Return void
|
|
|
+ * @MethodName inputParamCheck
|
|
|
+ */
|
|
|
+ private void inputParamCheck(ServiceDataAuthVO serviceDataAuthVO) {
|
|
|
+ if (serviceDataAuthVO == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "入参为空");
|
|
|
+ }
|
|
|
+ if (serviceDataAuthVO.getType() == 0) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "操作码为空");
|
|
|
+ }
|
|
|
+ if (StringUtil.isEmpty(serviceDataAuthVO.getDataAuthVO().getAuthName())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "数据权限名称为空");
|
|
|
+ }
|
|
|
+ if (ListUtil.isEmpty(serviceDataAuthVO.getDataAuthVO().getServiceVOS())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "数据权限对应系统未选择");
|
|
|
+ }
|
|
|
+ if (ListUtil.isEmpty(serviceDataAuthVO.getDataAuthVO().getServiceVOS().get(0).getDataAuthDetailVOS())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "系统对应数据权限明细未选择");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|