| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.example.springboot.common.Result; |
| | | import com.example.springboot.component.PLCAutoMes; |
| | | import com.example.springboot.component.Plchome; |
| | | import com.example.springboot.component.S7control; |
| | | import com.example.springboot.entity.FlowCard; |
| | | import com.example.springboot.entity.Flowcard; |
| | | import com.example.springboot.entity.GlassInfo; |
| | | import com.example.springboot.entity.MeasureSetting; |
| | | import com.example.springboot.entity.Queue; |
| | | import com.example.springboot.entity.StorageCage; |
| | | import com.example.springboot.entity.StorageTask; |
| | | import com.example.springboot.entity.device.PlcParameterObject; |
| | | import com.example.springboot.mapper.AlbaniaMapper; |
| | | import com.example.springboot.mapper.GlassInfoMapper; |
| | | import com.example.springboot.mapper.HomeMapper; |
| | | import com.example.springboot.mapper.QueueMapper; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | |
| | | @Service |
| | | public class StorageCageService { |
| | |
| | | private OutSliceServive outSliceServive; |
| | | |
| | | @Autowired |
| | | private QueueMapper QueueMapper; |
| | | |
| | | @Autowired |
| | | private SpianService spianService; |
| | | @Autowired |
| | | private AlbaniaMapper albaniaMapper; |
| | | @Autowired |
| | | private GlassInfoMapper glassInfoMapper; |
| | | |
| | | public void EndTask(int types) { |
| | | String A01glassid1 = spianService.queGlassid("DB103.128", 14).toString(); |
| | |
| | | } else { |
| | | if (id == 1) { |
| | | // 调用伍存储过程 |
| | | System.out.println("调用上片函数"); |
| | | zhi = spianService.selectAll(queue.getglassId()); |
| | | if (zhi == 200) { |
| | | homeMapper.InsertQueueGlassId(queue, id); |
| | |
| | | homeMapper.DeleteStroageCageByCell(cell); |
| | | } else { |
| | | homeMapper.updateStroageCageByCell(cell, num); |
| | | homeMapper.UpdateStroageCageWidthByCell(cell); |
| | | homeMapper.UpdateStroageCageWidthByCell(cell);// 修改笼子宽度 |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("message", "200"); |
| | |
| | | // 查询进/出片任务 |
| | | public List<StorageTask> SelectStorageTask(int task_type) { |
| | | List<StorageTask> storageTasks = new ArrayList<>(); |
| | | String loadrack = "0"; |
| | | if (task_type == 0) { |
| | | storageTasks = homeMapper.SelectStorageTask(task_type); |
| | | } else { |
| | | storageTasks = homeMapper.SelectStorageTask(task_type); |
| | | } |
| | | for (StorageTask storageTask : storageTasks) { |
| | | storageTask.setstorageCage(homeMapper.SelectStorageByCell(storageTask.getLoadrack())); |
| | | if (task_type == 0) { |
| | | loadrack = storageTask.getLoadrack(); |
| | | } else { |
| | | loadrack = storageTask.getShelfRack(); |
| | | } |
| | | // storageTask.setstorageCage(homeMapper.SelectStorageByCell(loadrack)); |
| | | storageTask.setstorageCage(homeMapper.SelectStorageByCellGlass(storageTask.getId())); |
| | | |
| | | } |
| | | return storageTasks; |
| | | } |
| | | |
| | | //手动完成任务 |
| | | public Result FinishTask(Integer id) { |
| | | StorageTask storageTask = homeMapper.SelectStorageTaskById(id);//获取任务信息 |
| | | homeMapper.FinishTask(storageTask.getId());//完成任务 |
| | | if(storageTask.getTaskType().equals("0")){ |
| | | UpdateStroageCageByCell(Integer.parseInt(storageTask.getLoadrack()),1);//玻璃数量+1 |
| | | }else{ |
| | | StorageCage storageCage = homeMapper.SelectStorageByCell(storageTask.getShelfRack()); |
| | | if(storageCage.getNumber()>1){ |
| | | UpdateStroageCageByCell(Integer.parseInt(storageTask.getShelfRack()),-1);//玻璃数量-1 |
| | | }else{ |
| | | UpdateStroageCageByCell(Integer.parseInt(storageTask.getShelfRack()),0);//清除格内信息 |
| | | // 查询进/出片任务 |
| | | public List<GlassInfo> SelectMeasure() { |
| | | return homeMapper.SelectMeasure(); |
| | | } |
| | | |
| | | // 查询当前膜系厚度 |
| | | public MeasureSetting SelectSetting() { |
| | | return homeMapper.SelectMeasureSetting(); |
| | | } |
| | | |
| | | // 查询测量宽高厚膜系 |
| | | public Map StorageCageForm() { |
| | | return homeMapper.SelectMeasureWidthHeight(); |
| | | } |
| | | //手动结束任务 |
| | | public Result TerminateTask(int id) { |
| | | for (int i = 1; i < 7; i++) { |
| | | int taskcont = albaniaMapper.SelectTaskcount(); // 正在进行的任务数量 |
| | | System.out.println("任务数量:" + taskcont); |
| | | if (taskcont == 0) { |
| | | break; |
| | | } |
| | | homeMapper.AddGlassNo(storageTask.getFlowcard(),storageTask.getMateid(),storageTask.geTier());//添加出片完成数量 |
| | | StorageTask storageTask = homeMapper.SelectStorageTaskById();// 获取任务信息 |
| | | if (storageTask.getTaskType().equals("0")) { |
| | | System.out.println("结束进片任务:" + storageTask.getId()); |
| | | homeMapper.FinishTask(storageTask.getId(), 2);// 完成任务 |
| | | homeMapper.DeletequeueByGlassid(storageTask.getGlasstype().toString()); |
| | | glassInfoMapper.updateGlassNumber(storageTask.getGlasstype());//减少扫描次数 |
| | | } else { |
| | | System.out.println("结束出片任务:" + storageTask.getId()); |
| | | homeMapper.FinishTask(storageTask.getId(), 2);// 完成任务 |
| | | UpdateStroageCageByCell(Integer.parseInt(storageTask.getShelfRack()), 1);// 玻璃数量+1 |
| | | homeMapper.OutGlassNo(storageTask.getGlasstype());// 还原出片完成数量 |
| | | } |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | // 手动完成任务 |
| | | public Result FinishTask() { |
| | | for (int i = 1; i < 7; i++) { |
| | | int taskcont = albaniaMapper.SelectTaskcount(); // 正在进行的任务数量 |
| | | System.out.println("任务数量:" + taskcont); |
| | | if (taskcont == 0) { |
| | | break; |
| | | } |
| | | StorageTask storageTask = homeMapper.SelectStorageTaskById();// 获取任务信息 |
| | | if (storageTask.getTaskType().equals("0")) { |
| | | System.out.println("完成进片任务:" + storageTask.getId()); |
| | | homeMapper.FinishTask(storageTask.getId(), 1);// 完成任务 |
| | | UpdateStroageCageByCell(Integer.parseInt(storageTask.getLoadrack()), 1);// 玻璃数量+1 |
| | | homeMapper.DeletequeueByGlassid(storageTask.getGlasstype().toString()); |
| | | } else { |
| | | System.out.println("完成出片任务:" + storageTask.getId()); |
| | | homeMapper.FinishTask(storageTask.getId(), 1);// 完成任务 |
| | | StorageCage storageCage = homeMapper.SelectStorageByCell(storageTask.getShelfRack()); |
| | | if (storageCage.getNumber() == null || storageCage.getNumber() == 0) { |
| | | UpdateStroageCageByCell(Integer.parseInt(storageTask.getShelfRack()), 0);// 清除格内信息 |
| | | } |
| | | // homeMapper.AddGlassNo(storageTask.getFlowcard(), storageTask.getMateid(), |
| | | // storageTask.geTier());// 添加出片完成数量 |
| | | |
| | | } |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("message", "200"); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | // 自动完成任务 |
| | | public Result LoseTask() { |
| | | for (int i = 1; i < 7; i++) { |
| | | int taskcont = albaniaMapper.SelectTaskcount(); // 正在进行的任务数量 |
| | | System.out.println("任务数量:" + taskcont); |
| | | if (taskcont == 0) { |
| | | break; |
| | | } |
| | | StorageTask storageTask = homeMapper.SelectStorageTaskById();// 获取任务信息 |
| | | if (storageTask.getTaskType().equals("0")) { |
| | | System.out.println("完成进片任务:" + storageTask.getId()); |
| | | homeMapper.FinishTask(storageTask.getId(), 1);// 完成任务 |
| | | UpdateStroageCageByCell(Integer.parseInt(storageTask.getLoadrack()), 1);// 玻璃数量+1 |
| | | homeMapper.DeletequeueByGlassid(storageTask.getGlasstype().toString()); |
| | | } else { |
| | | System.out.println("完成出片任务:" + storageTask.getId()); |
| | | homeMapper.FinishTask(storageTask.getId(), 1);// 完成任务 |
| | | StorageCage storageCage = homeMapper.SelectStorageByCell(storageTask.getShelfRack()); |
| | | if (storageCage.getNumber() > 1) { |
| | | UpdateStroageCageByCell(Integer.parseInt(storageTask.getShelfRack()), -1);// 玻璃数量-1 |
| | | } else { |
| | | UpdateStroageCageByCell(Integer.parseInt(storageTask.getShelfRack()), 0);// 清除格内信息 |
| | | } |
| | | homeMapper.AddGlassNo(storageTask.getFlowcard(), storageTask.getMateid(), storageTask.geTier());// 添加出片完成数量 |
| | | |
| | | //查询玻璃信息 |
| | | public Result SelectGlassInfo(String width,String height,String thickness,String films) { |
| | | List<GlassInfo> glassInfoList = homeMapper.SelectGlassInfo(width,height,thickness,films); |
| | | } |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("message", "200"); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | // 查询玻璃信息 |
| | | public Result SelectGlassInfo(String width, String height, String thickness, String films) { |
| | | List<GlassInfo> glassInfoList = homeMapper.SelectGlassInfo(width, height, thickness, films); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("StorageCageAddInfo", glassInfoList); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | //添加玻璃到格子内 |
| | | public Result StorageCageAddGlass(String cell,GlassInfo glassInfo) { |
| | | homeMapper.StorageCageAddGlass(cell,glassInfo); |
| | | UpdateStroageCageByCell(Integer.parseInt(cell),1); |
| | | // 添加玻璃到格子内 |
| | | public Result StorageCageAddGlass(String cell, GlassInfo glassInfo) { |
| | | homeMapper.StorageCageAddGlass(cell, glassInfo); |
| | | UpdateStroageCageByCell(Integer.parseInt(cell), 1); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("message", "200"); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | //查询订单任务 |
| | | public List<FlowCard> SelectOrderTask() { |
| | | List<FlowCard> OrderTask=homeMapper.SelectOrderTask(); |
| | | for (FlowCard flowcard : OrderTask) { |
| | | // 查询订单任务 |
| | | public List<Flowcard> SelectOrderTask() { |
| | | List<Flowcard> OrderTask = homeMapper.SelectOrderTask(); |
| | | for (Flowcard flowcard : OrderTask) { |
| | | flowcard.setglassinfo(homeMapper.SelectOrderView(flowcard.getFlowcard())); |
| | | } |
| | | return OrderTask; |
| | | } |
| | | |
| | | //开始任务 |
| | | public Result ClaimTasks(String flowcard, Integer state) { |
| | | if(state==1){ |
| | | homeMapper.ClaimTasks(flowcard,0); |
| | | }else{ |
| | | homeMapper.ClaimTasks(flowcard,1); |
| | | } |
| | | // 开始出片 |
| | | public Result ClaimTasks(String flowcard, Integer state, Integer line) { |
| | | int count = homeMapper.SelectTaskCount(flowcard, line); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("message", "200"); |
| | | if (count == 0) { |
| | | if (state == 1) { |
| | | homeMapper.ClaimTasks(flowcard, 0, line); |
| | | } else { |
| | | homeMapper.ClaimTasks(flowcard, 1, line); |
| | | } |
| | | map.put("message", "200"); |
| | | } else { |
| | | map.put("message", "300"); |
| | | } |
| | | |
| | | return Result.success(map); |
| | | } |
| | | |
| | | //任务模式修改 |
| | | // 任务模式修改 |
| | | public Result ModeChange(String flowcard, Integer method) { |
| | | if(method==1){ |
| | | homeMapper.ModeChange(flowcard,0); |
| | | }else{ |
| | | homeMapper.ModeChange(flowcard,1); |
| | | if (method == 1) { |
| | | homeMapper.ModeChange(flowcard, 0); |
| | | } else { |
| | | homeMapper.ModeChange(flowcard, 1); |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("message", "200"); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | //修改测量信息 |
| | | // 人工匹配修改测量信息 |
| | | public Result UpdateQueue(GlassInfo glassInfo) { |
| | | homeMapper.UpdateQueue(glassInfo.getFlowcard(),glassInfo.getWidth(),glassInfo.getHeight(),glassInfo.getGlasstype()); |
| | | // 删除数据 |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("message", "200"); |
| | | // QueueMapper.DeleteQueue(); |
| | | int count = homeMapper.SelectQueue(); |
| | | if (count > 0) { |
| | | homeMapper.UpdateQueue(glassInfo.getFlowcard(), glassInfo.getWidth(), glassInfo.getHeight(), |
| | | glassInfo.getGlasstype(), glassInfo.getThickness(), glassInfo.getTier(), glassInfo.getMateid()); |
| | | PlcParameterObject plcmes = PLCAutoMes.PlcMesObject; |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToGaStatus").getAddress(), (short) 1); |
| | | map.put("message", "200"); |
| | | }else { |
| | | map.put("message", "300"); |
| | | } |
| | | return Result.success(map); |
| | | } |
| | | |
| | |
| | | return homeMapper.SelectStorageCageByCage(cage); |
| | | } |
| | | |
| | | // 人工拿走 |
| | | public Result ManualTake(String glassInfo) { |
| | | // 读取DB105区文件 |
| | | PlcParameterObject plcmes = PLCAutoMes.PlcMesObject; |
| | | // 移除 |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToGaStatus").getAddress(), (short) 3); |
| | | // 删除数据 |
| | | QueueMapper.DeleteErrorQueue(); |
| | | |
| | | // plcmes.getPlcParameter("GaToMES").setValue("3"); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("message", "200"); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | // 开始上片 |
| | | public Result StartChange(String flowcard, int orderstate) { |
| | | homeMapper.StartChange(flowcard, orderstate); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | int state = homeMapper.selectStartChange(flowcard); |
| | | map.put("message", "200"); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | // 删除工程 |
| | | public Result deleteTasks(Map num) { |
| | | String flowcard = (String) num.get("num"); |
| | | int aa = homeMapper.deleteFlowcard(flowcard.trim()); |
| | | homeMapper.deleteGlassinfo(flowcard.trim()); |
| | | System.out.println(flowcard); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("message", flowcard.trim()); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | // 保存测量设置 |
| | | public Result SaveMeasure(String films, Integer thickness) { |
| | | int Measure = homeMapper.SaveMeasure(films, thickness); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("message", Measure); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | // 重新测量 |
| | | public Result AnewMeasure(String glassInfo) { |
| | | // 读取DB105区文件 |
| | | PlcParameterObject plcmes = PLCAutoMes.PlcMesObject; |
| | | // 重新测量 |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToGaStatus").getAddress(), (short) 2); |
| | | // 删除数据 |
| | | QueueMapper.DeleteErrorQueue(); |
| | | // plcmes.getPlcParameter("GaToMES").setValue("2"); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("message", "200"); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | // 添加小片信息 |
| | | public Result AddGlassinfo(List<Map> IportDataStr) { |
| | | |
| | | // 筛选处理数据 1.去除无用数据 2.计算配片ID 3.计算ID 4. 计算总层数 |
| | | List<Map> TypeDatas = homeMapper.SelectType(); |
| | | Map<String, String> TypeData = new HashMap<String, String>();// 得到处理完后所有的类型 |
| | | Map<String, Integer> groupby = new HashMap<String, Integer>(); // 得到处理完后所有总层数; |
| | | Map<String, Integer> OrderFinishedProduct = new HashMap<String, Integer>(); // 得到处理完后订单成品总数量; |
| | | // "order zong 0 1 10 2 10" |
| | | List<Map> RemoveErrorData = IportDataStr.stream() |
| | | .filter(item -> (item.get("order") != null && item.get("tier") != null |
| | | && |
| | | item.get("films") != null && item.get("base") != null && item.get("height") != null |
| | | && item.get("thickness") != null && item.get("quantity") != null |
| | | && item.get("matching") != null)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | TypeDatas.forEach(item -> { |
| | | TypeData.put(item.get("type").toString(), item.get("glasstype").toString()); |
| | | }); |
| | | |
| | | RemoveErrorData.forEach(item -> { |
| | | String key = item.get("order").toString() + "_" + item.get("matching").toString(); |
| | | String keyCount = item.get("order").toString() + "_" + item.get("matching").toString() + "_" |
| | | + item.get("tier").toString(); |
| | | String keyCountSum = item.get("order").toString() + "_" + item.get("matching").toString() + "_Sum";// 订单总数 |
| | | if (OrderFinishedProduct.get(keyCount) != null) { |
| | | Integer count = OrderFinishedProduct.get(keyCount) + 1; |
| | | Integer sumcount = OrderFinishedProduct.get(keyCountSum) |
| | | + Integer.parseInt(item.get("quantity").toString()); |
| | | OrderFinishedProduct.put(keyCount, count); |
| | | OrderFinishedProduct.put(keyCountSum, sumcount); |
| | | } else if (OrderFinishedProduct.get(keyCount) == null && groupby.get(key) == null) { |
| | | OrderFinishedProduct.put(keyCount, 1); |
| | | OrderFinishedProduct.put(keyCountSum, Integer.parseInt(item.get("quantity").toString())); |
| | | } |
| | | if (groupby.get(key) != null) { |
| | | Integer Tiers = groupby.get(key) + 1; |
| | | groupby.put(key, Tiers); |
| | | } else { |
| | | groupby.put(key, 1); |
| | | } |
| | | }); |
| | | |
| | | System.out.println(RemoveErrorData.size()); |
| | | // 处理完成 添加数据库 |
| | | int count = 1; |
| | | for (Map map : RemoveErrorData) { |
| | | String key = map.get("base").toString() + "_" + map.get("height").toString() + "_" |
| | | + map.get("thickness").toString() + "_" + map.get("films").toString() + "_" |
| | | + map.get("order").toString() + "_" + map.get("matching").toString(); |
| | | |
| | | String tierkey = map.get("order").toString() + "_" + map.get("matching").toString(); |
| | | |
| | | String value = TypeData.get(key); |
| | | Integer glasstype; |
| | | System.out.println(key + ":" + TypeData.get(key)); |
| | | if (TypeData.get(key) == null) { |
| | | |
| | | glasstype = homeMapper.SelectMaxTypes(key); |
| | | if (glasstype == null) { |
| | | glasstype = homeMapper.SelectMaxType(); |
| | | } |
| | | if (glasstype == null) { |
| | | glasstype = 1; |
| | | } |
| | | } else { |
| | | glasstype = Integer.valueOf(value); |
| | | } |
| | | // |
| | | |
| | | homeMapper.AddGlassinfo(map.get("order").toString(), glasstype, |
| | | Integer.parseInt(map.get("matching").toString()) // 需要计算 配片ID |
| | | , map.get("order").toString() + "-" + count + "" // 需要计算 玻璃ID |
| | | , Integer.parseInt(map.get("tier").toString()), map.get("films").toString(), |
| | | Double.parseDouble(map.get("base").toString()), Double.parseDouble(map.get("height").toString()), |
| | | Double.parseDouble(map.get("thickness").toString()), |
| | | Integer.parseInt(map.get("quantity").toString()), groupby.get(tierkey));// 需要计算总层数 |
| | | // 订单内总层数 |
| | | homeMapper.InsertFlowcard(map.get("order").toString(), OrderFinishedProduct.get(tierkey + "_Sum")); |
| | | count++; |
| | | } |
| | | Map<String, Object> ResultCode = new HashMap<>(); |
| | | ResultCode.put("message", "200"); |
| | | return Result.success(ResultCode); |
| | | } |
| | | |
| | | } |