大规模优化
This commit is contained in:
@@ -73,7 +73,7 @@ public interface IIndustryMaterialService
|
||||
|
||||
int start(IndustryMaterial industryMaterial);
|
||||
|
||||
String nextMaterial(IndustryMaterialDto industryMaterialDto);
|
||||
int nextMaterial(IndustryMaterialDto industryMaterialDto);
|
||||
|
||||
int updateIndustryMaterialStateByBatchId(Long batchId);
|
||||
|
||||
@@ -96,6 +96,7 @@ public interface IIndustryMaterialService
|
||||
|
||||
/**
|
||||
* 检测工艺是否相同 不相同返回0 相同返回1并且根据工艺表创建道次对象
|
||||
*
|
||||
* @param industryMaterial batchId state=1
|
||||
* @return
|
||||
*/
|
||||
@@ -108,7 +109,7 @@ public interface IIndustryMaterialService
|
||||
*/
|
||||
public int checkFlagError(IndustryMaterialDto material);
|
||||
|
||||
String nextError(IndustryMaterialDto industryMaterialDto);
|
||||
int nextError(IndustryMaterialDto industryMaterialDto);
|
||||
|
||||
|
||||
List<IndustryMaterialVo> selectIndustryMaterialList1(IndustryMaterial industryMaterial);
|
||||
|
||||
@@ -75,7 +75,7 @@ public interface IIndustryStepService
|
||||
* @param industryStep
|
||||
* @return
|
||||
*/
|
||||
String nextStep(IndustryStep industryStep);
|
||||
int nextStep(IndustryStep industryStep);
|
||||
|
||||
int finish(Long batchId);
|
||||
|
||||
@@ -92,7 +92,7 @@ public interface IIndustryStepService
|
||||
|
||||
int createStep(IndustryMaterial industryMaterial);
|
||||
|
||||
public String nextStepError(IndustryStep industryStep);
|
||||
public int nextStepError(IndustryStep industryStep);
|
||||
|
||||
/**
|
||||
* 获取当前运行这批料中道次最小的道次对应的材料id
|
||||
@@ -101,7 +101,7 @@ public interface IIndustryStepService
|
||||
*/
|
||||
String getSmallStepMaterialId(IndustryMaterial industryMaterial);
|
||||
|
||||
String finishError(Long batchId);
|
||||
int finishError(Long batchId);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.industry.work.service.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -10,6 +8,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
|
||||
import com.industry.common.annotation.DataSource;
|
||||
import com.industry.common.constant.Constants;
|
||||
import com.industry.common.core.redis.RedisCache;
|
||||
|
||||
import com.industry.common.enums.DataSourceType;
|
||||
@@ -209,7 +208,7 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 判断是否还存在一个
|
||||
// 判断是否存在一个
|
||||
if (Objects.isNull(firstMaterial.getBatchId())) {
|
||||
return 0;
|
||||
}
|
||||
@@ -221,7 +220,7 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
|
||||
// 判断是否已经开始
|
||||
industryMaterial.setOperation(1L);
|
||||
if (industryMaterialMapper.selectIndustryMaterialList(industryMaterial).size() != 0) {
|
||||
if (!industryMaterialMapper.selectIndustryMaterialList(industryMaterial).isEmpty()) {
|
||||
// 如果size不为零说明已经有正在进行中的了
|
||||
// 提醒前端已经开始了,无需重新开始
|
||||
return 0;
|
||||
@@ -234,10 +233,11 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
redisCache.setCacheObject("materialFlag", 1L, 100, TimeUnit.HOURS);
|
||||
redisCache.setCacheObject("nextStepFlag", 0L, 100, TimeUnit.HOURS);
|
||||
|
||||
for (IndustryMaterialVo industryMaterialVo : industryMaterialVos) {
|
||||
MomResource momResource = getMomResource(industryMaterialVo);
|
||||
momService.processPowerOn(momResource);
|
||||
}
|
||||
// TODO PLC
|
||||
// for (IndustryMaterialVo industryMaterialVo : industryMaterialVos) {
|
||||
// MomResource momResource = getMomResource(industryMaterialVo);
|
||||
// momService.processPowerOn(momResource);
|
||||
// }
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -265,30 +265,32 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public String nextMaterial(IndustryMaterialDto industryMaterialDto) {
|
||||
public int nextMaterial(IndustryMaterialDto industryMaterialDto) {
|
||||
if (industryMaterialDto.getStepFlag() == 0L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pos = -1;
|
||||
// 初始化 IndustryMaterial
|
||||
IndustryMaterial industryMaterial = new IndustryMaterial();
|
||||
industryMaterial.setBatchId(industryMaterialDto.getBatchId());
|
||||
Long state = industryMaterialDto.getState();
|
||||
if (industryMaterialDto.getStepFlag() == 0L) {
|
||||
return "当前未处理,你跳个鸡毛";
|
||||
}
|
||||
int pos = -1;
|
||||
|
||||
// 设置状态
|
||||
// 3代表的是该批次中存在道次异常,下面的查询时直接跳过这个批次
|
||||
state = state == 3 ? 1 : state;
|
||||
// 查询下一个应该将operation改为 1 的批次 并且为同一状态
|
||||
Long state = (industryMaterialDto.getState() == 3) ? 1 : industryMaterialDto.getState();
|
||||
industryMaterial.setState(state);
|
||||
|
||||
// 查询批次列表
|
||||
// 查询当前批次状态1的列表
|
||||
List<IndustryMaterialVo> industryMaterialVos = industryMaterialMapper.selectIndustryMaterialList(industryMaterial);
|
||||
|
||||
// 判断是否为空列表
|
||||
if (industryMaterialVos.size() == 0) {
|
||||
// 空列表返回2 通知前端改变操作方向 - -> +
|
||||
return "2";
|
||||
if (industryMaterialVos.isEmpty() ) {
|
||||
// 如果为空列表则直接返回,全部发生异常了
|
||||
return Constants.COMPLETE_PROCESS;
|
||||
}
|
||||
|
||||
// 判断列表是否只有一个对象 如果是的话则不需要更新字段operation
|
||||
if (industryMaterialVos.size() == 1) {
|
||||
return "0";
|
||||
if (industryMaterialVos.size() == 1){
|
||||
// 或者判断列表是否只有一个对象 如果是的话则不需要更新字段operation
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 记录当前正在运行的是第几个
|
||||
@@ -301,11 +303,13 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
// 将现在正在运行的批次状态改为0
|
||||
industryMaterialDto.setOperation(0L);
|
||||
updateIndustryMaterial(industryMaterialDto);
|
||||
|
||||
IndustryMaterialVo industryMaterialVo;
|
||||
Long materialFlag = redisCache.getCacheObject("materialFlag");
|
||||
// 处理是向上走还是向下走
|
||||
int next = -1;
|
||||
if (materialFlag == 0L) {
|
||||
int next = -1;
|
||||
// 此if为向上走
|
||||
// 找到上一个正常的
|
||||
for (int i = pos - 1; i >= 0; i--) {
|
||||
if (industryMaterialVos.get(i).getState() == 1L) {
|
||||
@@ -313,19 +317,22 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 降序
|
||||
// 往上走
|
||||
if (next == -1) {
|
||||
//走到这next如果还为-1表示这是最头上那个了 就要修改顺序
|
||||
redisCache.setCacheObject("materialFlag", 1L, 100, TimeUnit.HOURS);
|
||||
industryMaterialVo = industryMaterialVos.get(pos);
|
||||
industryMaterialVo.setOperation(1L);
|
||||
updateIndustryMaterial(industryMaterialVo);
|
||||
return "下道次";
|
||||
// 将批次改成他的下一个正常的
|
||||
// 找到下一个正常的
|
||||
for (int i =pos+1; i < industryMaterialVos.size(); i++) {
|
||||
if (industryMaterialVos.get(i).getState() == 1L) {
|
||||
next = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
industryMaterialVo = industryMaterialVos.get(next);
|
||||
redisCache.setCacheObject("nextStepFlag", 1L, 100, TimeUnit.HOURS);
|
||||
} else {
|
||||
industryMaterialVo = industryMaterialVos.get(next);
|
||||
}
|
||||
} else {
|
||||
int next = -1;
|
||||
// 找到下一个正常的
|
||||
for (int i = pos + 1; i < industryMaterialVos.size(); i++) {
|
||||
if (industryMaterialVos.get(i).getState() == 1L) {
|
||||
@@ -334,20 +341,23 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
}
|
||||
}
|
||||
if (next == -1) {
|
||||
|
||||
redisCache.setCacheObject("materialFlag", 0L, 100, TimeUnit.HOURS);
|
||||
|
||||
industryMaterialVo = industryMaterialVos.get(pos);
|
||||
industryMaterialVo.setOperation(1L);
|
||||
updateIndustryMaterial(industryMaterialVo);
|
||||
return "下道次";
|
||||
// 改变方向由向下改为向上
|
||||
// 找到上一个正常的
|
||||
for (int i = pos - 1; i >= 0; i--) {
|
||||
if (industryMaterialVos.get(i).getState() == 1L) {
|
||||
next = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
industryMaterialVo = industryMaterialVos.get(next);
|
||||
redisCache.setCacheObject("nextStepFlag", 1L, 100, TimeUnit.HOURS);
|
||||
} else {
|
||||
industryMaterialVo = industryMaterialVos.get(next);
|
||||
}
|
||||
}
|
||||
industryMaterialVo.setOperation(1L);
|
||||
updateIndustryMaterial(industryMaterialVo);
|
||||
return "1";
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -390,13 +400,12 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
public int abnormalStart(IndustryMaterial industryMaterial, String materialId) {
|
||||
|
||||
industryMaterial.setOperation(1L);
|
||||
if (industryMaterialMapper.selectIndustryMaterialList(industryMaterial).size() != 0) {
|
||||
if (!industryMaterialMapper.selectIndustryMaterialList(industryMaterial).isEmpty()) {
|
||||
// 如果size不为零说明已经有正在进行中的了
|
||||
// 提醒前端已经开始了,无需重新开始
|
||||
return 0;
|
||||
}
|
||||
IndustryMaterialVo firstMaterial = selectIndustryMaterialById(materialId);
|
||||
// 到这里没有return出去 表示该批次未开始
|
||||
// 拿到序号为第一的将其操作中设置成1
|
||||
firstMaterial.setOperation(1L);
|
||||
|
||||
@@ -419,7 +428,7 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
* 检查是否为左侧正常批次的最后一个或者第一个,是的话向前端给一个提示要求点击下道次
|
||||
*
|
||||
* @param material
|
||||
* @return
|
||||
* @return 0表示无需切换道次 1表示需要切换道次
|
||||
*/
|
||||
@Override
|
||||
public int checkFlag(IndustryMaterialDto material) {
|
||||
@@ -435,7 +444,7 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
// 判断列表是否只有一个对象 如果是的话则不需要更新字段operation
|
||||
if (industryMaterialVos.size() == 1) {
|
||||
redisCache.setCacheObject("nextStepFlag", 1L, 100, TimeUnit.HOURS);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
// 记录当前正在运行的是第几个
|
||||
int pos = -1;
|
||||
@@ -443,7 +452,7 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
int end = -1;
|
||||
int flag = 1;
|
||||
for (int i = 0; i < industryMaterialVos.size(); i++) {
|
||||
if (industryMaterialVos.get(i).getState() != 3 && flag == 1) {
|
||||
if (industryMaterialVos.get(i).getState() != 3L && flag == 1) {
|
||||
start = i;
|
||||
flag = 0;
|
||||
}
|
||||
@@ -463,16 +472,16 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
if (start == pos) {
|
||||
// 向上升并且已经升到头了
|
||||
redisCache.setCacheObject("nextStepFlag", 1L, 100, TimeUnit.HOURS);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (end == pos) {
|
||||
redisCache.setCacheObject("nextStepFlag", 1L, 100, TimeUnit.HOURS);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
redisCache.setCacheObject("nextStepFlag", 0L, 100, TimeUnit.HOURS);
|
||||
return 1;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -497,7 +506,7 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
// 判断列表是否只有一个对象 如果是的话则不需要更新字段operation
|
||||
if (industryMaterialVos.size() == 1) {
|
||||
redisCache.setCacheObject("nextStepFlagError", 1L, 100, TimeUnit.HOURS);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
// 记录当前正在运行的是第几个
|
||||
int pos = -1;
|
||||
@@ -527,64 +536,63 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
if (start == pos) {
|
||||
redisCache.setCacheObject("nextStepFlagError", 1L, 100, TimeUnit.HOURS);
|
||||
// 向上升并且已经升到头了
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (end == pos) {
|
||||
redisCache.setCacheObject("nextStepFlagError", 1L, 100, TimeUnit.HOURS);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
redisCache.setCacheObject("nextStepFlagError", 0L, 100, TimeUnit.HOURS);
|
||||
return 1;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextError(IndustryMaterialDto industryMaterialDto) {
|
||||
int pos = -1;
|
||||
public int nextError(IndustryMaterialDto industryMaterialDto) {
|
||||
if (industryMaterialDto.getStepFlag() == 0L) {
|
||||
return 0;
|
||||
}
|
||||
// 初始化
|
||||
IndustryMaterial industryMaterial = new IndustryMaterial();
|
||||
industryMaterial.setBatchId(industryMaterialDto.getBatchId());
|
||||
int pos = -1;
|
||||
Long state = industryMaterialDto.getState();
|
||||
|
||||
if (industryMaterialDto.getStepFlag() == 0L) {
|
||||
return "未处理";
|
||||
}
|
||||
// 3代表的是该批次中存在道次异常,下面的查询时直接跳过这个批次
|
||||
state = state == 3 ? 5 : state;
|
||||
// 查询下一个应该将operation改为 1 的批次 并且为同一状态
|
||||
industryMaterial.setState(state);
|
||||
industryMaterial.setDelFlag(1L);
|
||||
// 查出连同正在运行的道次以及左边料物信息
|
||||
List<IndustryMaterialVo> industryMaterialVos = industryMaterialMapper.selectIndustryMaterialAndStepList(industryMaterial);
|
||||
// 判断是否为空列表
|
||||
if (industryMaterialVos.size() == 0) {
|
||||
// 空列表返回2 通知前端改变操作方向 - -> +
|
||||
return "2";
|
||||
if (industryMaterialVos.isEmpty()) {
|
||||
// 为空则直接返回,表示全部异常了
|
||||
return Constants.COMPLETE_PROCESS;
|
||||
}
|
||||
|
||||
// 判断列表是否只有一个对象 如果是的话则不需要更新字段operation
|
||||
if (industryMaterialVos.size() == 1) {
|
||||
return "0";
|
||||
redisCache.setCacheObject("nextStepFlagError", 1L, 100, TimeUnit.HOURS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 记录当前正在运行的是第几个
|
||||
|
||||
for (int i = 0; i < industryMaterialVos.size(); i++) {
|
||||
if (industryMaterialDto.getId().equals(industryMaterialVos.get(i).getId())) {
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 将现在正在运行的批次状态改为0
|
||||
industryMaterialDto.setOperation(0L);
|
||||
updateIndustryMaterial(industryMaterialDto);
|
||||
IndustryMaterialVo industryMaterialVo;
|
||||
Long materialFlag = redisCache.getCacheObject("materialFlagError");
|
||||
// 处理是向上走还是向下走
|
||||
int next = -1;
|
||||
if (materialFlag == 0L) {
|
||||
|
||||
int next = -1;
|
||||
// 找到上一个正常的
|
||||
for (int i = pos - 1; i >= 0; i--) {
|
||||
if (industryMaterialVos.get(i).getState() == 5L && industryMaterialVos.get(i).getIndustryStepVo().getState() == 0L) {
|
||||
@@ -595,17 +603,20 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
// 降序
|
||||
if (next == -1) {
|
||||
//走到这next如果还为-1表示这是最头上那个了 就要修改顺序
|
||||
redisCache.setCacheObject("materialFlagError", 1L, 100, TimeUnit.HOURS);
|
||||
industryMaterialVo = industryMaterialVos.get(pos);
|
||||
industryMaterialVo.setOperation(1L);
|
||||
updateIndustryMaterial(industryMaterialVo);
|
||||
return "下道次";
|
||||
|
||||
// 找到下一个正常的
|
||||
for (int i = pos + 1; i < industryMaterialVos.size(); i++) {
|
||||
if (industryMaterialVos.get(i).getState() == 5L && industryMaterialVos.get(i).getIndustryStepVo().getState() == 0L) {
|
||||
next = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
industryMaterialVo = industryMaterialVos.get(next);
|
||||
redisCache.setCacheObject("nextStepFlagError", 1L, 100, TimeUnit.HOURS);
|
||||
} else {
|
||||
industryMaterialVo = industryMaterialVos.get(next);
|
||||
}
|
||||
} else {
|
||||
|
||||
int next = -1;
|
||||
// 找到下一个正常的
|
||||
for (int i = pos + 1; i < industryMaterialVos.size(); i++) {
|
||||
if (industryMaterialVos.get(i).getState() == 5L && industryMaterialVos.get(i).getIndustryStepVo().getState() == 0L) {
|
||||
@@ -615,19 +626,21 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
}
|
||||
|
||||
if (next == -1) {
|
||||
redisCache.setCacheObject("materialFlagError", 0L, 100, TimeUnit.HOURS);
|
||||
industryMaterialVo = industryMaterialVos.get(pos);
|
||||
industryMaterialVo.setOperation(1L);
|
||||
updateIndustryMaterial(industryMaterialVo);
|
||||
return "下道次";
|
||||
for (int i = pos - 1; i >= 0; i--) {
|
||||
if (industryMaterialVos.get(i).getState() == 5L && industryMaterialVos.get(i).getIndustryStepVo().getState() == 0L) {
|
||||
next = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
industryMaterialVo = industryMaterialVos.get(next);
|
||||
redisCache.setCacheObject("nextStepFlagError", 1L, 100, TimeUnit.HOURS);
|
||||
} else {
|
||||
industryMaterialVo = industryMaterialVos.get(next);
|
||||
}
|
||||
|
||||
}
|
||||
industryMaterialVo.setOperation(1L);
|
||||
updateIndustryMaterial(industryMaterialVo);
|
||||
return "1";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -669,7 +682,7 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
public void getMaterialData() {
|
||||
IndustryMaterial material = new IndustryMaterial();
|
||||
material.setState(1L);
|
||||
if (industryMaterialMapper.selectIndustryMaterialList2(material).size() > 0) {
|
||||
if (!industryMaterialMapper.selectIndustryMaterialList2(material).isEmpty()) {
|
||||
// 进入这个if 说明现在有正在轧制的料,则不进行入料,并且删除这些键
|
||||
|
||||
redisCache.deleteObject("sort");
|
||||
@@ -847,7 +860,7 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
if (pos - 1 == industryMaterialVos.size()) {
|
||||
if (pos+1 == industryMaterialVos.size()) {
|
||||
// 表示是最后一个
|
||||
return 0L;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.industry.work.service.impl;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
|
||||
import com.github.xingshuangs.iot.protocol.s7.serializer.S7Serializer;
|
||||
import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
|
||||
import com.industry.common.constant.Constants;
|
||||
import com.industry.common.core.redis.Redis2Cache;
|
||||
import com.industry.common.core.redis.RedisCache;
|
||||
import com.industry.common.plc.PLCSystemData;
|
||||
@@ -65,16 +65,12 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
@Autowired
|
||||
private S7PLC s7PLC;
|
||||
|
||||
|
||||
@Value("${ipAddress}")
|
||||
private String ipAddress;
|
||||
|
||||
|
||||
@Value("${mode}")
|
||||
private String mode;
|
||||
|
||||
@Autowired
|
||||
private Redis2Cache redis2Cache;
|
||||
|
||||
/**
|
||||
* 查询钽靶道次表
|
||||
*
|
||||
@@ -145,14 +141,12 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
|
||||
@Override
|
||||
public List<IndustryStepVo> selectIndustryStepListByProcess(IndustryStep industryStep) {
|
||||
|
||||
|
||||
String materialId = industryStep.getMaterialId();
|
||||
Long batchId = industryStep.getBatchId();
|
||||
industryStep.setMaterialId(materialId);
|
||||
industryStep.setBatchId(batchId);
|
||||
List<IndustryStepVo> industryStepVos = industryStepMapper.selectIndustryStepList(industryStep);
|
||||
if (industryStepVos.size() == 0) {
|
||||
if (industryStepVos.isEmpty()) {
|
||||
// 表示该批次没有出现道次 直接return
|
||||
industryStep = new IndustryStep();
|
||||
industryStep.setMaterialId(materialId);
|
||||
@@ -179,87 +173,98 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public String nextStep(IndustryStep industryStep) {
|
||||
public int nextStep(IndustryStep industryStep) {
|
||||
|
||||
Long tag = redisCache.getCacheObject("nextStepFlag");
|
||||
if (tag != 1L) {
|
||||
return "未到下道次";
|
||||
// nextStepFlag为切换道次的标志位,当其为1时需要进行切换道次,否则不用切换道次
|
||||
return 0;
|
||||
}
|
||||
|
||||
S7PLC s7PLC2 = new S7PLC(EPlcType.S1500, ipAddress);
|
||||
s7PLC2.setConnectTimeout(60000);
|
||||
s7PLC2.setReceiveTimeout(60000);
|
||||
s7PLC2.writeBoolean("DB15.1.2",true);
|
||||
// TODO PLC
|
||||
// 将切换道次改为true
|
||||
// s7PLC.writeBoolean("DB15.1.2",true);
|
||||
|
||||
while (!s7PLC2.readBoolean("DB15.1.2")){
|
||||
Threads.sleep(500);
|
||||
// 判断当前切换是否转化过来成true 没有则再发
|
||||
// while (!s7PLC.readBoolean("DB15.1.2")){
|
||||
// Threads.sleep(500);
|
||||
|
||||
// }
|
||||
|
||||
// 当当前的到此为true时候将其置 5s延迟 使其切换道次
|
||||
// if (s7PLC.readBoolean("DB15.1.2")){
|
||||
|
||||
Threads.sleep(5000);
|
||||
// 更新该批次中的全部道次的 "操作中" 字段为0
|
||||
IndustryStep step = new IndustryStep();
|
||||
|
||||
step.setBatchId(industryStep.getBatchId());
|
||||
|
||||
step.setOperation(0L);
|
||||
industryStepMapper.updateIndustryStepByBatchId(step);
|
||||
|
||||
IndustryStep industryStep1 = new IndustryStep();
|
||||
industryStep1.setBatchId(industryStep.getBatchId());
|
||||
Long newStep = industryStep.getStep() + 1L;
|
||||
industryStep1.setStep(newStep);
|
||||
// 查询下一步还有没有
|
||||
List<IndustryStepVo> industryStepVos = selectIndustryStepList(industryStep1);
|
||||
if (industryStepVos.isEmpty()) {
|
||||
// 等于0说明没有下一步了 通知前端处理下一批
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (s7PLC2.readBoolean("DB15.1.2")){
|
||||
// 如果不为0 说明该批次依然有道次未处理
|
||||
// 获取第一个 将其operation改为1
|
||||
industryStep1.setOperation(1L);
|
||||
// 更新一下下一步的状态
|
||||
industryStepMapper.updateIndustryStepByBatchId(industryStep1);
|
||||
// TODO 向plc发送当前道次
|
||||
// s7PLC.writeInt32("DB16.0", Math.toIntExact(newStep));
|
||||
//以及剩余道次
|
||||
Long num = industryStepMapper.selectMaxStepNum(industryStep.getBatchId());
|
||||
// s7PLC.writeInt32("M854", Math.toIntExact(num - newStep));
|
||||
Long materialFlag = redisCache.getCacheObject("materialFlag");
|
||||
redisCache.setCacheObject("nextStepFlag", 0L, 100, TimeUnit.HOURS);
|
||||
redisCache.setCacheObject("materialFlag", materialFlag == 1L ? 0L : 1L, 100, TimeUnit.HOURS);
|
||||
// s7PLC.writeBoolean("DB15.1.2",false);
|
||||
// s7PLC.writeFloat32("DB15.118",industryStepVos.get(0).getSetValue().floatValue());
|
||||
|
||||
Threads.sleep(5000);
|
||||
// 更新该批次中的全部道次的 "操作中" 字段为0
|
||||
IndustryStep step = new IndustryStep();
|
||||
// 设定值确认
|
||||
// s7PLC.writeBoolean("DB15.0.3",true);
|
||||
|
||||
step.setBatchId(industryStep.getBatchId());
|
||||
// while (s7PLC.readBoolean("DB15.0.3")){
|
||||
// s7PLC.writeBoolean("DB15.0.3",false);
|
||||
// }
|
||||
// }
|
||||
|
||||
step.setOperation(0L);
|
||||
industryStepMapper.updateIndustryStepByBatchId(step);
|
||||
// while (s7PLC.readBoolean("DB15.1.2")){
|
||||
// Threads.sleep(500);
|
||||
// }
|
||||
|
||||
IndustryStep industryStep1 = new IndustryStep();
|
||||
industryStep1.setBatchId(industryStep.getBatchId());
|
||||
Long newStep = industryStep.getStep() + 1L;
|
||||
industryStep1.setStep(newStep);
|
||||
// 查询下一步还有没有
|
||||
List<IndustryStepVo> industryStepVos = selectIndustryStepList(industryStep1);
|
||||
if (industryStepVos.size() == 0) {
|
||||
// 等于0说明没有下一步了 通知前端处理下一批
|
||||
return "2";
|
||||
}
|
||||
|
||||
// 如果不为0 说明该批次依然有道次未处理
|
||||
// 获取第一个 将其operation改为1
|
||||
industryStep1.setOperation(1L);
|
||||
// 更新一下下一步的状态
|
||||
industryStepMapper.updateIndustryStepByBatchId(industryStep1);
|
||||
// TODO 向plc发送当前道次
|
||||
s7PLC2.writeInt32("DB16.0", Math.toIntExact(newStep));
|
||||
// 当前厚度
|
||||
// s7PLC2.writeFloat32("DB16.6", industryStepVos.get(0).get);
|
||||
//以及剩余道次
|
||||
Long num = industryStepMapper.selectMaxStepNum(industryStep.getBatchId());
|
||||
s7PLC2.writeInt32("M854", Math.toIntExact(num - newStep));
|
||||
redisCache.setCacheObject("nextStepFlag", 0L, 100, TimeUnit.HOURS);
|
||||
s7PLC2.writeBoolean("DB15.1.2",false);
|
||||
s7PLC2.writeFloat32("DB15.118",industryStepVos.get(0).getSetValue().floatValue());
|
||||
s7PLC2.writeBoolean("DB15.0.3",true);
|
||||
|
||||
while (s7PLC2.readBoolean("DB15.0.3")){
|
||||
s7PLC2.writeBoolean("DB15.0.3",false);
|
||||
}
|
||||
}
|
||||
|
||||
while (s7PLC2.readBoolean("DB15.1.2")){
|
||||
Threads.sleep(500);
|
||||
}
|
||||
|
||||
s7PLC2.close();
|
||||
|
||||
return "1";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public String nextStepError(IndustryStep industryStep) {
|
||||
public int nextStepError(IndustryStep industryStep) {
|
||||
|
||||
s7PLC.writeBoolean("DB15.1.2",true);
|
||||
while (!s7PLC.readBoolean("DB15.1.2")){
|
||||
Threads.sleep(500);
|
||||
|
||||
// TODO PLC
|
||||
Long tag = redisCache.getCacheObject("nextStepFlagError");
|
||||
if (tag != 1L) {
|
||||
// nextStepFlag为切换道次的标志位,当其为1时需要进行切换道次,否则不用切换道次
|
||||
return 0;
|
||||
}
|
||||
if (s7PLC.readBoolean("DB15.1.2")){
|
||||
|
||||
|
||||
// s7PLC.writeBoolean("DB15.1.2", true);
|
||||
// while (!s7PLC.readBoolean("DB15.1.2")) {
|
||||
// Threads.sleep(500);
|
||||
//
|
||||
// }
|
||||
// if (s7PLC.readBoolean("DB15.1.2")) {
|
||||
Threads.sleep(5000);
|
||||
// 更新该批次中的全部道次的 "操作中" 字段为0
|
||||
IndustryStep step = new IndustryStep();
|
||||
@@ -278,7 +283,7 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
List<IndustryStepVo> industryStepVos = industryStepMapper.selectErrorIndustryStepList(industryStep1);
|
||||
if (industryStepVos.isEmpty()) {
|
||||
// 等于0说明没有下一步了 通知前端处理下一批
|
||||
return "2";
|
||||
return 2;
|
||||
}
|
||||
|
||||
// 如果不为0 说明该批次依然有道次未处理
|
||||
@@ -290,34 +295,33 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
industryStepMapper.updateIndustryStepByBatchId(industryStep1);
|
||||
|
||||
|
||||
|
||||
// TODO 向plc发送当前道次
|
||||
s7PLC.writeInt32("DB16.0", Math.toIntExact(newStep));
|
||||
// 当前厚度
|
||||
// s7PLC2.writeFloat32("DB16.6", industryStepVos.get(0).get);
|
||||
// s7PLC.writeInt32("DB16.0", Math.toIntExact(newStep));
|
||||
//以及剩余道次
|
||||
Long num = industryStepMapper.selectMaxStepNum(industryStep.getBatchId());
|
||||
s7PLC.writeInt32("M854", Math.toIntExact(num - newStep));
|
||||
// s7PLC.writeInt32("M854", Math.toIntExact(num - newStep));
|
||||
|
||||
Long materialFlagError = redisCache.getCacheObject("materialFlagError");
|
||||
redisCache.setCacheObject("nextStepFlagError", 0L, 100, TimeUnit.HOURS);
|
||||
redisCache.setCacheObject("materialFlagError", materialFlagError==1L?0L:1L, 100, TimeUnit.HOURS);
|
||||
|
||||
s7PLC.writeBoolean("DB15.1.2",false);
|
||||
// s7PLC.writeBoolean("DB15.1.2", false);
|
||||
//
|
||||
// s7PLC.writeFloat32("DB15.118", industryStepVos.get(0).getSetValue().floatValue());
|
||||
// s7PLC.writeBoolean("DB15.0.3", true);
|
||||
|
||||
s7PLC.writeFloat32("DB15.118",industryStepVos.get(0).getSetValue().floatValue());
|
||||
s7PLC.writeBoolean("DB15.0.3",true);
|
||||
|
||||
while (s7PLC.readBoolean("DB15.0.3")){
|
||||
s7PLC.writeBoolean("DB15.0.3",false);
|
||||
}
|
||||
}
|
||||
// while (s7PLC.readBoolean("DB15.0.3")) {
|
||||
// s7PLC.writeBoolean("DB15.0.3", false);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
while (s7PLC.readBoolean("DB15.1.2")){
|
||||
Threads.sleep(500);
|
||||
}
|
||||
// while (s7PLC.readBoolean("DB15.1.2")) {
|
||||
// Threads.sleep(500);
|
||||
// }
|
||||
|
||||
|
||||
return "1";
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -335,7 +339,6 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 将现在的道次改为运行中 目前的策略是小道次完成后再对齐
|
||||
industryStep.setStep(smallStep.getStep());
|
||||
industryStep.setOperation(1L);
|
||||
industryStep.setState(null);
|
||||
@@ -345,13 +348,16 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
|
||||
// TODO 缺少测试
|
||||
@Override
|
||||
public String finishError(Long batchId) {
|
||||
public int finishError(Long batchId) {
|
||||
|
||||
// 表示该批次全部处理完毕
|
||||
// 查询这里所有的异常料 完成了将其更新成6
|
||||
IndustryMaterialVo industryMaterialVo = new IndustryMaterialVo();
|
||||
industryMaterialVo.setState(5L);
|
||||
industryMaterialVo.setBatchId(batchId);
|
||||
industryMaterialVo.setDelFlag(1L);
|
||||
List<IndustryMaterialVo> industryMaterialVos = industryMaterialService.selectAbnormalList(industryMaterialVo);
|
||||
System.out.println(industryMaterialVos);
|
||||
for (IndustryMaterialVo materialVo : industryMaterialVos) {
|
||||
materialVo.setState(6L);
|
||||
materialVo.setOperation(0L);
|
||||
@@ -365,17 +371,17 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
industryStepMapper.updateAllIndustryStepByBatchId(industryStep);
|
||||
|
||||
// 如果当前模式是4辊
|
||||
if ("1".equals(mode)){
|
||||
if ("1".equals(mode)) {
|
||||
redisCache.deleteObject("materialLock");
|
||||
}
|
||||
|
||||
// 如果当前模式是2辊
|
||||
if ("0".equals(mode)){
|
||||
if ("0".equals(mode)) {
|
||||
// 2辊需要把当前材料提交到四辊库中
|
||||
Long materialLock = redis2Cache.getCacheObject("materialLock");
|
||||
if (Objects.isNull(materialLock) & materialLock!=0L){
|
||||
if (Objects.isNull(materialLock) & materialLock != 0L) {
|
||||
// 如果是空就写一个1进去占住锁
|
||||
redis2Cache.setCacheObject("materialLock",1L);
|
||||
redis2Cache.setCacheObject("materialLock", 1L);
|
||||
// 然后把非异常的东西都赛里面
|
||||
industryMaterialVo = new IndustryMaterialVo();
|
||||
industryMaterialVo.setBatchId(industryStep.getBatchId());
|
||||
@@ -385,13 +391,15 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
}
|
||||
}
|
||||
|
||||
s7PLC.writeBoolean("DB15.1.2",false);
|
||||
return null;
|
||||
// TODO PLC
|
||||
//s7PLC.writeBoolean("DB15.1.2", false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询数量
|
||||
* 查询数量
|
||||
*
|
||||
* @param batchId
|
||||
* @return
|
||||
*/
|
||||
@@ -421,26 +429,45 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
}
|
||||
List<IndustryTechnologyVo> industryTechnologyVos = industryTechnologyService.selectIndustryTechnologyList(industryTechnology);
|
||||
List<IndustryMaterialVo> industryMaterialVos = industryMaterialService.selectIndustryMaterialByBatchId(industryMaterial.getBatchId());
|
||||
// 添加特判 当工艺表为空时通知前端无此工艺不可进入轧制页面
|
||||
if (industryTechnologyVos.isEmpty()) {
|
||||
|
||||
// 把状态改回去
|
||||
if (Objects.nonNull(industryMaterialVos.get(0))) {
|
||||
for (IndustryMaterialVo materialVo : industryMaterialVos) {
|
||||
materialVo.setState(0L);
|
||||
industryMaterialMapper.updateIndustryMaterial(materialVo);
|
||||
}
|
||||
return Constants.NOT_HAVE_TECHNOLOGY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (IndustryMaterialVo industryMaterialVo : industryMaterialVos) {
|
||||
for (IndustryTechnologyVo industryTechnologyVo : industryTechnologyVos) {
|
||||
IndustryStep industryStep = new IndustryStep();
|
||||
industryStep.setStep(industryTechnologyVo.getStep());
|
||||
industryStep.setSetValue(industryTechnologyVo.getSetValue());
|
||||
industryStep.setReduction(industryTechnologyVo.getReduction());
|
||||
industryStep.setAngle(industryTechnologyVo.getAngle());
|
||||
industryStep.setMaterialId(industryMaterialVo.getId());
|
||||
industryStep.setBatchId(industryMaterial.getBatchId());
|
||||
IndustryStep industryStep = getIndustryStep(industryMaterial, industryMaterialVo, industryTechnologyVo);
|
||||
insertIndustryStep(industryStep);
|
||||
}
|
||||
industryMaterialVo.setStepSize((long) industryTechnologyVos.size());
|
||||
industryMaterialService.updateIndustryMaterial(industryMaterialVo);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static IndustryStep getIndustryStep(IndustryMaterial industryMaterial, IndustryMaterialVo
|
||||
industryMaterialVo, IndustryTechnologyVo industryTechnologyVo) {
|
||||
IndustryStep industryStep = new IndustryStep();
|
||||
industryStep.setStep(industryTechnologyVo.getStep());
|
||||
industryStep.setSetValue(industryTechnologyVo.getSetValue());
|
||||
industryStep.setReduction(industryTechnologyVo.getReduction());
|
||||
industryStep.setAngle(industryTechnologyVo.getAngle());
|
||||
industryStep.setMaterialId(industryMaterialVo.getId());
|
||||
industryStep.setBatchId(industryMaterial.getBatchId());
|
||||
return industryStep;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int finish(Long batchId) {
|
||||
@@ -457,17 +484,17 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
redisCache.deleteObject("size");
|
||||
|
||||
// 如果当前模式是4辊
|
||||
if ("1".equals(mode)){
|
||||
if ("1".equals(mode)) {
|
||||
redisCache.deleteObject("materialLock");
|
||||
}
|
||||
|
||||
// 如果当前模式是2辊
|
||||
if ("0".equals(mode)){
|
||||
if ("0".equals(mode)) {
|
||||
// 2辊需要把当前材料提交到四辊库中
|
||||
Long materialLock = redis2Cache.getCacheObject("materialLock");
|
||||
if (Objects.isNull(materialLock) & materialLock!=0L){
|
||||
if (Objects.isNull(materialLock) & materialLock != 0L) {
|
||||
// 如果是空就写一个1进去占住锁
|
||||
redis2Cache.setCacheObject("materialLock",1L);
|
||||
redis2Cache.setCacheObject("materialLock", 1L);
|
||||
// 然后把非异常的东西都赛里面
|
||||
IndustryMaterialVo industryMaterialVo = new IndustryMaterialVo();
|
||||
industryMaterialVo.setBatchId(industryStep.getBatchId());
|
||||
@@ -476,7 +503,9 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
industryMaterialService.insertIndustryMaterialToSlaveDataSource(industryMaterialVos);
|
||||
}
|
||||
}
|
||||
s7PLC.writeBoolean("DB15.1.2",false);
|
||||
|
||||
// TODO PLC
|
||||
// s7PLC.writeBoolean("DB15.1.2", false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -544,13 +573,15 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
@Override
|
||||
public void start(IndustryStep industryStep) {
|
||||
List<IndustryStepVo> industryStepVos = industryStepMapper.selectIndustryStepList(industryStep);
|
||||
if (!industryStepVos.isEmpty()){
|
||||
s7PLC.writeFloat32("DB15.118",industryStepVos.get(0).getSetValue().floatValue());
|
||||
s7PLC.writeBoolean("DB15.0.3",true);
|
||||
while (s7PLC.readBoolean("DB15.0.3")){
|
||||
s7PLC.writeBoolean("DB15.0.3",false);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO PLC
|
||||
// if (!industryStepVos.isEmpty()){
|
||||
// s7PLC.writeFloat32("DB15.118",industryStepVos.get(0).getSetValue().floatValue());
|
||||
// s7PLC.writeBoolean("DB15.0.3",true);
|
||||
// while (s7PLC.readBoolean("DB15.0.3")){
|
||||
// s7PLC.writeBoolean("DB15.0.3",false);
|
||||
// }
|
||||
// }
|
||||
industryStep.setOperation(1L);
|
||||
industryStepMapper.start(industryStep);
|
||||
}
|
||||
|
||||
@@ -61,12 +61,13 @@
|
||||
<if test="diameter != null ">and diameter = #{diameter}</if>
|
||||
<if test="batchId != null ">and batch_id = #{batchId}</if>
|
||||
<if test="sort != null ">and sort = #{sort}</if>
|
||||
<if test="state != null ">and state = #{state} or state=3</if>
|
||||
<if test="state != null ">and (state = #{state} or state=3)</if>
|
||||
<if test="stepSize != null ">and step_size = #{stepSize}</if>
|
||||
<if test="finalWidth != null and finalWidth != ''">and final_width = #{finalWidth}</if>
|
||||
<if test="finalDiameter != null and finalDiameter != ''">and final_diameter = #{finalDiameter}</if>
|
||||
<if test="weight != null and weight != ''">and weight = #{weight}</if>
|
||||
<if test="width != null and width != ''">and width = #{width}</if>
|
||||
<if test="delFlag != null and delFlag != ''">and del_flag = #{delFlag}</if>
|
||||
</where>
|
||||
order by sort
|
||||
</select>
|
||||
@@ -292,7 +293,9 @@
|
||||
<if test="delFlag != null">del_flag,</if>
|
||||
<if test="stepSize != null">step_size,</if>
|
||||
<if test="finalWidth != null">final_width,</if>
|
||||
<if test="finalWidth2 != null">final_width2,</if>
|
||||
<if test="finalDiameter != null">final_diameter,</if>
|
||||
<if test="finalDiameter2 != null">final_diameter2,</if>
|
||||
<if test="weight != null">weight,</if>
|
||||
<if test="width != null">width,</if>
|
||||
</trim>
|
||||
@@ -312,7 +315,9 @@
|
||||
<if test="state != null">#{state},</if>
|
||||
<if test="stepSize != null">#{stepSize},</if>
|
||||
<if test="finalWidth != null">#{finalWidth},</if>
|
||||
<if test="finalWidth2 != null">#{finalWidth2},</if>
|
||||
<if test="finalDiameter != null">#{finalDiameter},</if>
|
||||
<if test="finalDiameter2 != null">#{finalDiameter2},</if>
|
||||
<if test="weight != null">#{weight},</if>
|
||||
<if test="width != null">#{width},</if>
|
||||
</trim>
|
||||
@@ -335,7 +340,9 @@
|
||||
<if test="state != null">state = #{state},</if>
|
||||
<if test="stepSize != null">step_size = #{stepSize},</if>
|
||||
<if test="finalWidth != null">final_width = #{finalWidth},</if>
|
||||
<if test="finalWidth2 != null">final_width2 = #{finalWidth2},</if>
|
||||
<if test="finalDiameter != null">final_diameter = #{finalDiameter},</if>
|
||||
<if test="finalDiameter2 != null">final_diameter2 = #{finalDiameter2},</if>
|
||||
<if test="weight != null">weight = #{weight},</if>
|
||||
<if test="width != null">width = #{width},</if>
|
||||
</trim>
|
||||
@@ -349,7 +356,7 @@
|
||||
<if test="state == 0">state =1,</if>
|
||||
<if test="state == 1">state =2,</if>
|
||||
<if test="state == 3">state =4,</if>
|
||||
<if test="state == 4">state =5,</if>
|
||||
<if test="state == 4 and delFlag ==1">state =5,</if>
|
||||
<if test="state == 5">state =6,</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
|
||||
@@ -114,7 +114,6 @@
|
||||
and step.del_flag=0
|
||||
and step.batch_id = #{batchId}
|
||||
and im.state =1
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
@@ -126,6 +125,7 @@
|
||||
and step.del_flag=1
|
||||
and step.batch_id = #{batchId}
|
||||
and im.state =5
|
||||
and im.del_flag=1
|
||||
</select>
|
||||
|
||||
<select id="selectMaxStepNum" resultType="java.lang.Long" parameterType="Long">
|
||||
|
||||
Reference in New Issue
Block a user