package org.jeecg.modules.dncFlow.service.impl; import org.apache.shiro.SecurityUtils; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.modules.dnc.entity.DeviceType; import org.jeecg.modules.dnc.entity.PermissionStreamNew; import org.jeecg.modules.dnc.exception.ExceptionCast; import org.jeecg.modules.dnc.response.ActivitiCode; import org.jeecg.modules.dnc.service.IDeviceTypeService; import org.jeecg.modules.dncFlow.adapter.AssignEquipmentFileStreamAdapter; import org.jeecg.modules.dncFlow.adapter.AssignFileStreamAdapter; import org.jeecg.modules.dncFlow.adapter.DispatchFileAdapter; import org.jeecg.modules.dncFlow.entity.AssignEquipmentFileStream; import org.jeecg.modules.dncFlow.entity.AssignFileStream; import org.jeecg.modules.dncFlow.entity.DispatchFile; import org.jeecg.modules.dncFlow.handler.*; import org.jeecg.modules.dncFlow.service.PermissionHandler; import org.jeecg.modules.dncFlow.service.StreamTarget; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class PermissionService { @Autowired private PermissionProcessor processor; @Autowired private ProductHandler productHandler; @Autowired private ComponentHandler componentHandler; @Autowired private PartsHandler partsHandler; @Autowired private ProcessSpecVersionHandle processSpecVersionHandler; @Autowired private ProcessHandle processHandler; @Autowired private WorkStepHandle workStepHandler; @Autowired private IDeviceTypeService deviceTypeService; public PermissionStreamNew getPermissionStreams(DispatchFile file) { return processInternal(new DispatchFileAdapter(file), file.getAttributionType()); } public PermissionStreamNew getPermissionStreams(AssignFileStream stream) { return processInternal(new AssignFileStreamAdapter(stream), stream.getAttributionType()); } public PermissionStreamNew getPermissionStreams(AssignEquipmentFileStream stream) { return processInternal(new AssignEquipmentFileStreamAdapter(stream), stream.getAttributionType()); } private PermissionStreamNew processInternal(StreamTarget target, String attributionType) { LoginUser user = getCurrentUser(); String resolvedId = resolveAttributionId(target.getAttributionId()); PermissionHandler handler = resolveHandler(attributionType); return processor.process(resolvedId, user, target, handler); } private String resolveAttributionId(String AttributionId) { DeviceType deviceType = deviceTypeService.getById(AttributionId); if (deviceType == null) { return AttributionId; }else { return deviceType.getAttributionId(); } } private PermissionHandler resolveHandler(String type) { switch (type) { case "1": return productHandler; case "2": return componentHandler; case "3": return partsHandler; case "4": return processSpecVersionHandler; case "5": return processHandler; case "6": return workStepHandler; default: ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE); return null; // 实际不会执行 } } private LoginUser getCurrentUser() { return (LoginUser) SecurityUtils.getSubject().getPrincipal(); } }