Skip to content

Commit

Permalink
打印相关
Browse files Browse the repository at this point in the history
  • Loading branch information
ZTT820 committed Apr 14, 2021
1 parent 5d051fd commit a0b05cf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.newbiest.mms.print;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.newbiest.base.exception.ClientParameterException;
import com.newbiest.base.utils.CollectionUtils;
import com.newbiest.base.utils.DateUtils;
Expand All @@ -14,7 +13,6 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
Expand Down Expand Up @@ -69,7 +67,8 @@ public void print(PrintContext printContext) {
}

public Map<String, Object> buildParameters(PrintContext printContext) {
Map<String, Object> parameterMap = Maps.newHashMap();
Map<String, Object> parameterMap = printContext.getParameterMap();
log.debug("parameterMap:" + parameterMap);
List<LabelTemplateParameter> labelTemplateParameters = printContext.getLabelTemplate().getLabelTemplateParameterList();
if (CollectionUtils.isNotEmpty(labelTemplateParameters)) {
for (LabelTemplateParameter parameter : labelTemplateParameters) {
Expand All @@ -86,6 +85,7 @@ public Map<String, Object> buildParameters(PrintContext printContext) {
}
if (value != null) {
if (value instanceof Date) {
log.debug("value:" + value);
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.DEFAULT_DATE_PATTERN);
value = sdf.format(value);
}
Expand All @@ -94,6 +94,7 @@ public Map<String, Object> buildParameters(PrintContext printContext) {
value = parameter.getDefaultValue();
}
parameterMap.put(parameter.getName(), value);
log.debug("parameterName:" + parameter.getName() + ".value :" + value);
}
}
parameterMap.put("printCount", printContext.getLabelTemplate().getPrintCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import com.newbiest.base.exception.ClientException;
import com.newbiest.base.exception.ClientParameterException;
import com.newbiest.base.msg.Request;
import com.newbiest.base.rest.AbstractRestController;
import com.newbiest.base.utils.StringUtils;
import com.newbiest.base.threadlocal.ThreadLocalContext;
import com.newbiest.mms.dto.MaterialLotAction;
import com.newbiest.mms.exception.MmsException;
import com.newbiest.mms.model.MaterialLot;
import com.newbiest.mms.model.RawMaterial;
import com.newbiest.mms.service.MmsService;
import com.newbiest.base.msg.Request;
import com.newbiest.mms.service.PrintService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
Expand Down Expand Up @@ -60,7 +60,8 @@ public MaterialLotResponse execute(@RequestBody MaterialLotRequest request) thro
materialLot = mmsService.consumeMLot(materialLot, materialLotAction);
} else if (MaterialLotRequest.ACTION_PRINT_LABEL.equals(actionType)) {
materialLot = mmsService.getMLotByMLotId(materialLot.getMaterialLotId());
printService.printMLot(materialLot);
log.debug("transactionIp" + ThreadLocalContext.getTransactionIp());
printService.printMLot(materialLot, ThreadLocalContext.getTransactionIp());
} else {
throw new ClientException(Request.NON_SUPPORT_ACTION_TYPE + requestBody.getActionType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
* @date 4/6/21 3:04 PM
*/
public interface PrintService {
void printMLot(MaterialLot materialLot) throws ClientException;
void printMLot(MaterialLot materialLot, String workStationIp) throws ClientException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.newbiest.base.exception.ClientException;
import com.newbiest.base.exception.ClientParameterException;
import com.newbiest.base.exception.ExceptionManager;
import com.newbiest.base.threadlocal.ThreadLocalContext;
import com.newbiest.base.utils.DateUtils;
import com.newbiest.mms.exception.MmsException;
import com.newbiest.mms.model.LabelTemplate;
Expand Down Expand Up @@ -60,16 +59,18 @@ public class PrintServiceImpl implements PrintService {
*/
@Override
@Async
public void printMLot(MaterialLot materialLot) throws ClientException {
public void printMLot(MaterialLot materialLot, String workStationIp) throws ClientException {
try {
String transactionIp = ThreadLocalContext.getTransactionIp();
WorkStation workStation = workStationRepository.findByIpAddress(transactionIp);
if (log.isDebugEnabled()) {
log.debug("workStationIp:" + workStationIp);
}
WorkStation workStation = workStationRepository.findByIpAddress(workStationIp);
if (workStation == null) {
throw new ClientParameterException(MmsException.MM_WORK_STATION_IS_NOT_EXIST, transactionIp);
throw new ClientParameterException(MmsException.MM_WORK_STATION_IS_NOT_EXIST, workStationIp);
}
LabelTemplate labelTemplate = labelTemplateRepository.findOneByName("PrintMLot");
if (labelTemplate == null) {
throw new ClientParameterException(MmsException.MM_LBL_TEMPLATE_IS_NOT_EXIST, transactionIp);
throw new ClientParameterException(MmsException.MM_LBL_TEMPLATE_IS_NOT_EXIST);
}
List<LabelTemplateParameter> parameterList = labelTemplateParameterRepository.findByLblTemplateRrn(labelTemplate.getObjectRrn());
labelTemplate.setLabelTemplateParameterList(parameterList);
Expand Down

0 comments on commit a0b05cf

Please sign in to comment.