加入二辊将数据传入四辊调试,加入锁机制转化
This commit is contained in:
@@ -116,7 +116,7 @@ public interface IIndustryMaterialService
|
||||
|
||||
void deleteIndustryMaterialByState(Long state);
|
||||
|
||||
void insertIndustryMaterialToSlaveDataSource(List<IndustryMaterialVo> industryMaterialVos);
|
||||
String insertIndustryMaterialToSlaveDataSource(List<IndustryMaterialVo> industryMaterialVos);
|
||||
|
||||
/**3
|
||||
*
|
||||
@@ -125,4 +125,12 @@ public interface IIndustryMaterialService
|
||||
* @return
|
||||
*/
|
||||
List<IndustryMaterialVo> selectIndustryListRecord(IndustryMaterial industryMaterial);
|
||||
|
||||
/**
|
||||
* 查询四辊数据是否存在0的,将0的全部删除
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean clearNotProcessMaterial();
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,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.Redis2Cache;
|
||||
import com.industry.common.core.redis.RedisCache;
|
||||
|
||||
import com.industry.common.enums.DataSourceType;
|
||||
@@ -54,6 +55,9 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Autowired
|
||||
private Redis2Cache redis2Cache;
|
||||
|
||||
@Autowired
|
||||
private IMomService momService;
|
||||
|
||||
@@ -115,8 +119,10 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
|
||||
@Override
|
||||
@DataSource(value = DataSourceType.SLAVE)
|
||||
public void insertIndustryMaterialToSlaveDataSource(List<IndustryMaterialVo> industryMaterialVos) {
|
||||
public String insertIndustryMaterialToSlaveDataSource(List<IndustryMaterialVo> industryMaterialVos) {
|
||||
|
||||
// 直接删掉扫入并且未轧制的,写入二辊数据到四辊机器里面
|
||||
clearSystem();
|
||||
// TODO 这里需要查一下数据库查看是否有正在轧或者说是未轧的情况 state=0,1,3,4
|
||||
List<IndustryMaterialVo> industryMaterialVos1 = industryMaterialMapper.selectIndustryMaterialListAndNotFinish();
|
||||
|
||||
@@ -136,9 +142,12 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
industryMaterialVo.setFinalWidth(null);
|
||||
industryMaterialMapper.insertIndustryMaterial(industryMaterialVo);
|
||||
}
|
||||
|
||||
return "写入成功";
|
||||
}
|
||||
|
||||
|
||||
return "检测到存在物料正在轧制";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,6 +155,21 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
return industryMaterialMapper.selectIndustryListRecord(industryMaterial);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DataSource(value = DataSourceType.SLAVE)
|
||||
public boolean clearNotProcessMaterial() {
|
||||
IndustryMaterial industryMaterial = new IndustryMaterial();
|
||||
industryMaterial.setState(0L);
|
||||
List<IndustryMaterialVo> industryMaterialVos = industryMaterialMapper.selectAbnormalList(industryMaterial);
|
||||
if (industryMaterialVos.isEmpty()){
|
||||
|
||||
// 代表状态至少是 1 2 3 4 5 6
|
||||
return false;
|
||||
}
|
||||
industryMaterialMapper.deleteIndustryMaterialByState(0L);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增钽靶主类
|
||||
@@ -749,7 +773,7 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
|
||||
if ("1".equals(mode)) {
|
||||
Long materialLock = redisCache.getCacheObject("materialLock");
|
||||
if (Objects.isNull(materialLock)) {
|
||||
if (Objects.isNull(materialLock) || materialLock !=1L) {
|
||||
// 如果没有获取到锁对象就向里面写一个锁对象
|
||||
redisCache.setCacheObject("materialLock", 0L, 100, TimeUnit.HOURS);
|
||||
}
|
||||
@@ -891,4 +915,17 @@ public class IndustryMaterialServiceImpl implements IIndustryMaterialService {
|
||||
}
|
||||
|
||||
|
||||
@DataSource(value = DataSourceType.SLAVE)
|
||||
private void clearSystem() {
|
||||
redis2Cache.deleteObject("sort");
|
||||
redis2Cache.deleteObject("batchId");
|
||||
redis2Cache.deleteObject("leftId");
|
||||
redis2Cache.deleteObject("rightId");
|
||||
|
||||
s7PLC.writeString("DB4.30","\u0000\u0000\u0000\u0000");
|
||||
s7PLC.writeString("DB44.30","\u0000\u0000\u0000\u0000");
|
||||
industryMaterialMapper.deleteIndustryMaterialByState(0L);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -403,7 +403,7 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
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);
|
||||
// 然后把非异常的东西都赛里面
|
||||
@@ -411,7 +411,9 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
industryMaterialVo.setBatchId(industryStep.getBatchId());
|
||||
industryMaterialVo.setState(6L);
|
||||
List<IndustryMaterialVo> industryMaterialVos1 = industryMaterialMapper.selectIndustryMaterialList1(industryMaterialVo);
|
||||
industryMaterialService.insertIndustryMaterialToSlaveDataSource(industryMaterialVos1);
|
||||
String result = industryMaterialService.insertIndustryMaterialToSlaveDataSource(industryMaterialVos1);
|
||||
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,15 +519,37 @@ public class IndustryStepServiceImpl implements IIndustryStepService {
|
||||
if ("0".equals(mode)) {
|
||||
// 2辊需要把当前材料提交到四辊库中
|
||||
Long materialLock = redis2Cache.getCacheObject("materialLock");
|
||||
if (Objects.isNull(materialLock) & materialLock != 0L) {
|
||||
|
||||
// DONE 这里还有一个问题来自,他拿到的锁标志是0代表四辊正在工作 有一个种可能来自四辊工作但是都是未轧制的(state==0),这个时候应该删除然后直接进入
|
||||
if (Objects.nonNull(materialLock) && materialLock == 0L){
|
||||
// 这个时候要加一个方法 如果是状态为0的直接全部clear然后改锁标志
|
||||
|
||||
// 这里的返回值如果是true则代表虽然四辊站住锁了但是物料未轧制。 返回值是true的情况就已经将state的都删掉了
|
||||
// 根据二辊优先原则,将二辊未轧制数据直接删除解除锁让新数据进来。
|
||||
boolean flag = industryMaterialService.clearNotProcessMaterial();
|
||||
if (flag){
|
||||
// 删除后将锁标志改为空也就是直接删除锁
|
||||
redis2Cache.deleteObject("materialLock");
|
||||
// 删除后重新获取供下方使用
|
||||
materialLock = redis2Cache.getCacheObject("materialLock");
|
||||
}
|
||||
|
||||
// 如果上面的bool返回的是false 则代表四辊中有数据进行轧制此时应该巩固锁不让二辊物料进入
|
||||
else{
|
||||
redis2Cache.setCacheObject("materialLock", 0L,3000,TimeUnit.HOURS);
|
||||
}
|
||||
}
|
||||
if (Objects.isNull(materialLock) || materialLock != 0L) {
|
||||
|
||||
// 如果是空就写一个1进去占住锁
|
||||
redis2Cache.setCacheObject("materialLock", 1L);
|
||||
redis2Cache.setCacheObject("materialLock", 1L,3000,TimeUnit.HOURS);
|
||||
// 然后把非异常的东西都赛里面
|
||||
IndustryMaterialVo industryMaterialVo = new IndustryMaterialVo();
|
||||
industryMaterialVo.setBatchId(industryStep.getBatchId());
|
||||
industryMaterialVo.setState(2L);
|
||||
List<IndustryMaterialVo> industryMaterialVos = industryMaterialMapper.selectIndustryMaterialList1(industryMaterialVo);
|
||||
industryMaterialService.insertIndustryMaterialToSlaveDataSource(industryMaterialVos);
|
||||
String result = industryMaterialService.insertIndustryMaterialToSlaveDataSource(industryMaterialVos);
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user