package com.ruoyi.ams.xuankuang.service; import cn.hutool.core.util.NumberUtil; import com.ruoyi.ams.order.domain.WmsDocOrderHeader; import com.ruoyi.ams.order.mapper.WmsDocOrderHeaderMapper; import com.ruoyi.ams.task.domain.WcsTask; import com.ruoyi.ams.task.service.IWcsTaskService; import com.ruoyi.ams.xuankuang.domain.dto.SkuAgitatedTankAttrDTO; import com.ruoyi.base.constant.Constant; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.hard.xuankang.StirringTankClient; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import static com.ruoyi.hard.xuankang.StirringTankClient.STIR_TANK_COMMAND.*; /** * @author Jwk * @version 1.0 * @date 2023/4/24 15:31 */ @Slf4j @Service public class StirringTankClientService { @Autowired private IWcsTaskService wcsTaskService; @Autowired StirringTankClient stirringTankClient; @Autowired BaseLocationInfoSubService baseLocationInfoSubService; @Autowired WmsDocOrderSubService wmsDocOrderSubService; @Autowired WmsDocOrderHeaderMapper wmsDocOrderHeaderMapper; //物料的换算比率映射 PS: 换算比例 Rate=20 代表一份物料20kg private static final Map skuToAgitatedTankAttrMapper = new HashMap(){ { put("Na2CO3", new SkuAgitatedTankAttrDTO().setReadDosageCommand(READ_THE_STIRRING_TANK_07) .setReadLiquidLevel(READ_THE_STIRRING_TANK_01).setAutomatic(Boolean.FALSE) .setRate(25).setUnableBitIndex(5).setAbleBitIndex(5).setStartBitIndex(5) .setRunBitIndex(5).setErrorBitIndex(5).setEndBitIndex(5).setConfirmBitIndex(5));//碳酸钠 put("C5H10OS2", new SkuAgitatedTankAttrDTO().setReadDosageCommand(READ_THE_STIRRING_TANK_08) .setReadLiquidLevel(READ_THE_STIRRING_TANK_02).setAutomatic(Boolean.TRUE) .setRate(25).setUnableBitIndex(1).setAbleBitIndex(1).setStartBitIndex(1) .setRunBitIndex(1).setErrorBitIndex(1).setEndBitIndex(1).setConfirmBitIndex(1));//丁黄药 put("C4H9O2PSSNH4", new SkuAgitatedTankAttrDTO().setReadDosageCommand(READ_THE_STIRRING_TANK_09) .setReadLiquidLevel(READ_THE_STIRRING_TANK_03).setAutomatic(Boolean.FALSE) .setRate(5).setUnableBitIndex(5).setAbleBitIndex(5).setStartBitIndex(5) .setRunBitIndex(5).setErrorBitIndex(5).setEndBitIndex(5).setConfirmBitIndex(5));//丁铵黑药 put("(NaPO3)6", new SkuAgitatedTankAttrDTO().setReadDosageCommand(READ_THE_STIRRING_TANK_10) .setReadLiquidLevel(READ_THE_STIRRING_TANK_04).setAutomatic(Boolean.TRUE) .setRate(20).setUnableBitIndex(3).setAbleBitIndex(3).setStartBitIndex(3) .setRunBitIndex(3).setErrorBitIndex(3).setEndBitIndex(3).setConfirmBitIndex(3));//六偏磷酸钠 put("(NH4)2SO4", new SkuAgitatedTankAttrDTO().setReadDosageCommand(READ_THE_STIRRING_TANK_11) .setReadLiquidLevel(READ_THE_STIRRING_TANK_05).setAutomatic(Boolean.TRUE) .setRate(20).setUnableBitIndex(4).setAbleBitIndex(4).setStartBitIndex(4) .setRunBitIndex(4).setErrorBitIndex(4).setEndBitIndex(4).setConfirmBitIndex(4));//硫酸铵 // put("CH3CH2OCS2Na", new SkuAgitatedTankAttrDTO().setReadDosageCommand(READ_THE_STIRRING_TANK_12) // .setReadLiquidLevel(READ_THE_STIRRING_TANK_06).setAutomatic(Boolean.TRUE) // .setRate(25).setUnableBitIndex(5).setAbleBitIndex(5).setStartBitIndex(5) // .setRunBitIndex(5).setErrorBitIndex(5).setEndBitIndex(5).setConfirmBitIndex(5));//乙黄药 put("CH3CH2OCS2Na", new SkuAgitatedTankAttrDTO().setReadDosageCommand(READ_THE_STIRRING_TANK_08) .setReadLiquidLevel(READ_THE_STIRRING_TANK_02).setAutomatic(Boolean.TRUE) .setRate(25).setUnableBitIndex(1).setAbleBitIndex(1).setStartBitIndex(1) .setRunBitIndex(1).setErrorBitIndex(1).setEndBitIndex(1).setConfirmBitIndex(1));//乙黄药 暂用丁黄药搅拌槽 } }; public static final List getSkuList(){ return skuToAgitatedTankAttrMapper.entrySet().stream().filter(item -> item.getValue().getAutomatic()).map(Map.Entry::getKey).collect(Collectors.toList()); } public Boolean setTaskEnd(String skuChemicalName) { SkuAgitatedTankAttrDTO skuAgitatedTankAttrDTO = skuToAgitatedTankAttrMapper.get(skuChemicalName); return stirringTankClient.writeTaskEnd(skuAgitatedTankAttrDTO.getEndBitIndex()); } public Boolean setTaskError(String skuChemicalName) { SkuAgitatedTankAttrDTO skuAgitatedTankAttrDTO = skuToAgitatedTankAttrMapper.get(skuChemicalName); return stirringTankClient.writeTaskError(skuAgitatedTankAttrDTO.getErrorBitIndex()); } public Boolean setTaskRun(String skuChemicalName) { SkuAgitatedTankAttrDTO skuAgitatedTankAttrDTO = skuToAgitatedTankAttrMapper.get(skuChemicalName); return stirringTankClient.writeTaskRun(skuAgitatedTankAttrDTO.getRunBitIndex()); } /** * 写无法注入 */ public Boolean setUnableInject(String skuChemicalName){ SkuAgitatedTankAttrDTO skuAgitatedTankAttrDTO = skuToAgitatedTankAttrMapper.get(skuChemicalName); return stirringTankClient.writeUnableInject(skuAgitatedTankAttrDTO.getUnableBitIndex()); } /** * 写可以注入 * @param skuChemicalName * @return */ public Boolean setAbleInject(String skuChemicalName){ SkuAgitatedTankAttrDTO skuAgitatedTankAttrDTO = skuToAgitatedTankAttrMapper.get(skuChemicalName); return stirringTankClient.writeAbleInject(skuAgitatedTankAttrDTO.getAbleBitIndex()); } /** * 确认是否现在就需要生成任务 * @param skuChemicalName * @return */ public Boolean confirmNeedNow(String skuChemicalName) { SkuAgitatedTankAttrDTO skuAgitatedTankAttrDTO = skuToAgitatedTankAttrMapper.get(skuChemicalName); return stirringTankClient.readConfirmNeedMark(skuAgitatedTankAttrDTO.getConfirmBitIndex()); } /** * 确认是否可以执行出库任务 * @param skuChemicalName * @return */ public Boolean enableExcuteTask(String skuChemicalName) { SkuAgitatedTankAttrDTO skuAgitatedTankAttrDTO = skuToAgitatedTankAttrMapper.get(skuChemicalName); return stirringTankClient.readExcuteTaskMark(skuAgitatedTankAttrDTO.getStartBitIndex()); } /** * 读取并计算物料的使用剂量转换为物料袋数 * @param skuChemicalName 物料化学名称 * @return */ public BigDecimal getNeededInvQuantity(String skuChemicalName){ SkuAgitatedTankAttrDTO skuAgitatedTankAttrDTO = skuToAgitatedTankAttrMapper.get(skuChemicalName); Number neededWeightCount = stirringTankClient.readNeedDosage(skuAgitatedTankAttrDTO.getReadDosageCommand()); return NumberUtil.div(neededWeightCount, skuAgitatedTankAttrDTO.getRate(), 0); } /** * 读取物料搅拌槽液位值 * @param skuChemicalName 物料化学名称 * @return */ public BigDecimal getSkuLiquidLevel(String skuChemicalName){ SkuAgitatedTankAttrDTO skuAgitatedTankAttrDTO = skuToAgitatedTankAttrMapper.get(skuChemicalName); Number neededWeightCount = stirringTankClient.readLiquidLevel(skuAgitatedTankAttrDTO.getReadDosageCommand()); return NumberUtil.div(neededWeightCount, BigDecimal.ONE); } /** * 对比碳酸钠库存 * * @return */ public boolean matchInventory_1() { String sku = "Na2CO3"; BigDecimal b = new BigDecimal(0); //读注入标志位 boolean[] booleans = stirringTankClient.readTank13(); if (booleans[15] = true) { //读到的碳酸钠所需剂量 Number number = stirringTankClient.readTank07(); int i = number.intValue(); int i1 = ConvertUtils.convertToInt(i); int qty = ConvertUtils.convertToQty(i1); int remainder = ConvertUtils.convertToRemainder(i1); if (remainder >= 25) { qty = qty + 1; } List bigDecimals = baseLocationInfoSubService.checkInventory(sku); for (BigDecimal bigDecimal : bigDecimals) { b = b.add(bigDecimal); } if (qty <= b.intValue()) { WmsDocOrderHeader wmsDocOrderHeader = new WmsDocOrderHeader(); wmsDocOrderHeader.setSoReference3("1"); List wmsDocOrderHeaders = wmsDocOrderHeaderMapper.selectWmsDocOrderHeaderList1(wmsDocOrderHeader); String orderNo = wmsDocOrderHeaders.get(0).getOrderNo(); if (wmsDocOrderHeaders != null && wmsDocOrderHeaders.size() > 0) { boolean[] booleans1 = stirringTankClient.readTank14(); if (booleans1[15] = true) { AjaxResult ajaxResult = wmsDocOrderSubService.initOrderDetails(orderNo); if (ajaxResult.isSuccess()) { stirringTankClient.writeTank03(); } return true; } return false; } stirringTankClient.writeTank02(); stirringTankClient.writeTank01f(); outbound_1(qty); return true; } else { stirringTankClient.writeTank01(); stirringTankClient.writeTank02f(); return false; } } return false; } /** * 生成碳酸钠出库单 * * @return */ public AjaxResult outbound_1(int qty) { String sku = "Na2CO3"; BigDecimal qty1 = new BigDecimal(qty); String orderNo = wmsDocOrderSubService.generateAnOutboundOrder(sku, qty1); return AjaxResult.success(); } /** * 对比丁黄药库存 * * @return */ public boolean matchInventory_2() { String sku = "C5H10OS2"; BigDecimal b = new BigDecimal(0); //读注入标志位 boolean[] booleans = stirringTankClient.readTank13(); if (booleans[14] = true) { //读到的丁黄药所需剂量 Number number = stirringTankClient.readTank08(); int i = number.intValue(); int i1 = ConvertUtils.convertToInt1(i); int qty = ConvertUtils.convertToQty1(i1); int remainder = ConvertUtils.convertToRemainder1(i1); if (remainder >= 20) { qty = qty + 1; } List bigDecimals = baseLocationInfoSubService.checkInventory(sku); for (BigDecimal bigDecimal : bigDecimals) { b = b.add(bigDecimal); } if (qty <= b.intValue()) { WmsDocOrderHeader wmsDocOrderHeader = new WmsDocOrderHeader(); wmsDocOrderHeader.setSoReference3("2"); List wmsDocOrderHeaders = wmsDocOrderHeaderMapper.selectWmsDocOrderHeaderList1(wmsDocOrderHeader); String orderNo = wmsDocOrderHeaders.get(0).getOrderNo(); if (wmsDocOrderHeaders != null && wmsDocOrderHeaders.size() > 0) { boolean[] booleans1 = stirringTankClient.readTank14(); if (booleans1[14] = true) { AjaxResult ajaxResult = wmsDocOrderSubService.initOrderDetails(orderNo); if (ajaxResult.isSuccess()) { stirringTankClient.writeTank03_1(); } return true; } return false; } stirringTankClient.writeTank02_1(); stirringTankClient.writeTank01_1f(); outbound_2(qty); return true; } else { stirringTankClient.writeTank01_1(); stirringTankClient.writeTank02_1f(); return false; } } return false; } /** * 生成丁黄药出库单 * * @return */ public AjaxResult outbound_2(int qty) { String sku = "C5H10OS2"; Number number = stirringTankClient.readTank08(); BigDecimal qty1 = new BigDecimal(qty); String order = wmsDocOrderSubService.generateAnOutboundOrder(sku, qty1); return AjaxResult.success(); } /** * 对比丁铵黑药库存 * * @return */ public boolean matchInventory_3() { String sku = "C4H9O2PSSNH4"; BigDecimal b = new BigDecimal(0); //读注入标志位 boolean[] booleans = stirringTankClient.readTank13(); if (booleans[13] = true) { //读到的丁铵黑药所需剂量 Number number = stirringTankClient.readTank09(); int i = number.intValue(); int i1 = ConvertUtils.convertToInt2(i); int qty = ConvertUtils.convertToQty2(i1); int remainder = ConvertUtils.convertToRemainder2(i1); if (remainder >= 100) { qty = qty + 1; } List bigDecimals = baseLocationInfoSubService.checkInventory(sku); for (BigDecimal bigDecimal : bigDecimals) { b = b.add(bigDecimal); } if (qty <= b.intValue()) { WmsDocOrderHeader wmsDocOrderHeader = new WmsDocOrderHeader(); wmsDocOrderHeader.setSoReference3(null); List wmsDocOrderHeaders = wmsDocOrderHeaderMapper.selectWmsDocOrderHeaderList1(wmsDocOrderHeader); if (wmsDocOrderHeaders != null && wmsDocOrderHeaders.size() > 0) { String orderNo = wmsDocOrderHeaders.get(0).getOrderNo(); boolean[] booleans1 = stirringTankClient.readTank14(); if (booleans1[13] = true) { AjaxResult ajaxResult = wmsDocOrderSubService.initOrderDetails(orderNo); if (ajaxResult.isSuccess()) { stirringTankClient.writeTank03_2(); } return true; } return false; } stirringTankClient.writeTank02_2(); stirringTankClient.writeTank01_2f(); outbound_3(qty); return true; } else { stirringTankClient.writeTank01_2(); stirringTankClient.writeTank02_2f(); return false; } } return false; } /** * 生成丁铵黑药出库单 * * @return */ public AjaxResult outbound_3(int qty) { String sku = "C4H9O2PSSNH4"; Number number = stirringTankClient.readTank09(); BigDecimal qty1 = new BigDecimal(qty); String order = wmsDocOrderSubService.generateAnOutboundOrder(sku, qty1); return AjaxResult.success(); } /** * 对比六偏磷酸钠库存 * * @return */ public boolean matchInventory_4() { String sku = "(NaPO3)6"; BigDecimal b = new BigDecimal(0); //读注入标志位 boolean[] booleans = stirringTankClient.readTank13(); if (booleans[12] = true) { //读到的六偏磷酸钠所需剂量 Number number = stirringTankClient.readTank10(); int i = number.intValue(); int i1 = ConvertUtils.convertToInt3(i); int qty = ConvertUtils.convertToQty3(i1); int remainder = ConvertUtils.convertToRemainder3(i1); if (remainder >= 25) { qty = qty + 1; } List bigDecimals = baseLocationInfoSubService.checkInventory(sku); for (BigDecimal bigDecimal : bigDecimals) { b = b.add(bigDecimal); } if (qty <= b.intValue()) { WmsDocOrderHeader wmsDocOrderHeader = new WmsDocOrderHeader(); wmsDocOrderHeader.setSoReference3("3"); List wmsDocOrderHeaders = wmsDocOrderHeaderMapper.selectWmsDocOrderHeaderList1(wmsDocOrderHeader); if (wmsDocOrderHeaders != null && wmsDocOrderHeaders.size() > 0) { String orderNo = wmsDocOrderHeaders.get(0).getOrderNo(); boolean[] booleans1 = stirringTankClient.readTank14(); if (booleans1[12] = true) { AjaxResult ajaxResult = wmsDocOrderSubService.initOrderDetails(orderNo); if (ajaxResult.isSuccess()) { stirringTankClient.writeTank03_3(); } return true; } return false; } stirringTankClient.writeTank02_3(); stirringTankClient.writeTank01_3f(); outbound_4(qty); return true; } else { stirringTankClient.writeTank01_3(); stirringTankClient.writeTank02_3f(); return false; } } return false; } /** * 生成六偏磷酸钠出库单 * * @return */ public AjaxResult outbound_4(int qty) { String sku = "(NaPO3)6"; Number number = stirringTankClient.readTank10(); BigDecimal qty1 = new BigDecimal(qty); String order = wmsDocOrderSubService.generateAnOutboundOrder(sku, qty1); return AjaxResult.success(); } /** * 对比硫酸铵库存 * * @return */ public boolean matchInventory_5() { String sku = "(NH4)2SO4"; BigDecimal b = new BigDecimal(0); //读注入标志位 boolean[] booleans = stirringTankClient.readTank13(); if (booleans[11] = true) { //读到的硫酸铵所需剂量 Number number = stirringTankClient.readTank11(); int i = number.intValue(); int i1 = ConvertUtils.convertToInt4(i); int qty = ConvertUtils.convertToQty4(i1); int remainder = ConvertUtils.convertToRemainder4(i1); if (remainder >= 25) { qty = qty + 1; } List bigDecimals = baseLocationInfoSubService.checkInventory(sku); for (BigDecimal bigDecimal : bigDecimals) { b = b.add(bigDecimal); } if (qty <= b.intValue()) { WmsDocOrderHeader wmsDocOrderHeader = new WmsDocOrderHeader(); wmsDocOrderHeader.setSoReference3("4"); List wmsDocOrderHeaders = wmsDocOrderHeaderMapper.selectWmsDocOrderHeaderList1(wmsDocOrderHeader); if (wmsDocOrderHeaders != null && wmsDocOrderHeaders.size() > 0) { String orderNo = wmsDocOrderHeaders.get(0).getOrderNo(); boolean[] booleans1 = stirringTankClient.readTank14(); if (booleans1[11] = true) { AjaxResult ajaxResult = wmsDocOrderSubService.initOrderDetails(orderNo); if (ajaxResult.isSuccess()) { stirringTankClient.writeTank03_4(); return true; } } return false; } stirringTankClient.writeTank02_4(); stirringTankClient.writeTank01_4f(); outbound_5(qty); return true; } else { stirringTankClient.writeTank01_4(); stirringTankClient.writeTank02_4f(); return false; } } return false; } /** * 生成硫酸铵出库单 * * @return */ public AjaxResult outbound_5(int qty) { String sku = "(NH4)2SO4"; Number number = stirringTankClient.readTank11(); BigDecimal qty1 = new BigDecimal(qty); String order = wmsDocOrderSubService.generateAnOutboundOrder(sku, qty1); return AjaxResult.success(); } /** * 对比乙黄药库存 * * @return */ public boolean matchInventory_6() { String sku = "CH3CH2OCS2Na"; BigDecimal b = new BigDecimal(0); //读注入标志位 boolean[] booleans = stirringTankClient.readTank13(); if (booleans[10] = true) { //读到的乙黄药所需剂量 Number number = stirringTankClient.readTank12(); int i = number.intValue(); int i1 = ConvertUtils.convertToInt5(i); int qty = ConvertUtils.convertToQty5(i1); int remainder = ConvertUtils.convertToRemainder5(i1); if (remainder >= 20) { qty = qty + 1; } List bigDecimals = baseLocationInfoSubService.checkInventory(sku); for (BigDecimal bigDecimal : bigDecimals) { b = b.add(bigDecimal); } if (qty <= b.intValue()) { WmsDocOrderHeader wmsDocOrderHeader = new WmsDocOrderHeader(); wmsDocOrderHeader.setSoReference3("5"); List wmsDocOrderHeaders = wmsDocOrderHeaderMapper.selectWmsDocOrderHeaderList1(wmsDocOrderHeader); if (wmsDocOrderHeaders != null && wmsDocOrderHeaders.size() > 0) { String orderNo = wmsDocOrderHeaders.get(0).getOrderNo(); boolean[] booleans1 = stirringTankClient.readTank14(); if (booleans1[10] = true) { AjaxResult ajaxResult = wmsDocOrderSubService.initOrderDetails(orderNo); if (ajaxResult.isSuccess()) { stirringTankClient.writeTank03_5(); return true; } } return false; } stirringTankClient.writeTank02_5(); stirringTankClient.writeTank01_5f(); outbound_6(qty); return true; } else { stirringTankClient.writeTank01_5(); stirringTankClient.writeTank02_5f(); return false; } } return false; } /** * 生成乙黄药出库单 * * @return */ public AjaxResult outbound_6(int qty) { String sku = "CH3CH2OCS2Na"; Number number = stirringTankClient.readTank12(); BigDecimal qty1 = new BigDecimal(qty); String order = wmsDocOrderSubService.generateAnOutboundOrder(sku, qty1); return AjaxResult.success(); } /** * 清除所有写的数据 * * @return */ public AjaxResult clear() { boolean[] booleans = stirringTankClient.writeTank03_Read(); if (booleans[15] = true) { stirringTankClient.writeTank01f(); stirringTankClient.writeTank02f(); stirringTankClient.writeTank03f(); stirringTankClient.writeTank04f(); stirringTankClient.writeTank05f(); } if (booleans[14] = true) { stirringTankClient.writeTank01_1f(); stirringTankClient.writeTank02_1f(); stirringTankClient.writeTank03_1f(); stirringTankClient.writeTank04_1f(); stirringTankClient.writeTank05_1f(); } if (booleans[13] = true) { stirringTankClient.writeTank01_2f(); stirringTankClient.writeTank02_2f(); stirringTankClient.writeTank03_2f(); stirringTankClient.writeTank04_2f(); stirringTankClient.writeTank05_2f(); } if (booleans[12] = true) { stirringTankClient.writeTank01_3f(); stirringTankClient.writeTank02_3f(); stirringTankClient.writeTank03_3f(); stirringTankClient.writeTank04_3f(); stirringTankClient.writeTank05_3f(); } if (booleans[11] = true) { stirringTankClient.writeTank01_4f(); stirringTankClient.writeTank02_4f(); stirringTankClient.writeTank03_4f(); stirringTankClient.writeTank04_4f(); stirringTankClient.writeTank05_4f(); } if (booleans[10] = true) { stirringTankClient.writeTank01_5f(); stirringTankClient.writeTank02_5f(); stirringTankClient.writeTank03_5f(); stirringTankClient.writeTank04_5f(); stirringTankClient.writeTank05_5f(); } return AjaxResult.success(); } /** * 清除未完成和未下发成功的任务 * @return */ public void delTask() { List wcsTaskList = wcsTaskService.selectWcsByState(Constant.WAREHOUSE_ID); if (wcsTaskList == null || wcsTaskList.size() < 1) { log.info("当前暂无需要处理的任务!"+ new Date());} for (WcsTask wcsTask : wcsTaskList) { wcsTaskService.callBack(wcsTask.getTaskNo(), 7, null); } } }