Skip to content

Commit

Permalink
物料批次分批自动打标签
Browse files Browse the repository at this point in the history
1. 分批之后自动打标签
2. 打印标签相关为异步处理
3. 日志完善
#550 #552
  • Loading branch information
adomguo committed Apr 8, 2021
1 parent 08f1c35 commit b40bea1
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +101,6 @@ public Map<String, Object> buildParameters(PrintContext printContext) {
}

public void printWithBartender(PrintContext printContext) {

String destination = printContext.getLabelTemplate().getBartenderDestination(printContext.getWorkStation());
Map<String, Object> params = buildParameters(printContext);

Expand All @@ -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<byte[]> responseEntity = restTemplate.getForEntity(destination, byte[].class);
String response = new String(responseEntity.getBody(), StringUtils.getUtf8Charset());
if (log.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,6 +103,9 @@ public class MmsServiceImpl implements MmsService {
@Autowired
ProductRepository productRepository;

@Autowired
PrintService printService;

/**
* 根据名称获取源物料。
* 源物料不区分版本。故此处只会有1个
Expand Down Expand Up @@ -222,6 +226,11 @@ public List<MaterialLot> 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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -37,10 +39,9 @@
@Transactional
@BaseJpaFilter
@Data
@Async
public class PrintServiceImpl implements PrintService {

public static final String PRINT_MATERIAL_LOT = "printMLot";

@Autowired
Map<String, IPrintStrategy> printStrategyMap;

Expand All @@ -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();
Expand All @@ -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);
}

}
36 changes: 36 additions & 0 deletions newbiest-starter/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@
</encoder>
</appender>

<appender name="vanchip" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/vanchip/vanchip.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/vanchip/vanchip.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>500MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>${global_pattern}</pattern>
</encoder>
</appender>

<appender name="mms" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/mms/mms.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/mms/mms.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>500MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>${global_pattern}</pattern>
</encoder>
</appender>

<appender name="async_file_log" class="ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold>0</discardingThreshold>
Expand All @@ -55,6 +83,14 @@
<appender-ref ref="file"/>
</appender>

<logger name="com.newbiest.vanchip" level="DEBUG" additivity="false">
<appender-ref ref="vanchip"/>
</logger>

<logger name="com.newbiest.mms" level="DEBUG" additivity="false">
<appender-ref ref="mms"/>
</logger>

<springProfile name="production">
<root level="INFO">
<appender-ref ref="file" />
Expand Down

0 comments on commit b40bea1

Please sign in to comment.