| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.jeecg.modules.dnc.entity.ProductPermission; |
| | | import org.jeecg.modules.dnc.entity.*; |
| | | import org.jeecg.modules.dnc.exception.ExceptionCast; |
| | | import org.jeecg.modules.dnc.mapper.ProductPermissionMapper; |
| | | import org.jeecg.modules.dnc.response.CommonCode; |
| | | import org.jeecg.modules.dnc.service.*; |
| | | import org.jeecg.modules.dnc.ucenter.UserDepartExt; |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.system.entity.DncDevicePermission; |
| | | import org.jeecg.modules.system.entity.SysUser; |
| | | import org.jeecg.modules.dnc.service.IProductPermissionService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | |
| | | @Service |
| | | public class ProductPermissionServiceImpl extends ServiceImpl<ProductPermissionMapper, ProductPermission> implements IProductPermissionService { |
| | | @Autowired |
| | | private IComponentPermissionService componentPermissionService; |
| | | @Autowired |
| | | private IPartsPermissionService partsPermissionService; |
| | | @Autowired |
| | | private IProcessStreamPermissionService processStreamPermissionService; |
| | | @Autowired |
| | | private IWorkStepPermissionService workStepPermissionService; |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | @Override |
| | | public ProductPermission getByProductIdAndUserId(String productId, String userId) { |
| | | if(!ValidateUtil.validateString(productId) || !ValidateUtil.validateString(userId)) |
| | |
| | | list = Collections.emptyList(); |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 新增权限数据 |
| | | * @param id |
| | | * @param userId |
| | | * @param type |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean add(String id, String userId, String type) { |
| | | // 验证参数有效性 |
| | | if (!ValidateUtil.validateString(userId) || !ValidateUtil.validateString(id) || !ValidateUtil.validateString(type)) { |
| | | return false; |
| | | } |
| | | // 获取管理员用户 |
| | | SysUser adminUser = sysUserService.getUserByName("admin"); |
| | | try { |
| | | boolean isAdmin = userId.equals(adminUser.getId()); |
| | | savePermission(id, userId, type); |
| | | if (!isAdmin) { |
| | | savePermission(id, adminUser.getId(), type); |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | private void savePermission(String id, String userId, String type) { |
| | | switch (type) { |
| | | case "1": |
| | | // 组件权限 |
| | | super.save(new ProductPermission(id, userId)); |
| | | break; |
| | | case "2": |
| | | // 部件权限 |
| | | componentPermissionService.save(new ComponentPermission(id, userId)); |
| | | break; |
| | | case "3": |
| | | // 零件权限 |
| | | partsPermissionService.save(new PartsPermission(id, userId)); |
| | | break; |
| | | case "5": |
| | | // 工序权限 |
| | | processStreamPermissionService.save(new ProcessionPermission(id, userId)); |
| | | break; |
| | | case "6": |
| | | // 工序步骤权限 |
| | | workStepPermissionService.save(new WorkStepPermission(id, userId)); |
| | | break; |
| | | default: |
| | | // 处理未知类型 |
| | | throw new IllegalArgumentException("Unknown permission type: " + type); |
| | | } |
| | | } |
| | | |
| | | } |