| | |
| | | package com.mes.hollow.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.mes.common.config.Const; |
| | | import com.mes.glassinfo.entity.GlassInfo; |
| | | import com.mes.glassinfo.service.GlassInfoService; |
| | | import com.mes.hollow.controller.HollowBigStorageCageController; |
| | | import com.mes.hollow.entity.HollowBigStorageCageDetails; |
| | | import com.mes.hollow.entity.HollowFormulaDetails; |
| | | import com.mes.hollow.entity.HollowGlassOutRelationInfo; |
| | | import com.mes.hollow.entity.HollowGlassRelationInfo; |
| | | import com.mes.hollow.entity.dto.*; |
| | | import com.mes.hollow.entity.request.HollowTaskRequest; |
| | | import com.mes.hollow.mapper.HollowGlassOutRelationInfoMapper; |
| | | import com.mes.hollow.service.HollowBigStorageCageDetailsService; |
| | | import com.mes.hollow.service.HollowFormulaDetailsService; |
| | | import com.mes.hollow.service.HollowGlassOutRelationInfoService; |
| | | import com.mes.hollow.service.HollowGlassRelationInfoService; |
| | | import com.mes.hollowqueue.entity.HollowGlassQueueInfo; |
| | | import com.mes.hollowqueue.service.HollowGlassQueueInfoService; |
| | | import com.mes.utils.Blank; |
| | | import com.mes.utils.RedisUtil; |
| | | import freemarker.template.Configuration; |
| | | import freemarker.template.Template; |
| | | import freemarker.template.TemplateException; |
| | | import freemarker.template.Version; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.io.*; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | HollowBigStorageCageDetailsService hollowBigStorageCageDetailsService; |
| | | @Resource |
| | | HollowGlassQueueInfoService hollowGlassQueueInfoService; |
| | | @Resource |
| | | HollowFormulaDetailsService hollowFormulaDetailsService; |
| | | @Resource |
| | | HollowGlassRelationInfoService hollowGlassRelationInfoService; |
| | | |
| | | @Resource |
| | | RedisUtil redisUtil; |
| | | |
| | | private static final int ID_RATIO = 10; |
| | | |
| | | @Override |
| | | public HollowGlassOutRelationInfo receiveTask(String flowCardId, int cell, int totalPairQuantity) { |
| | | return childrenTask(flowCardId,cell,totalPairQuantity,0); |
| | | public HollowGlassOutRelationInfo receiveTask(HollowTaskRequest request) { |
| | | return childrenTask(request, 0); |
| | | } |
| | | |
| | | @Override |
| | | public HollowGlassOutRelationInfo forceOutGlass(String flowCardId, int cell, int totalPairQuantity) { |
| | | return childrenTask(flowCardId,cell,totalPairQuantity,1); |
| | | public HollowGlassOutRelationInfo forceOutGlass(HollowTaskRequest request) { |
| | | return childrenTask(request, 1); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean dispatchHollowSwitch(Boolean flag) { |
| | | redisUtil.setCacheObject("dispatchHollowSwitch", flag); |
| | | return redisUtil.getCacheObject("dispatchHollowSwitch"); |
| | | return redisUtil.getCacheObject("dispatchHollowSwitch"); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> hollowTaskList(int cell) { |
| | | //查询任务表中本条线所有未完成的任务信息 |
| | | List<HollowGlassOutRelationInfo> list = this.list(new LambdaQueryWrapper<HollowGlassOutRelationInfo>() |
| | | .in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE) |
| | | .eq(HollowGlassOutRelationInfo::getCell, cell)); |
| | | if (CollectionUtil.isNotEmpty(list)) { |
| | | return list.stream().map(HollowGlassOutRelationInfo::getFlowCardId).collect(Collectors.toList()); |
| | | } |
| | | return new ArrayList<String>(); |
| | | } |
| | | |
| | | @Override |
| | | public List<HollowGlassQueueInfo> appointHollowTaskDetails(String flowCardId, int cell) { |
| | | //按照流程卡及路线,查找对应的任务信息 |
| | | HollowGlassOutRelationInfo hollowGlassOutRelationInfo = this.getOne(new LambdaQueryWrapper<HollowGlassOutRelationInfo>() |
| | | .in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE) |
| | | .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId) |
| | | .eq(HollowGlassOutRelationInfo::getCell, cell).last("limit 1")); |
| | | if (null == hollowGlassOutRelationInfo) { |
| | | return new ArrayList<HollowGlassQueueInfo>(); |
| | | } |
| | | //按照任务id查询对列表中的队列信息 |
| | | return hollowGlassQueueInfoService.list(new LambdaQueryWrapper<HollowGlassQueueInfo>() |
| | | .eq(HollowGlassQueueInfo::getRelationId, hollowGlassOutRelationInfo.getId())); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean startTask(String flowCardId, int cell) { |
| | | //更新任务状态为开始 |
| | | return this.update(new LambdaUpdateWrapper<HollowGlassOutRelationInfo>() |
| | | .set(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_START) |
| | | .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId) |
| | | .eq(HollowGlassOutRelationInfo::getCell, cell)); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean pauseTask(String flowCardId, int cell) { |
| | | // 更新任务状态为暂停 |
| | | return this.update(new LambdaUpdateWrapper<HollowGlassOutRelationInfo>() |
| | | .set(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_PAUSE) |
| | | .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId) |
| | | .eq(HollowGlassOutRelationInfo::getCell, cell)); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean finishTask(String flowCardId, int cell) { |
| | | //清空队列表中未完成的玻璃信息 |
| | | hollowGlassQueueInfoService.remove(new LambdaQueryWrapper<HollowGlassQueueInfo>() |
| | | .in(HollowGlassQueueInfo::getState, Const.TEMPERING_NEW) |
| | | .eq(HollowGlassQueueInfo::getFlowCardId, flowCardId) |
| | | .eq(HollowGlassQueueInfo::getCell, cell)); |
| | | //更新任务状态未已完成 |
| | | return this.update(new LambdaUpdateWrapper<HollowGlassOutRelationInfo>() |
| | | .set(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_SUCCESS) |
| | | .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId) |
| | | .eq(HollowGlassOutRelationInfo::getCell, cell)); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean deleteHollowTaskDetails(String flowCardId, int cell) { |
| | | //按照流程卡及路线,查找对应的任务信息 |
| | | this.remove(new LambdaQueryWrapper<HollowGlassOutRelationInfo>() |
| | | .in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE) |
| | | .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId) |
| | | .eq(HollowGlassOutRelationInfo::getCell, cell)); |
| | | hollowGlassQueueInfoService.remove(new LambdaQueryWrapper<HollowGlassQueueInfo>() |
| | | .in(HollowGlassQueueInfo::getState, Const.TEMPERING_NEW) |
| | | .eq(HollowGlassQueueInfo::getFlowCardId, flowCardId) |
| | | .eq(HollowGlassQueueInfo::getCell, cell)); |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | | @Override |
| | | public String generateHollowLisecFile(String flowCardId, int cell, int isForce) throws IOException { |
| | | List<HollowGlassOutRelationInfo> outRelationList = this.list(new LambdaQueryWrapper<HollowGlassOutRelationInfo>() |
| | | .in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE) |
| | | .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId) |
| | | .eq(HollowGlassOutRelationInfo::getCell, cell)); |
| | | if (CollectionUtil.isEmpty(outRelationList) || outRelationList.size() != 1) { |
| | | return "本条线不存在该流程任务或者同流程卡任务数大于1"; |
| | | } |
| | | HollowGlassOutRelationInfo relationInfo = outRelationList.get(0); |
| | | if (relationInfo.getTotalLayer() < 2) { |
| | | return "任务总层数小于2,不生成李赛克文件"; |
| | | } |
| | | //获取订单相关信息 |
| | | OrderDTO order = baseMapper.queryOrderByFlowCardId(flowCardId); |
| | | if (null == order) { |
| | | return "生成失败,相关订单信息不存在"; |
| | | } |
| | | //获取配方相关信息 |
| | | HollowFormulaDetails formulaDetails = hollowFormulaDetailsService.getById(relationInfo.getFormulaId()); |
| | | if (null == formulaDetails) { |
| | | return "生成失败,相关配方信息不存在"; |
| | | } |
| | | //总层数是否与进笼关系表内层数数量相同,层数相同生成继续,不同结束 |
| | | int layerCount = hollowGlassRelationInfoService.queryLayerByFlowCardId(flowCardId); |
| | | if (layerCount != relationInfo.getTotalLayer() && isForce == 0) { |
| | | return "生成失败,该流程卡内层数与进笼关系表内层数数量不相同"; |
| | | } |
| | | //设置文件的主体内容 |
| | | LisecHollowDetails details = new LisecHollowDetails(); |
| | | String randomNumber = "" + (int) (Math.random() * 100000 + 100000); |
| | | details.setBcdStart(randomNumber); |
| | | details.setBatchNo(randomNumber); |
| | | details.setOrd(relationInfo.getFlowCardId().substring(2, 9)); |
| | | details.setCustNum(order.getCustomerId() + ""); |
| | | details.setCustNam(order.getCustomerName()); |
| | | details.setProDate((new SimpleDateFormat("dd/MM/yyyy").format(new Date()))); |
| | | details.setDelDate(new SimpleDateFormat("dd/MM/yyyy").format(order.getDeliveryDate())); |
| | | |
| | | //设置文件第一层列表数据 |
| | | //暂时生成笼内所有的玻璃信息(已配对和未配对的) |
| | | List<HollowGlassRelationInfo> hollowGlassRelationInfos = hollowGlassRelationInfoService.list(new LambdaQueryWrapper<HollowGlassRelationInfo>() |
| | | .eq(HollowGlassRelationInfo::getFlowCardId, flowCardId).orderByAsc(HollowGlassRelationInfo::getHollowSequence)); |
| | | Map<Integer, List<HollowGlassRelationInfo>> listMap = hollowGlassRelationInfos.stream().collect(Collectors.groupingBy(HollowGlassRelationInfo::getHollowSequence)); |
| | | |
| | | //设置间隔板数据共所有配对玻璃使用 |
| | | List<LisecHollowFrameDetails> frameList = new ArrayList<>(); |
| | | for (int i = 1; i < relationInfo.getTotalLayer(); i++) { |
| | | LisecHollowFrameDetails frameDetails = new LisecHollowFrameDetails(); |
| | | frameDetails.setRecType("<FR" + i + ">"); |
| | | frameDetails.setType(formulaDetails.getIntervalFrameType()); |
| | | frameDetails.setWidth(formulaDetails.getIntervalFrameWidth()); |
| | | frameDetails.setHeight(formulaDetails.getIntervalFrameHeight()); |
| | | frameList.add(frameDetails); |
| | | } |
| | | List<LisecHollowGlassAndFrameDetails> glassAndFrameList = new ArrayList<>(); |
| | | listMap.forEach((e, v) -> { |
| | | LisecHollowGlassAndFrameDetails glassAndFrame = new LisecHollowGlassAndFrameDetails(); |
| | | List<LisecHollowGlassDetails> glassList = new ArrayList<>(); |
| | | for (int i = 1; i <= v.size(); i++) { |
| | | LisecHollowGlassDetails hollowGlassDetails = new LisecHollowGlassDetails(); |
| | | hollowGlassDetails.setRecType("<GL" + i + ">"); |
| | | hollowGlassDetails.setThickness((int) (v.get(i - 1).getThickness() * 10) + ""); |
| | | hollowGlassDetails.setPaneBcd(randomNumber + "" + (e * ID_RATIO + i)); |
| | | glassList.add(hollowGlassDetails); |
| | | } |
| | | glassAndFrame.setGlassList(glassList); |
| | | glassAndFrame.setFrameList(frameList); |
| | | glassAndFrame.setItemNum(e + ""); |
| | | glassAndFrame.setIdNum(e + ""); |
| | | glassAndFrame.setBarcode(randomNumber.substring(randomNumber.length() - 3)); |
| | | glassAndFrame.setWidth((int) (v.get(0).getWidth() * 10) + ""); |
| | | glassAndFrame.setHeight((int) (v.get(0).getHeight() * 10) + ""); |
| | | glassAndFrame.setGlass1(e * ID_RATIO + 1 + ""); |
| | | glassAndFrame.setFrame1(formulaDetails.getFrameOne()); |
| | | glassAndFrame.setGasCode1(formulaDetails.getCasOne()); |
| | | if (relationInfo.getTotalLayer() == 2) { |
| | | glassAndFrame.setGlass2(e * ID_RATIO + 2 + ""); |
| | | } else if (relationInfo.getTotalLayer() == 3) { |
| | | glassAndFrame.setGlass2(e * ID_RATIO + 2 + ""); |
| | | glassAndFrame.setFrame2(formulaDetails.getFrameTwo()); |
| | | glassAndFrame.setGasCode2(formulaDetails.getCasTwo()); |
| | | glassAndFrame.setGlass3(e * ID_RATIO + 3 + ""); |
| | | } else if (relationInfo.getTotalLayer() == 4) { |
| | | glassAndFrame.setGlass2(e * ID_RATIO + 2 + ""); |
| | | glassAndFrame.setFrame2(formulaDetails.getFrameTwo()); |
| | | glassAndFrame.setGasCode2(formulaDetails.getCasTwo()); |
| | | glassAndFrame.setGlass3(e * ID_RATIO + 3 + ""); |
| | | glassAndFrame.setFrame3(formulaDetails.getFrameThree()); |
| | | glassAndFrame.setGasCode3(formulaDetails.getCasThree()); |
| | | glassAndFrame.setGlass4(e * ID_RATIO + 4 + ""); |
| | | } else { |
| | | glassAndFrame.setGlass2(e * ID_RATIO + 2 + ""); |
| | | glassAndFrame.setFrame2(formulaDetails.getFrameTwo()); |
| | | glassAndFrame.setGasCode2(formulaDetails.getCasTwo()); |
| | | glassAndFrame.setGlass3(e * ID_RATIO + 3 + ""); |
| | | glassAndFrame.setFrame3(formulaDetails.getFrameThree()); |
| | | glassAndFrame.setGasCode3(formulaDetails.getCasThree()); |
| | | glassAndFrame.setGlass4(e * ID_RATIO + 4 + ""); |
| | | glassAndFrame.setFrame3(formulaDetails.getFrameFour()); |
| | | glassAndFrame.setGasCode4(formulaDetails.getCasFour()); |
| | | glassAndFrame.setGlass4(e * ID_RATIO + 5 + ""); |
| | | } |
| | | glassAndFrame.setInset(formulaDetails.getSealInsert()); |
| | | glassAndFrameList.add(glassAndFrame); |
| | | }); |
| | | details.setGlassAndFrameList(glassAndFrameList); |
| | | |
| | | |
| | | Configuration cfg = new Configuration(new Version("2.3.29")); |
| | | cfg.setClassForTemplateLoading(HollowBigStorageCageController.class, "/templates/"); |
| | | // 创建Calculator实例 |
| | | Blank blank = new Blank(); |
| | | |
| | | // 创建数据模型 |
| | | Map<String, Object> root = new HashMap<>(); |
| | | root.put("blank", blank); |
| | | |
| | | root.put("details", details); |
| | | |
| | | // 获取模板 |
| | | Template temp = cfg.getTemplate("hollowGlass.ftl"); |
| | | |
| | | |
| | | // 将生成的文件存入指定路径 |
| | | //计算生成李赛克需要的数据给到每个属性 |
| | | StringWriter out = new StringWriter(); |
| | | File file = new File("D:\\temp", relationInfo.getFlowCardId() + randomNumber.substring(randomNumber.length() - 3) + ".trf"); |
| | | try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { |
| | | temp.process(root, out); |
| | | writer.write(out.toString()); |
| | | } catch (TemplateException | IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return "success"; |
| | | } |
| | | |
| | | |
| | | private HollowGlassOutRelationInfo childrenTask(String flowCardId, int cell, int totalPairQuantity,int isForce) { |
| | | GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getFlowCardId, flowCardId).last("limit 1")); |
| | | private HollowGlassOutRelationInfo childrenTask(HollowTaskRequest request, int isForce) { |
| | | GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getFlowCardId, request.getFlowCardId()).last("limit 1")); |
| | | HollowGlassOutRelationInfo info = new HollowGlassOutRelationInfo(); |
| | | if (null == glassInfo) { |
| | | log.info("该流程卡信息系统未找到"); |
| | | return info; |
| | | } |
| | | info.setFlowCardId(flowCardId); |
| | | info.setCell(cell); |
| | | List<HollowGlassOutRelationInfo> outRelationInfos = this.list(new LambdaQueryWrapper<HollowGlassOutRelationInfo>() |
| | | .eq(HollowGlassOutRelationInfo::getCell, request.getCell()) |
| | | .eq(HollowGlassOutRelationInfo::getFlowCardId, request.getFlowCardId()) |
| | | .in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE)); |
| | | if (CollectionUtil.isNotEmpty(outRelationInfos)) { |
| | | log.info("当前流程卡在本条线有未完成的任务"); |
| | | return null; |
| | | } |
| | | //保存任务关系主表 |
| | | info.setFlowCardId(request.getFlowCardId()); |
| | | info.setCell(request.getCell()); |
| | | info.setIsForce(isForce); |
| | | info.setTotalLayer(glassInfo.getTotalLayer()); |
| | | info.setState(Const.HOLLOW_FLOW_CARD_START); |
| | | info.setTotalPairQuantity(totalPairQuantity); |
| | | List<HollowBigStorageCageDetails> hollowBigStorageCageDetailsList = hollowBigStorageCageDetailsService.queryOutGlassList(flowCardId, cell); |
| | | int isPairCount = glassInfo.getTotalLayer() * totalPairQuantity; |
| | | info.setState(Const.HOLLOW_FLOW_CARD_NEW); |
| | | info.setTotalPairQuantity(request.getTotalPairQuantity()); |
| | | info.setFormulaId(request.getFormulaId()); |
| | | this.save(info); |
| | | // 查询出需要出玻璃的队列 |
| | | List<HollowBigStorageCageDetails> hollowBigStorageCageDetailsList = hollowBigStorageCageDetailsService |
| | | .queryOutGlassList(request.getFlowCardId(), request.getCell()); |
| | | int isPairCount = glassInfo.getTotalLayer() * request.getTotalPairQuantity(); |
| | | List<HollowGlassQueueInfo> hollowQueues = new ArrayList<>(); |
| | | loop: |
| | | for (HollowBigStorageCageDetails queue : hollowBigStorageCageDetailsList) { |
| | | HollowGlassQueueInfo queueInfo = new HollowGlassQueueInfo(); |
| | | BeanUtils.copyProperties(queue, queueInfo); |
| | | queueInfo.setRelationId(info.getId()); |
| | | queueInfo.setState(Const.TEMPERING_NEW); |
| | | queueInfo.setCell(cell); |
| | | queueInfo.setCell(request.getCell()); |
| | | queueInfo.setCreateTime(new Date()); |
| | | queueInfo.setUpdateTime(new Date()); |
| | | hollowQueues.add(queueInfo); |
| | | if (queue.getIsPair() == 1){ |
| | | isPairCount -=1; |
| | | if (isPairCount == 0){ |
| | | if (queue.getIsPair() == 1) { |
| | | isPairCount -= 1; |
| | | if (isPairCount == 0) { |
| | | break loop; |
| | | } |
| | | } |
| | | } |
| | | hollowGlassQueueInfoService.saveBatch(hollowQueues); |
| | | this.save(info); |
| | | try { |
| | | if (request.getCell() == 930) { |
| | | generateHollowLisecFile(request.getFlowCardId(), 930, isForce); |
| | | } |
| | | } catch (Exception e) { |
| | | log.info("生成李赛克文件时发生异常,流程卡号为{}", request.getFlowCardId()); |
| | | } |
| | | return info; |
| | | } |
| | | } |