离线客户条码打印

master
臧学普 6 months ago
parent 34f8cb319f
commit fe3c342dee

@ -0,0 +1,8 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi.offlineprint;
import java.util.Map;
public interface IMesOfflinePrintService {
Map<String,Object> getCustSnOfflineInfo(String custSn,String templateCode,String organizeCode);
}

@ -0,0 +1,36 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.controller.busi.offlinesn;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.offlineprint.MesOfflinePrintServiceImpl;
import cn.estsh.i3plus.ext.mes.pcn.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.impp.framework.boot.util.ResultBean;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@Api(tags = "离线条码打印")
@RequestMapping(MesCommonConstant.MES_YANFEN + "/offline/print")
@Slf4j
public class MesWuhanOfflinePrint {
@Autowired
private MesOfflinePrintServiceImpl mesOfflinePrintService;
@GetMapping("/cust-sn/{custSn}/{templateCode}/{organizeCode}")
public ResultBean custSn(@PathVariable("custSn") String custSn,@PathVariable("templateCode") String templateCode,@PathVariable("organizeCode") String organizeCode) {
Map<String, Object> custSnOfflineInfo = null;
try {
custSnOfflineInfo = mesOfflinePrintService.getCustSnOfflineInfo(custSn, templateCode, organizeCode);
} catch (Exception e) {
ResultBean.fail().setErrorMsg(e.getMessage());
}
return ResultBean.success("查询成功").setResultMap(custSnOfflineInfo);
}
}

@ -0,0 +1,99 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.offlineprint;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.offlineprint.IMesOfflinePrintService;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.BarCodeUtils;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.MesLabelTemplate;
import cn.estsh.i3plus.pojo.mes.bean.MesLabelTemplateParam;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkOrder;
import cn.estsh.i3plus.pojo.mes.repository.MesLabelTemplateParamRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesLabelTemplateRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesWorkOrderRepository;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream;
import java.util.*;
@Service
@Slf4j
public class MesOfflinePrintServiceImpl implements IMesOfflinePrintService {
@Autowired
private MesWorkOrderRepository workOrderRepository;
@Autowired
private MesLabelTemplateRepository labelTemplateRepository;
@Autowired
private MesLabelTemplateParamRepository labelTemplateParamRepository;
@Override
public Map<String, Object> getCustSnOfflineInfo(String custSn,String templateCode,String organizeCode) {
List<Map<String, Object>> printDate = new ArrayList<>();
Map<String, Object> data = new HashMap<>();
if (custSn.length() != MesPcnExtConstWords.CUSTOMER_SN_LENGTH_GM) {
String a = custSn.substring(0, 3);
String b = custSn.substring(3, 5);
String c = custSn.substring(5, 20);
String d = custSn.substring(20, 29);
String e = custSn.substring(29, 41);
String f = custSn.substring(41, 58);
custSn= a + (char)30 + b + (char)29 + c + (char)29 + d + (char)29 + e + (char)29 + f + (char)30 + (char)04;
}
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(custSn,"custSn",ddlPackBean);
List<MesWorkOrder> workOrderList = workOrderRepository.findByHqlWhere(ddlPackBean);
if (workOrderList != null && !workOrderList.isEmpty()) {
MesWorkOrder mesWorkOrder = workOrderList.get(0);
String vpps = custSn.substring(8, 23);
String custPartNo = mesWorkOrder.getCustPartNo();
String duns = custSn.substring(36, 46);
String custSnAfterContent = custSn.substring(47, custSn.length() - 2);
data.put("custSn", custSn);
data.put("custPartNoPrefix", custPartNo.substring(0, custPartNo.length() - 4));
data.put("custPartNoAfterFour", custPartNo.substring(custPartNo.length() - 4).toUpperCase());
data.put("custSnVPPS", vpps);
data.put("custSnDUNS", duns);
data.put("custSnAfterContent", custSnAfterContent);
}
try {
ByteArrayOutputStream dataMatrixCode = BarCodeUtils.createDataMatrixCode(custSn);
data.put("custSnDataMatrix", Base64.getEncoder().encodeToString(dataMatrixCode.toByteArray()));
printDate.add(data);
} catch (Exception e) {
throw new ImppBusiException().setErrorDetail("生成条码出错!");
}
MesLabelTemplate mesLabelTemplate = getMesLabelTemplate(templateCode, organizeCode);
Map<String, Object> templateMap = new HashMap<>();
templateMap.put("labelTemplate", mesLabelTemplate);
templateMap.put("templateData", printDate);
return templateMap;
}
private MesLabelTemplate getMesLabelTemplate(String templateCode,String organizeCode) {
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(templateCode,"templateCode",ddlPackBean);
List<MesLabelTemplate> mesLabelTemplates = labelTemplateRepository.findByHqlWhere(ddlPackBean);
if (mesLabelTemplates == null ||mesLabelTemplates.isEmpty()){
log.error(String.format("标签模板代码【%s】在标签模板表不存在", templateCode));
throw ImppExceptionBuilder.newInstance().setErrorDetail(String.format("标签模板代码【%s】在标签模板表不存在", templateCode)).build();
}
DdlPackBean templateParamPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(templateCode,"templateCode",templateParamPackBean);
List<MesLabelTemplateParam> mesLabelTemplateParams = labelTemplateParamRepository.findByHqlWhere(templateParamPackBean);
if (mesLabelTemplateParams == null || mesLabelTemplateParams.isEmpty()){
log.error(String.format("标签模板代码【%s】在标签模板明细表不存在", templateCode));
throw ImppExceptionBuilder.newInstance().setErrorDetail(String.format("标签模板代码【%s】在标签模板明细表不存在", templateCode)).build();
}
MesLabelTemplate mesLabelTemplate = mesLabelTemplates.get(0);
mesLabelTemplate.setLabelTemplateParamList(mesLabelTemplateParams);
return mesLabelTemplate;
}
}
Loading…
Cancel
Save