diff --git a/newbiest-mm/src/main/java/com/newbiest/mms/print/DefaultPrintStrategy.java b/newbiest-mm/src/main/java/com/newbiest/mms/print/DefaultPrintStrategy.java index 05aee5e61..d18de1821 100644 --- a/newbiest-mm/src/main/java/com/newbiest/mms/print/DefaultPrintStrategy.java +++ b/newbiest-mm/src/main/java/com/newbiest/mms/print/DefaultPrintStrategy.java @@ -31,10 +31,12 @@ * @author guoxunbo * @date 4/6/21 3:07 PM */ -@Component("defaultPrintStrategy") +@Component(DefaultPrintStrategy.DEFAULT_STRATEGY_NAME) @Slf4j public class DefaultPrintStrategy implements IPrintStrategy { + public static final String DEFAULT_STRATEGY_NAME = "defaultPrintStrategy"; + public static final int CONNECTION_TIME_OUT = 10; public static final int READ_TIME_OUT = 30; @@ -99,7 +101,6 @@ public Map buildParameters(PrintContext printContext) { } public void printWithBartender(PrintContext printContext) { - String destination = printContext.getLabelTemplate().getBartenderDestination(printContext.getWorkStation()); Map params = buildParameters(printContext); @@ -108,14 +109,11 @@ public void printWithBartender(PrintContext printContext) { paramStr.add(key + "=" + params.get(key)); } - HttpHeaders headers = new HttpHeaders(); - HttpEntity entity = new HttpEntity(headers); - - + destination = destination + "?" + StringUtils.join(paramStr, "&"); if (log.isDebugEnabled()) { - log.debug("Start to send print data to bartender. The destination is [ " + destination + "] and the parameter is [ " + params + "] "); + log.debug("Start to send print data to bartender. The destination is [ " + destination + "] "); } - destination = destination + "?" + StringUtils.join(paramStr, "&"); + HttpEntity responseEntity = restTemplate.getForEntity(destination, byte[].class); String response = new String(responseEntity.getBody(), StringUtils.getUtf8Charset()); if (log.isDebugEnabled()) { diff --git a/newbiest-mm/src/main/java/com/newbiest/mms/service/impl/MmsServiceImpl.java b/newbiest-mm/src/main/java/com/newbiest/mms/service/impl/MmsServiceImpl.java index e79fc2927..e049fac3b 100644 --- a/newbiest-mm/src/main/java/com/newbiest/mms/service/impl/MmsServiceImpl.java +++ b/newbiest-mm/src/main/java/com/newbiest/mms/service/impl/MmsServiceImpl.java @@ -25,6 +25,7 @@ import com.newbiest.mms.model.*; import com.newbiest.mms.repository.*; import com.newbiest.mms.service.MmsService; +import com.newbiest.mms.service.PrintService; import com.newbiest.mms.state.model.MaterialEvent; import com.newbiest.mms.state.model.MaterialStatus; import com.newbiest.mms.state.model.MaterialStatusCategory; @@ -102,6 +103,9 @@ public class MmsServiceImpl implements MmsService { @Autowired ProductRepository productRepository; + @Autowired + PrintService printService; + /** * 根据名称获取源物料。 * 源物料不区分版本。故此处只会有1个 @@ -222,6 +226,11 @@ public List splitStandardMLot(String parentMaterialLotId, BigDecima subMaterialLots.add(subMaterialLot); currentQty = currentQty.subtract(standardQty); } + // 如果没有分完,则需要重新打标签 + if (currentQty.compareTo(BigDecimal.ZERO) > 0) { + parentMaterialLot = getMLotByMLotId(parentMaterialLotId, true); + printService.printMLot(parentMaterialLot); + } return subMaterialLots; } catch (Exception e) { throw ExceptionManager.handleException(e, log); @@ -258,6 +267,8 @@ public MaterialLot splitMLot(String parentMaterialLotId, MaterialLotAction mater subMaterialLot.setIncomingQty(BigDecimal.ZERO); subMaterialLot.setParentMaterialLot(parentMaterialLot); baseService.saveEntity(subMaterialLot, MaterialLotHistory.TRANS_TYPE_SPLIT_CREATE, materialLotAction); + + printService.printMLot(subMaterialLot); return subMaterialLot; } catch (Exception e) { throw ExceptionManager.handleException(e, log); diff --git a/newbiest-mm/src/main/java/com/newbiest/mms/service/impl/PrintServiceImpl.java b/newbiest-mm/src/main/java/com/newbiest/mms/service/impl/PrintServiceImpl.java index 547887e51..5669c3c55 100644 --- a/newbiest-mm/src/main/java/com/newbiest/mms/service/impl/PrintServiceImpl.java +++ b/newbiest-mm/src/main/java/com/newbiest/mms/service/impl/PrintServiceImpl.java @@ -7,6 +7,7 @@ import com.newbiest.base.exception.ExceptionManager; import com.newbiest.base.threadlocal.ThreadLocalContext; import com.newbiest.base.utils.DateUtils; +import com.newbiest.base.utils.StringUtils; import com.newbiest.mms.exception.MmsException; import com.newbiest.mms.model.LabelTemplate; import com.newbiest.mms.model.LabelTemplateParameter; @@ -22,6 +23,7 @@ import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -37,10 +39,9 @@ @Transactional @BaseJpaFilter @Data +@Async public class PrintServiceImpl implements PrintService { - public static final String PRINT_MATERIAL_LOT = "printMLot"; - @Autowired Map printStrategyMap; @@ -53,7 +54,13 @@ public class PrintServiceImpl implements PrintService { @Autowired LabelTemplateParameterRepository labelTemplateParameterRepository; + /** + * 打标签进行异步构建 + * @param materialLot + * @throws ClientException + */ @Override + @Async public void printMLot(MaterialLot materialLot) throws ClientException { try { String transactionIp = ThreadLocalContext.getTransactionIp(); @@ -79,16 +86,26 @@ public void printMLot(MaterialLot materialLot) throws ClientException { parameterMap.put("specification", materialLot.getMaterialDesc()); printContext.setParameterMap(parameterMap); - IPrintStrategy printStrategy = printStrategyMap.get("PrintMLot"); - if (printStrategy == null) { - printStrategy = printStrategyMap.get("defaultPrintStrategy"); - } -// IPrintStrategy printStrategy = new DefaultPrintStrategy(); - printStrategy.print(printContext); + print(printContext); } catch (Exception e) { throw ExceptionManager.handleException(e, log); } } + public void print(PrintContext printContext) { + print(DefaultPrintStrategy.DEFAULT_STRATEGY_NAME, printContext); + } + + public void print(String strategyName, PrintContext printContext) { + IPrintStrategy printStrategy = printStrategyMap.get(strategyName); + if (printStrategy == null) { + printStrategy = printStrategyMap.get(DefaultPrintStrategy.DEFAULT_STRATEGY_NAME); + } + if (log.isDebugEnabled()) { + log.debug("Use context [" + printContext.toString() + "] to print"); + } + printStrategy.print(printContext); + } + } diff --git a/newbiest-starter/src/main/resources/logback-spring.xml b/newbiest-starter/src/main/resources/logback-spring.xml index 08bd0519a..b821fce1c 100644 --- a/newbiest-starter/src/main/resources/logback-spring.xml +++ b/newbiest-starter/src/main/resources/logback-spring.xml @@ -44,6 +44,34 @@ + + ${log.path}/vanchip/vanchip.log + + ${log.path}/vanchip/vanchip.%d{yyyy-MM-dd}.%i.log.zip + + 500MB + + + + UTF-8 + ${global_pattern} + + + + + ${log.path}/mms/mms.log + + ${log.path}/mms/mms.%d{yyyy-MM-dd}.%i.log.zip + + 500MB + + + + UTF-8 + ${global_pattern} + + + 0 @@ -55,6 +83,14 @@ + + + + + + + +