| | |
| | | */ |
| | | List<ToEquipmentTask> selectTaskSyncFlag(Integer syncFlag); |
| | | |
| | | /** |
| | | * 通过文件名称与状态确定是否可以删除 |
| | | * @param filePath,fileEncodeName,yncFlag |
| | | * @return |
| | | */ |
| | | List<ToEquipmentTask> selectTaskByNameAndSyncFlag(String filePath,String fileEncodeName,Integer syncFlag); |
| | | |
| | | } |
| | |
| | | import com.lxzn.nc.service.IDeviceInfoService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.security.core.parameters.P; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | public class ToEquipmentTaskServiceImpl extends ServiceImpl<ToEquipmentTaskMapper, ToEquipmentTask> implements IToEquipmentTaskService { |
| | |
| | | private IDeviceInfoService deviceInfoService; |
| | | @Autowired |
| | | private IDeviceGroupService deviceGroupService; |
| | | @Value("${fileNcGateway}") |
| | | private String fileNcGateway; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | @Scheduled(cron = "${taskSync}") |
| | | public void updateNcFileFromTask() { |
| | | List<ToEquipmentTask> taskList = this.selectTaskSyncFlag(1); |
| | | if (taskList == null || taskList.isEmpty()) { |
| | | List<ToEquipmentTask> list = selectTaskSyncFlag(1); |
| | | if(list == null || list.isEmpty()) { |
| | | return; |
| | | } |
| | | List<ToEquipmentTask> successTasks = new ArrayList<>(); |
| | | |
| | | for (ToEquipmentTask task : taskList) { |
| | | for (ToEquipmentTask task : list) { |
| | | //获取文件夹位置 |
| | | DeviceInfo deviceInfo = deviceInfoService.getByDeviceNo(task.getDeviceNo()); |
| | | if (deviceInfo == null) { |
| | | if(deviceInfo == null) { |
| | | continue; |
| | | } |
| | | List<String> pathList = deviceGroupService.findListParentTreeAll(deviceInfo.getGroupId()); |
| | | if (pathList == null || pathList.isEmpty()) { |
| | | List<String> strings = deviceGroupService.findListParentTreeAll(deviceInfo.getGroupId()); |
| | | if (strings == null || strings.isEmpty()) { |
| | | continue; |
| | | } |
| | | String targetPath = StringUtils.join(pathList.toArray(), "/") |
| | | + "/" + deviceInfo.getDeviceNo() |
| | | + "/send/" |
| | | + task.getFileName(); |
| | | String sourceFilePath = task.getFilePath() + "/" + task.getFileEncodeName(); |
| | | Boolean copySuccess = FileUtil.copyFileUpName(sourceFilePath, targetPath, task.getFileSuffix()); |
| | | if (copySuccess) { |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | Boolean b = FileUtil.copyFileUpName(task.getFilePath() + "/" + task.getFileEncodeName(), |
| | | fileNcGateway +"/" + path +"/" + task.getDeviceNo() + "/send/" + task.getFileName(),task.getFileSuffix()); |
| | | if (b) { |
| | | task.setSyncFlag(2); |
| | | successTasks.add(task); |
| | | } |
| | | } |
| | | if (!successTasks.isEmpty()) { |
| | | super.saveOrUpdateBatch(successTasks); |
| | | } |
| | | deleteSourceFilesAfterBatchUpdate(taskList); |
| | | } |
| | | |
| | | /** |
| | | * 批量更新后检查并删除源文件 |
| | | */ |
| | | private void deleteSourceFilesAfterBatchUpdate(List<ToEquipmentTask> allTasks) { |
| | | Map<String, String> filePathMap = new HashMap<>(); |
| | | |
| | | for (ToEquipmentTask task : allTasks) { |
| | | if (task.getSyncFlag() == 2) { |
| | | String key = task.getFilePath() + "_" + task.getFileEncodeName(); |
| | | if (!filePathMap.containsKey(key)) { |
| | | filePathMap.put(key, task.getFilePath() + "/" + task.getFileEncodeName()); |
| | | } |
| | | } |
| | | } |
| | | for (Map.Entry<String, String> entry : filePathMap.entrySet()) { |
| | | String[] parts = entry.getKey().split("_"); |
| | | if (parts.length >= 2) { |
| | | String filePath = parts[0]; |
| | | String fileEncodeName = parts[1]; |
| | | List<ToEquipmentTask> remainingTasks = this.selectTaskByNameAndSyncFlag( |
| | | filePath, |
| | | fileEncodeName, |
| | | 1 |
| | | ); |
| | | if (remainingTasks == null || remainingTasks.isEmpty()) { |
| | | FileUtil.deleteNcFile(entry.getValue()); |
| | | } |
| | | } |
| | | } |
| | | super.saveOrUpdateBatch(list); |
| | | } |
| | | |
| | | @Override |
| | | public List<ToEquipmentTask> selectTaskSyncFlag(Integer syncFlag) { |
| | | if (!ValidateUtil.validateInteger(syncFlag)) { |
| | | if(!ValidateUtil.validateInteger(syncFlag)) { |
| | | return null; |
| | | } |
| | | return super.lambdaQuery() |
| | | .eq(ToEquipmentTask::getSyncFlag, syncFlag) |
| | | .list(); |
| | | } |
| | | |
| | | @Override |
| | | public List<ToEquipmentTask> selectTaskByNameAndSyncFlag(String filePath, String fileEncodeName, Integer syncFlag) { |
| | | if (!ValidateUtil.validateInteger(syncFlag) |
| | | || !ValidateUtil.validateString(filePath) |
| | | || !ValidateUtil.validateString(fileEncodeName)) { |
| | | List<ToEquipmentTask> list = super.lambdaQuery().eq(ToEquipmentTask::getSyncFlag, syncFlag).list(); |
| | | /* List<ToEquipmentTask> list = new ArrayList<>(); |
| | | ToEquipmentTask t = getById("1800797949617278977"); |
| | | list.add(t);*/ |
| | | if(list == null || list.isEmpty()) { |
| | | return null; |
| | | } |
| | | return super.lambdaQuery() |
| | | .eq(ToEquipmentTask::getSyncFlag, syncFlag) |
| | | .eq(ToEquipmentTask::getFilePath, filePath) |
| | | .eq(ToEquipmentTask::getFileEncodeName, fileEncodeName) |
| | | .list(); |
| | | return list; |
| | | } |
| | | } |
| | |
| | | PdmProgramSource source = new PdmProgramSource(); |
| | | try { |
| | | Object[] objects = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"",""}; |
| | | String program = "{\"code\":1,\"message\":\"\",\"response\":[{\"skgx_id\":\"CX信息中心10000070\",\"skgx_rev_id\":\"1\",\"skgx_name\":\"焊接数控程序\",\"sqzt\":\"S状态\",\"ae8nc_cxno\":\"CX信息中心10000070\",\"ae8nc_gfrev\":\"1\",\"ae8nc_sbno\":\"2240080\",\"ae8nc_jcid\":\"QJK006\",\"ae8nc_os\":\"华中数控-HNC848C\",\"ae8nc_filename\":\"107052PA5\",\"ae8nc_cxfz\":\"计算机仿真\",\"ae8nc_operator\":\"\",\"ae8nc_inspect\":\"\",\"ae8nc_acceptview\":\"\",\"ae8nc_cxno_unit\":\"信息中心\",\"ae8nc_filename_unit\":\"PA\",\"ae8gallery\":\"\",\"ae8nc_plant\":\"信息中心\",\"ae8nc_modelno\":\"jx\",\"ae8nc_batchno\":\"\",\"meop_id\":\"OPHJ000000000049108\",\"meop_rev_id\":\"A\",\"meop_name\":\"焊接\",\"meop_type\":\"AE8Operation Revision\",\"ae8gx_no\":\"5\",\"process_id\":\"JZG2022008107653\",\"process_rev_id\":\"1\",\"process_name\":\"107052\",\"ae8part_no\":\"107052\",\"ae8stageidentifying\":\"L\",\"ae8gy_type\":\"机加工艺设计\",\"ae8plant\":\"信息中心\",\"part_id\":\"1047051\",\"part_rev_id\":\"01\",\"part_name\":\"集成测试件\",\"create_by\":\"用户2(user2)\",\"create_date\":\"02-9月-22 17:15:14\",\"filename\":\"DNC-CX信息中心10000070-1.zip\",\"filepath\":\"http://localhost:9099/outer/test/download.xhtml\"}]}\n"; |
| | | //String program =pdmWebClientApi.queryNcProgramAttrInfo(objects); |
| | | //String program = "{\"code\":1,\"message\":\"\",\"response\":[{\"skgx_id\":\"CX信息中心10000070\",\"skgx_rev_id\":\"1\",\"skgx_name\":\"焊接数控程序\",\"sqzt\":\"S状态\",\"ae8nc_cxno\":\"CX信息中心10000070\",\"ae8nc_gfrev\":\"1\",\"ae8nc_sbno\":\"2240080\",\"ae8nc_jcid\":\"QJK006\",\"ae8nc_os\":\"华中数控-HNC848C\",\"ae8nc_filename\":\"107052PA5\",\"ae8nc_cxfz\":\"计算机仿真\",\"ae8nc_operator\":\"\",\"ae8nc_inspect\":\"\",\"ae8nc_acceptview\":\"\",\"ae8nc_cxno_unit\":\"信息中心\",\"ae8nc_filename_unit\":\"PA\",\"ae8gallery\":\"\",\"ae8nc_plant\":\"信息中心\",\"ae8nc_modelno\":\"jx\",\"ae8nc_batchno\":\"\",\"meop_id\":\"OPHJ000000000049108\",\"meop_rev_id\":\"A\",\"meop_name\":\"焊接\",\"meop_type\":\"AE8Operation Revision\",\"ae8gx_no\":\"5\",\"process_id\":\"JZG2022008107653\",\"process_rev_id\":\"1\",\"process_name\":\"107052\",\"ae8part_no\":\"107052\",\"ae8stageidentifying\":\"L\",\"ae8gy_type\":\"机加工艺设计\",\"ae8plant\":\"信息中心\",\"part_id\":\"1047051\",\"part_rev_id\":\"01\",\"part_name\":\"集成测试件\",\"create_by\":\"用户2(user2)\",\"create_date\":\"02-9月-22 17:15:14\",\"filename\":\"DNC-CX信息中心10000070-1.zip\",\"filepath\":\"http://localhost:9099/outer/test/download.xhtml\"}]}\n"; |
| | | String program =pdmWebClientApi.queryNcProgramAttrInfo(objects); |
| | | if (StringUtils.isEmpty(program)) { |
| | | log.error("======= 无 "+ ncLog.getSkgxId() +" 新增记录======="); |
| | | return false; |