diff --git a/industry-admin/src/main/java/com/industry/web/controller/work/IndustryBatchController.java b/industry-admin/src/main/java/com/industry/web/controller/work/IndustryBatchController.java index 3ccc5dc1..d3f0e27a 100644 --- a/industry-admin/src/main/java/com/industry/web/controller/work/IndustryBatchController.java +++ b/industry-admin/src/main/java/com/industry/web/controller/work/IndustryBatchController.java @@ -48,22 +48,6 @@ public class IndustryBatchController extends BaseController return getDataTable(list); } - - - /** - * 导出批次总表列表 - - @PreAuthorize("@ss.hasPermi('work:batch:export')") - @Log(title = "批次总表", businessType = BusinessType.EXPORT) - @PostMapping("/export") - public void export(HttpServletResponse response, IndustryBatch industryBatch) - { - List list = industryBatchService.selectIndustryBatchList(industryBatch); - ExcelUtil util = new ExcelUtil(IndustryBatch.class); - util.exportExcel(response, list, "批次总表数据"); - } - */ - /** * 获取批次总表详细信息 */ diff --git a/industry-admin/src/main/java/com/industry/web/controller/work/IndustryFaultController.java b/industry-admin/src/main/java/com/industry/web/controller/work/IndustryFaultController.java index 2fed201f..89050f49 100644 --- a/industry-admin/src/main/java/com/industry/web/controller/work/IndustryFaultController.java +++ b/industry-admin/src/main/java/com/industry/web/controller/work/IndustryFaultController.java @@ -49,20 +49,6 @@ public class IndustryFaultController extends BaseController return getDataTable(list); } - /** - * 导出故障管理列表 - - @PreAuthorize("@ss.hasPermi('system:fault:export')") - @Log(title = "故障管理", businessType = BusinessType.EXPORT) - @PostMapping("/export") - public void export(HttpServletResponse response, IndustryFault industryFault) - { - List list = industryFaultService.selectIndustryFaultList(industryFault); - ExcelUtil util = new ExcelUtil(IndustryFault.class); - util.exportExcel(response, list, "故障管理数据"); - } - */ - /** * 获取故障管理详细信息 */ diff --git a/industry-admin/src/main/java/com/industry/web/controller/work/IndustryMaterialController.java b/industry-admin/src/main/java/com/industry/web/controller/work/IndustryMaterialController.java index cc0a6ee3..10f2b303 100644 --- a/industry-admin/src/main/java/com/industry/web/controller/work/IndustryMaterialController.java +++ b/industry-admin/src/main/java/com/industry/web/controller/work/IndustryMaterialController.java @@ -71,7 +71,6 @@ public class IndustryMaterialController extends BaseController /** * 查询钽靶主类列表 */ - //@PreAuthorize("@ss.hasPermi('system:material:list')") @GetMapping("/list") public TableDataInfo list(IndustryMaterial industryMaterial) { @@ -82,9 +81,8 @@ public class IndustryMaterialController extends BaseController /** - * 查询钽靶主类列表 + * 查询钽靶主类列表,和上述接口差在只会查单一状态的列表 */ - //@PreAuthorize("@ss.hasPermi('system:material:list')") @GetMapping("/list1") public TableDataInfo list1(IndustryMaterial industryMaterial) { @@ -117,23 +115,6 @@ public class IndustryMaterialController extends BaseController List list = industryMaterialService.selectAbnormalList(industryMaterial); return getDataTable(list); } - - - - /** - * 导出钽靶主类列表 - - @PreAuthorize("@ss.hasPermi('system:material:export')") - @Log(title = "钽靶主类", businessType = BusinessType.EXPORT) - @PostMapping("/export") - public void export(HttpServletResponse response, IndustryMaterial industryMaterial) - { - List list = industryMaterialService.selectIndustryMaterialList(industryMaterial); - ExcelUtil util = new ExcelUtil(IndustryMaterial.class); - util.exportExcel(response, list, "钽靶主类数据"); - } - */ - /** * 获取钽靶主类详细信息 */ @@ -194,7 +175,6 @@ public class IndustryMaterialController extends BaseController IndustryStep industryStep = new IndustryStep(); industryStep.setStep(1L); industryStep.setDelFlag(0L); - industryStepService.start(industryStep); return success(industryMaterialService.start(industryMaterial)); } @@ -280,19 +260,23 @@ public class IndustryMaterialController extends BaseController @GetMapping("/nextStepFlag") public AjaxResult nextStepFlag(){ Long flag = redisCache.getCacheObject("nextStepFlag"); - if (flag==0L){ + if (Objects.nonNull(flag) && flag==0L){ return AjaxResult.success(0); + }else{ + return AjaxResult.success(1); } - return AjaxResult.success(1); + } @GetMapping("/nextStepFlagError") public AjaxResult nextStepFlagError(){ Long flag = redisCache.getCacheObject("nextStepFlagError"); - if (flag==0L){ + if (Objects.nonNull(flag) && flag==0L){ return AjaxResult.success(0); + }else{ + return AjaxResult.success(1); } - return AjaxResult.success(1); + } @GetMapping("/clear") diff --git a/industry-admin/src/main/java/com/industry/web/controller/work/IndustryStepController.java b/industry-admin/src/main/java/com/industry/web/controller/work/IndustryStepController.java index c71814fc..ca693bef 100644 --- a/industry-admin/src/main/java/com/industry/web/controller/work/IndustryStepController.java +++ b/industry-admin/src/main/java/com/industry/web/controller/work/IndustryStepController.java @@ -62,20 +62,6 @@ public class IndustryStepController extends BaseController return AjaxResult.success(list); } - /** - * 导出钽靶道次表列表 - - @PreAuthorize("@ss.hasPermi('system:step:export')") - @Log(title = "钽靶道次表", businessType = BusinessType.EXPORT) - @PostMapping("/export") - public void export(HttpServletResponse response, IndustryStep industryStep) - { - List list = industryStepService.selectIndustryStepList(industryStep); - ExcelUtil util = new ExcelUtil(IndustryStep.class); - util.exportExcel(response, list, "钽靶道次表数据"); - } - */ - /** * 获取钽靶道次表详细信息 */ diff --git a/industry-admin/src/main/resources/application-druid.yml b/industry-admin/src/main/resources/application-druid.yml index f157200c..ec5c353e 100644 --- a/industry-admin/src/main/resources/application-druid.yml +++ b/industry-admin/src/main/resources/application-druid.yml @@ -6,16 +6,16 @@ spring: druid: # 主库数据源 master: - url: jdbc:mysql://localhost:3306/industry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + url: jdbc:mysql://49.233.157.185:3306/industry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root - password: root + password: WANGyu11! # 从库数据源 slave: # 从数据源开关/默认关闭 enabled: false - url: jdbc:mysql://localhost:3306/industry2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + url: jdbc:mysql://49.233.157.185:3306/industry2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root - password: root + password: WANGyu11! # 初始连接数 initialSize: 5 # 最小连接池数量 diff --git a/industry-admin/src/main/resources/application.yml b/industry-admin/src/main/resources/application.yml index 4fbf0fd2..c0657814 100644 --- a/industry-admin/src/main/resources/application.yml +++ b/industry-admin/src/main/resources/application.yml @@ -37,8 +37,8 @@ server: # 日志配置 logging: level: - com.industry: error - org.springframework: error + com.industry: debug + org.springframework: debug # 用户配置 user: @@ -71,13 +71,13 @@ spring: # redis 配置 redis: # 地址 - host: localhost + host: 49.233.157.185 # 端口,默认为6379 port: 6379 # 数据库索引 database: 0 # 密码 - password: + password: WANGyu11! # 连接超时时间 timeout: 10000 lettuce: @@ -92,11 +92,11 @@ spring: max-wait: -1 redis2: # 地址 - host: localhost + host: 49.233.157.185 # 端口号 port: 6379 # 密码 - password: + password: WANGyu11! # 连接超时时间 timeout: 10000 # 数据库索引 diff --git a/industry-common/src/main/java/com/industry/common/constant/Constants.java b/industry-common/src/main/java/com/industry/common/constant/Constants.java index 4309232d..56085250 100644 --- a/industry-common/src/main/java/com/industry/common/constant/Constants.java +++ b/industry-common/src/main/java/com/industry/common/constant/Constants.java @@ -10,6 +10,22 @@ import io.jsonwebtoken.Claims; */ public class Constants { + + /** + * 轧制结束 + */ + public static final int COMPLETE_PROCESS = 2; + + /** + * 无此工艺 + */ + public static final int NOT_HAVE_TECHNOLOGY = 2; + + /** + * 为处理此道次 + */ + public static final int NOT_PROCESS = 2; + /** * UTF-8 字符集 */ @@ -165,6 +181,7 @@ public class Constants */ public static final String[] JOB_WHITELIST_STR = { "com.industry.quartz.task" }; + /** * 定时任务违规的字符 */ diff --git a/industry-system/src/main/java/com/industry/work/service/IIndustryMaterialService.java b/industry-system/src/main/java/com/industry/work/service/IIndustryMaterialService.java index 3009473d..4ab97377 100644 --- a/industry-system/src/main/java/com/industry/work/service/IIndustryMaterialService.java +++ b/industry-system/src/main/java/com/industry/work/service/IIndustryMaterialService.java @@ -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 selectIndustryMaterialList1(IndustryMaterial industryMaterial); diff --git a/industry-system/src/main/java/com/industry/work/service/IIndustryStepService.java b/industry-system/src/main/java/com/industry/work/service/IIndustryStepService.java index 2b05d63a..a85cee61 100644 --- a/industry-system/src/main/java/com/industry/work/service/IIndustryStepService.java +++ b/industry-system/src/main/java/com/industry/work/service/IIndustryStepService.java @@ -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); /** diff --git a/industry-system/src/main/java/com/industry/work/service/impl/IndustryMaterialServiceImpl.java b/industry-system/src/main/java/com/industry/work/service/impl/IndustryMaterialServiceImpl.java index 1efedd02..7a7e6291 100644 --- a/industry-system/src/main/java/com/industry/work/service/impl/IndustryMaterialServiceImpl.java +++ b/industry-system/src/main/java/com/industry/work/service/impl/IndustryMaterialServiceImpl.java @@ -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 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 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; } diff --git a/industry-system/src/main/java/com/industry/work/service/impl/IndustryStepServiceImpl.java b/industry-system/src/main/java/com/industry/work/service/impl/IndustryStepServiceImpl.java index 2692a4e6..f2765586 100644 --- a/industry-system/src/main/java/com/industry/work/service/impl/IndustryStepServiceImpl.java +++ b/industry-system/src/main/java/com/industry/work/service/impl/IndustryStepServiceImpl.java @@ -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 selectIndustryStepListByProcess(IndustryStep industryStep) { - - String materialId = industryStep.getMaterialId(); Long batchId = industryStep.getBatchId(); industryStep.setMaterialId(materialId); industryStep.setBatchId(batchId); List 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 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 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 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 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 industryTechnologyVos = industryTechnologyService.selectIndustryTechnologyList(industryTechnology); List 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 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); } diff --git a/industry-system/src/main/resources/mapper/work/IndustryMaterialMapper.xml b/industry-system/src/main/resources/mapper/work/IndustryMaterialMapper.xml index 7876db1f..871fc69c 100644 --- a/industry-system/src/main/resources/mapper/work/IndustryMaterialMapper.xml +++ b/industry-system/src/main/resources/mapper/work/IndustryMaterialMapper.xml @@ -61,12 +61,13 @@ and diameter = #{diameter} and batch_id = #{batchId} and sort = #{sort} - and state = #{state} or state=3 + and (state = #{state} or state=3) and step_size = #{stepSize} and final_width = #{finalWidth} and final_diameter = #{finalDiameter} and weight = #{weight} and width = #{width} + and del_flag = #{delFlag} order by sort @@ -292,7 +293,9 @@ del_flag, step_size, final_width, + final_width2, final_diameter, + final_diameter2, weight, width, @@ -312,7 +315,9 @@ #{state}, #{stepSize}, #{finalWidth}, + #{finalWidth2}, #{finalDiameter}, + #{finalDiameter2}, #{weight}, #{width}, @@ -335,7 +340,9 @@ state = #{state}, step_size = #{stepSize}, final_width = #{finalWidth}, + final_width2 = #{finalWidth2}, final_diameter = #{finalDiameter}, + final_diameter2 = #{finalDiameter2}, weight = #{weight}, width = #{width}, @@ -349,7 +356,7 @@ state =1, state =2, state =4, - state =5, + state =5, state =6, where id = #{id} diff --git a/industry-system/src/main/resources/mapper/work/IndustryStepMapper.xml b/industry-system/src/main/resources/mapper/work/IndustryStepMapper.xml index 58f42d6c..7f27e87e 100644 --- a/industry-system/src/main/resources/mapper/work/IndustryStepMapper.xml +++ b/industry-system/src/main/resources/mapper/work/IndustryStepMapper.xml @@ -114,7 +114,6 @@ and step.del_flag=0 and step.batch_id = #{batchId} and im.state =1 - @@ -126,6 +125,7 @@ and step.del_flag=1 and step.batch_id = #{batchId} and im.state =5 + and im.del_flag=1