Skip to content

Commit

Permalink
工作站构建,打印模板构建
Browse files Browse the repository at this point in the history
1. 支持工作站的构建
2. 支持打印模板和参数的传递构建
3. 支持打印bartender和excel打印
4.
#551 #552
  • Loading branch information
adomguo committed Apr 6, 2021
1 parent aa1e61a commit c3c6576
Show file tree
Hide file tree
Showing 19 changed files with 544 additions and 2 deletions.
6 changes: 6 additions & 0 deletions newbiest-mm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>mm</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
</dependencies>

<parent>
<groupId>com.newbiest</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class MmsException {
public static final String MM_PRODUCT_IS_EXIST = "mm.product_is_exist";
public static final String MM_PRODUCT_IS_NOT_EXIST = "mm.product_is_not_exist";

public static final String MM_RECEIVE_QTY_OVER_INCOMING_QTY = "mm_receive_qty_over_incoming_qty";
public static final String MM_RECEIVE_QTY_OVER_INCOMING_QTY = "mm.receive_qty_over_incoming_qty";

public static final String MM_WORK_STATION_IS_NOT_EXIST = "mm.work_station_is_not_exist";
public static final String MM_LBL_TEMPLATE_IS_NOT_EXIST = "mm.lbl_template_is_not_exist";
public static final String MM_LBL_TEMPLATE_TYPE_IS_NOT_ALLOW = "mm.lbl_template_is_not_allow";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.newbiest.mms.model;

import com.newbiest.base.model.NBBase;
import com.newbiest.base.threadlocal.ThreadLocalContext;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;

/**
* @author guoxunbo
* @date 4/6/21 2:22 PM
*/
@Entity
@Table(name="MMS_LBL_TEMPLATE")
@Data
public class LabelTemplate extends NBBase {

public static final String TYPE_BARTENDER = "Bartender";
public static final String TYPE_EXCEL = "Excel";

@Column(name="NAME")
private String name;

@Column(name="DESCRIPTION")
private String description;

@Column(name="TYPE")
private String type;

/**
* 当type是Bartender的时候
* 需要指定其IB的地址。如http://${remote_address}:10099/******
* 当type是excel的时候,则为excel的Template的模板名称
*/
@Column(name="DESTINATION")
private String destination;

@Column(name="PRINT_COUNT")
private Integer printCount = 1;

@Transient
private List<LabelTemplateParameter> labelTemplateParameterList;

public String getBartenderDestination() {
return destination.replace("${remote_address}", ThreadLocalContext.getTransactionIp());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.newbiest.mms.model;

import com.newbiest.base.model.NBBase;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
* @author guoxunbo
* @date 4/6/21 2:22 PM
*/
@Entity
@Table(name="MMS_LBL_TEMPLATE_PARA")
@Data
public class LabelTemplateParameter extends NBBase {

@Column(name="LBL_TEMPLATE_RRN")
private String lblTemplateRrn;

@Column(name="NAME")
private String name;

@Column(name="DEFAULT_VALUE")
private String defaultValue;

}
25 changes: 25 additions & 0 deletions newbiest-mm/src/main/java/com/newbiest/mms/model/WorkStation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.newbiest.mms.model;

import com.newbiest.base.model.NBBase;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
* @author guoxunbo
* @date 4/6/21 2:18 PM
*/
@Entity
@Table(name="MMS_WORK_STATION")
@Data
public class WorkStation extends NBBase {

@Column(name="IP_ADDRESS")
private String ipAddress;

@Column(name = "PRINT_MACHINE_IP_ADDRESS")
private String printMachineIpAddress;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.newbiest.mms.print;

import com.google.common.collect.Maps;
import com.newbiest.base.exception.ClientParameterException;
import com.newbiest.base.utils.CollectionUtils;
import com.newbiest.base.utils.DateUtils;
import com.newbiest.base.utils.PropertyUtils;
import com.newbiest.base.utils.StringUtils;
import com.newbiest.mms.exception.MmsException;
import com.newbiest.mms.model.LabelTemplate;
import com.newbiest.mms.model.LabelTemplateParameter;
import lombok.extern.slf4j.Slf4j;
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.HttpMethod;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static org.apache.http.impl.client.HttpClientBuilder.create;

/**
* @author guoxunbo
* @date 4/6/21 3:07 PM
*/
@Component
@Slf4j
public class DefaultPrintStrategy implements IPrintStrategy {

public static final int CONNECTION_TIME_OUT = 10;

public static final int READ_TIME_OUT = 30;

private RestTemplate restTemplate;

@PostConstruct
public void init() {
CloseableHttpClient client = createHttpClient().build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(client);
requestFactory.setConnectTimeout(CONNECTION_TIME_OUT * 1000);
requestFactory.setReadTimeout(READ_TIME_OUT * 1000);
restTemplate = new RestTemplate(requestFactory);
}

protected HttpClientBuilder createHttpClient() {
return create().useSystemProperties().disableRedirectHandling().disableCookieManagement();
}

@Override
public void print(PrintContext printContext) {
LabelTemplate labelTemplate = printContext.getLabelTemplate();
if (LabelTemplate.TYPE_BARTENDER.equals(labelTemplate.getType())) {
printWithBartender(printContext);
} else if (LabelTemplate.TYPE_EXCEL.equals(labelTemplate.getType())){
//TODO 后续实现
} else {
throw new ClientParameterException(MmsException.MM_LBL_TEMPLATE_TYPE_IS_NOT_ALLOW, labelTemplate.getType());
}
}

public Map<String, Object> buildParameters(PrintContext printContext) {
Map<String, Object> parameterMap = Maps.newHashMap();
List<LabelTemplateParameter> labelTemplateParameters = printContext.getLabelTemplate().getLabelTemplateParameterList();
if (CollectionUtils.isNotEmpty(labelTemplateParameters)) {
for (LabelTemplateParameter parameter : labelTemplateParameters) {
Object value = null;
if (printContext.getParameterMap().containsKey(parameter.getName())) {
value = parameterMap.get(parameter.getName());
} else {
try {
value = PropertyUtils.getProperty(printContext.getBaseObject(), parameter.getName());
if (value != null) {
if (value instanceof Date) {
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.DEFAULT_DATE_PATTERN);
value = sdf.format(value);
}
value = String.valueOf(value);
} else {
value = parameter.getDefaultValue();
}
} catch (Exception e) {
// 此处异常不处理
log.warn(e.getMessage(), e);
}
}
parameterMap.put(parameter.getName(), value);
}
}
parameterMap.put("printCount", printContext.getLabelTemplate().getPrintCount());
return parameterMap;
}

public void printWithBartender(PrintContext printContext) {
String destination = printContext.getLabelTemplate().getBartenderDestination();
Map<String, Object> params = buildParameters(printContext);

HttpHeaders headers = new HttpHeaders();
HttpEntity entity = new HttpEntity(headers);

HttpEntity<byte[]> responseEntity = restTemplate.exchange(destination, HttpMethod.GET, entity, byte[].class, params);
String response = new String(responseEntity.getBody(), StringUtils.getUtf8Charset());
if (log.isDebugEnabled()) {
log.debug(String.format("Get response from bartender. Response is [%s]", response));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.newbiest.mms.print;

/**
* @author guoxunbo
* @date 4/6/21 3:06 PM
*/

public interface IPrintStrategy {

void print(PrintContext printContext);

}

23 changes: 23 additions & 0 deletions newbiest-mm/src/main/java/com/newbiest/mms/print/PrintContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.newbiest.mms.print;

import com.google.common.collect.Maps;
import com.newbiest.mms.model.LabelTemplate;
import lombok.Data;

import java.io.Serializable;
import java.util.Map;

/**
* @author guoxunbo
* @date 4/6/21 3:12 PM
*/
@Data
public class PrintContext implements Serializable {

private Object baseObject;

private Map<String, Object> parameterMap = Maps.newHashMap();

private LabelTemplate labelTemplate;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.newbiest.mms.repository;

import com.newbiest.base.exception.ClientException;
import com.newbiest.base.repository.custom.IRepository;
import com.newbiest.mms.model.LabelTemplateParameter;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface LabelTemplateParameterRepository extends IRepository<LabelTemplateParameter, String> {

List<LabelTemplateParameter> findByLblTemplateRrn(String lblTemplateRrn) throws ClientException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.newbiest.mms.repository;

import com.newbiest.base.repository.custom.IRepository;
import com.newbiest.mms.model.DeliveryOrder;
import com.newbiest.mms.model.LabelTemplate;
import org.springframework.stereotype.Repository;


@Repository
public interface LabelTemplateRepository extends IRepository<LabelTemplate, String> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.newbiest.mms.repository;

import com.newbiest.base.exception.ClientException;
import com.newbiest.base.repository.custom.IRepository;
import com.newbiest.mms.model.LabelTemplate;
import com.newbiest.mms.model.WorkStation;
import org.springframework.stereotype.Repository;


@Repository
public interface WorkStationRepository extends IRepository<WorkStation, String> {

WorkStation findByIpAddress(String ipAddress) throws ClientException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
import io.swagger.annotations.ApiOperation;
Expand All @@ -32,6 +33,9 @@ public class MaterialLotController extends AbstractRestController {
@Autowired
MmsService mmsService;

@Autowired
PrintService printService;

@ApiOperation(value = "对物料批做操作", notes = "接收。消耗等")
@ApiImplicitParam(name="request", value="request", required = true, dataType = "MaterialLotRequest")
@RequestMapping(value = "/materialLotManage", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
Expand All @@ -54,6 +58,9 @@ public MaterialLotResponse execute(@RequestBody MaterialLotRequest request) thro
} else if (MaterialLotRequest.ACTION_CONSUME.equals(actionType)) {
materialLot = validationMaterialLot(materialLot);
materialLot = mmsService.consumeMLot(materialLot, materialLotAction);
} else if (MaterialLotRequest.ACTION_PRINT_LABEL.equals(actionType)) {
materialLot = mmsService.getMLotByMLotId(materialLot.getMaterialLotId());
printService.printMLot(materialLot);
} 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 @@ -14,6 +14,7 @@ public class MaterialLotRequest extends Request {

public static final String ACTION_RECEIVE_2_WAREHOUSE = "Receive2Warehouse";
public static final String ACTION_CONSUME = "Consume";
public static final String ACTION_PRINT_LABEL = "PrintLabel";

private MaterialLotRequestBody body;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.newbiest.mms.service;

import com.newbiest.base.exception.ClientException;
import com.newbiest.mms.model.MaterialLot;

/**
* @author guoxunbo
* @date 4/6/21 3:04 PM
*/
public interface PrintService {
void printMLot(MaterialLot materialLot) throws ClientException;
}
Loading

0 comments on commit c3c6576

Please sign in to comment.