-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
544 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
newbiest-mm/src/main/java/com/newbiest/mms/model/LabelTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
newbiest-mm/src/main/java/com/newbiest/mms/model/LabelTemplateParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
newbiest-mm/src/main/java/com/newbiest/mms/model/WorkStation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
114 changes: 114 additions & 0 deletions
114
newbiest-mm/src/main/java/com/newbiest/mms/print/DefaultPrintStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
newbiest-mm/src/main/java/com/newbiest/mms/print/IPrintStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
newbiest-mm/src/main/java/com/newbiest/mms/print/PrintContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
newbiest-mm/src/main/java/com/newbiest/mms/repository/LabelTemplateParameterRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
newbiest-mm/src/main/java/com/newbiest/mms/repository/LabelTemplateRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
newbiest-mm/src/main/java/com/newbiest/mms/repository/WorkStationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
newbiest-mm/src/main/java/com/newbiest/mms/service/PrintService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.