Merge remote-tracking branch 'origin/dev' into dev

dev
xiangwei.zhang 4 months ago
commit efc977e0b9

@ -0,0 +1,23 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi.ford;
import cn.estsh.i3plus.pojo.mes.bean.ford.MesFordFetchParameter;
import cn.estsh.i3plus.pojo.mes.bean.ford.MesFordJsaSortInfoWithFetchWeb;
import java.util.List;
public interface IFordFetchWebService {
void insertParams(MesFordFetchParameter parameter);
void updateParams(MesFordFetchParameter parameter);
void deleteParams(Long id,String UserName);
MesFordFetchParameter queryParams(Long id);
List<MesFordFetchParameter> queryParams(String organizeCode);
List<MesFordJsaSortInfoWithFetchWeb> doFetchData(Long id, String organizeCode);
}

@ -14,6 +14,10 @@
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
</dependency>
<!-- CXF依赖 -->
<dependency>
<groupId>org.apache.cxf</groupId>

@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Iterator;
import java.util.List;
/**
@ -41,11 +42,18 @@ public class MesPartController {
ListPager<MesPart> mesPartListPager = mesPartService.queryMesPart(mesPart, pager);
List<MesPart> partList = mesPartListPager.getObjectList();
for (MesPart part : partList) {
MesPartSap partSap = mesPartService.getMesPartSapByPartNo(part.getPartNo(), part.getOrganizeCode());
if (partSap != null) {
part.setUnit(partSap.getUnit());
Iterator<MesPart> iterator = partList.iterator();
while (iterator.hasNext()) {
MesPart part = iterator.next();
try {
MesPartSap partSap = mesPartService.getMesPartSapByPartNo(part.getPartNo(), part.getOrganizeCode());
if (partSap != null) {
part.setUnit(partSap.getUnit());
}
} catch (ImppBusiException e) {
iterator.remove();
}
}
mesPartListPager.setObjectList(partList);
return ResultBean.success("查询成功").setListPager(mesPartListPager);

@ -0,0 +1,97 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.controller.busi.ford;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ford.IFordFetchWebService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.pojo.mes.bean.ford.MesFordFetchParameter;
import cn.estsh.i3plus.pojo.mes.bean.ford.MesFordJsaSortInfoWithFetchWeb;
import cn.estsh.impp.framework.boot.util.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
@Api(tags = "福特web抓单")
@RequestMapping(MesCommonConstant.MES_YANFEN + "/fetch-web")
@Slf4j
public class MesFordFetchWebController {
@Autowired
private IFordFetchWebService fordFetchWebService;
@PostMapping(value = "/param/save")
@ApiOperation(value = "保存抓单参数")
public ResultBean saveParams(@RequestBody MesFordFetchParameter params) {
try {
fordFetchWebService.insertParams(params);
} catch (Exception e) {
return ResultBean.fail(e.getMessage());
}
return ResultBean.success("保存成功!");
}
@PostMapping(value = "/param/update")
@ApiOperation(value = "更新抓单参数")
public ResultBean updateParams(@RequestBody MesFordFetchParameter params) {
try {
fordFetchWebService.updateParams(params);
} catch (Exception e) {
return ResultBean.fail(e.getMessage());
}
return ResultBean.success("更新成功!");
}
@GetMapping(value = "/param/del/{id}/{userName}")
@ApiOperation(value = "删除抓单参数")
public ResultBean updateParams(@PathVariable Long id, @PathVariable String userName) {
try {
fordFetchWebService.deleteParams(id, userName);
} catch (Exception e) {
return ResultBean.fail(e.getMessage());
}
return ResultBean.success("删除成功!");
}
@GetMapping(value = "/param/query/{id}")
@ApiOperation(value = "查询抓单参数")
public ResultBean queryParams(@PathVariable Long id) {
MesFordFetchParameter parameter;
try {
parameter = fordFetchWebService.queryParams(id);
} catch (Exception e) {
return ResultBean.fail(e.getMessage());
}
return ResultBean.success("查询成功!").setResultObject(parameter);
}
@GetMapping(value = "/param/query/list/{organizeCode}")
@ApiOperation(value = "查询抓单参数")
public ResultBean queryParamList(@PathVariable String organizeCode) {
List<MesFordFetchParameter> mesFordFetchParameters;
try {
mesFordFetchParameters = fordFetchWebService.queryParams(organizeCode);
} catch (Exception e) {
return ResultBean.fail(e.getMessage());
}
return ResultBean.success("查询成功!").setResultList(mesFordFetchParameters);
}
@GetMapping(value = "/param/data/{id}/{organizeCode}")
@ApiOperation(value = "定时抓单")
public ResultBean queryData(@PathVariable Long id,@PathVariable String organizeCode) {
List<MesFordJsaSortInfoWithFetchWeb> mesFordJsaSortInfoWithFetchWebs;
try {
mesFordJsaSortInfoWithFetchWebs = fordFetchWebService.doFetchData(id, organizeCode);
} catch (Exception e) {
return ResultBean.fail(e.getMessage());
}
return ResultBean.success("查询成功").setResultList(mesFordJsaSortInfoWithFetchWebs);
}
}

@ -15,5 +15,5 @@ import java.util.List;
public interface IMesProductionRecordDao {
@ApiOperation("查询汇报的加工记录")
List<MesProductionRecord> findMesProductionRecordNoReport(String organizeCode, Integer workOrderType, Integer pageSize, List<String> workCenterList);
List<MesProductionRecord> findMesProductionRecordNoReport(String organizeCode, Integer workOrderType, Integer pageSize, List<String> workCenterList, boolean isHasOrder);
}

@ -32,7 +32,7 @@ public class MesProductionRecordImpl implements IMesProductionRecordDao {
private EntityManager entityManager;
@Override
public List<MesProductionRecord> findMesProductionRecordNoReport(String organizeCode, Integer workOrderType, Integer pageSize, List<String> workCenterList) {
public List<MesProductionRecord> findMesProductionRecordNoReport(String organizeCode, Integer workOrderType, Integer pageSize, List<String> workCenterList, boolean isHasOrder) {
StringBuilder hql = new StringBuilder();
hql.append(" select record from MesProductionRecord record left join MesWorkCenter center on record.workCenterCode = center.workCenterCode where 1=1");
hql.append(" and record.organizeCode = :organizeCode and record.isValid = :isValid and record.isDeleted = :isDeleted ");
@ -44,6 +44,11 @@ public class MesProductionRecordImpl implements IMesProductionRecordDao {
if(MesExtEnumUtil.WORK_CENTER_TYPE.SORT.getValue() == workOrderType){
hql.append(" order by record.reportStatus asc,record.modifyDatetime asc ");
}else{
if (isHasOrder) {
hql.append(" and record.workOrderNo !='' and record.workOrderNo is not null ");
} else {
hql.append(" and (record.workOrderNo = '' or record.workOrderNo is null) ");
}
hql.append(" order by record.modifyDatetime asc ");
}
Query hqlQuery = entityManager.createQuery(hql.toString(), MesProductionRecord.class);

@ -28,13 +28,16 @@ import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel;
import cn.estsh.i3plus.pojo.mes.repository.*;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.util.ImppRedis;
import cn.estsh.impp.framework.boot.util.ResultBean;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -127,6 +130,9 @@ public class MesNcProcessingService implements IMesNcProcessingService {
@Autowired
private IMesMoveRuleRepository mesMoveRuleRepository;
@Resource(name = "redisMesPcn")
private ImppRedis redisMesPcn;
@Override
public ListPager<MesPartInspection> queryPartInspectionByPager(MesPartInspection partInspection, Pager pager) {
@ -200,18 +206,32 @@ public class MesNcProcessingService implements IMesNcProcessingService {
if(!Objects.isNull(model.getPart())){
model.setPart(mesPartService.getMesPartSapByPartNo(model.getPart().getPartNo(), org));
}
if (model.getPartInspection().getSourceType() == MesExtEnumUtil.PART_INSPECTION_SOURCE_TYPE.SINGLE.getValue()) {
Integer type = model.getType();
MesDefectType person = StringUtil.isEmpty(model.getPerson())?new MesDefectType():model.getPerson();
//保存数据
saveDate(model, model.getPart(), type, person, org,model.getInventoryLocationCode(),isOrder);
} else {
final String redisKey = MesPcnExtConstWords.SAP_TRANS_JOB_LOCK_TAG + model.getPartInspection().getId();
RLock rLock = (RLock) redisMesPcn.getLock(redisKey);
try {
if (model.getPartInspection().getSourceType() == MesExtEnumUtil.PART_INSPECTION_SOURCE_TYPE.SINGLE.getValue()) {
Integer type = model.getType();
MesDefectType person = StringUtil.isEmpty(model.getPerson())?new MesDefectType():model.getPerson();
//使用tryLock拿不到锁直接返回
//rlock的leaseTime为-1会每隔WatchdogTimeout秒去续约
if (!rLock.tryLock()){
throw new ImppBusiException(String.format("【%s】此条码正在处理中不能并发执行", model.getSn()));
}
Integer type = model.getType();
MesDefectType person = StringUtil.isEmpty(model.getPerson())?new MesDefectType():model.getPerson();
//保存数据
saveDate(model, model.getPart(), type, person, org,model.getInventoryLocationCode(), isOrder);
//保存数据
saveDate(model, model.getPart(), type, person, org,model.getInventoryLocationCode(),isOrder);
} else {
Integer type = model.getType();
MesDefectType person = StringUtil.isEmpty(model.getPerson())?new MesDefectType():model.getPerson();
//保存数据
saveDate(model, model.getPart(), type, person, org,model.getInventoryLocationCode(), isOrder);
}
} finally {
if (rLock.isHeldByCurrentThread()) {
rLock.unlock();
}
}
}
@ -350,6 +370,10 @@ public class MesNcProcessingService implements IMesNcProcessingService {
String workCenterCode = null == model.getPartInspection() ? null : model.getPartInspection().getWorkCenterCode();
assert model.getPartInspection() != null;
model.getPartInspection().setQmsSync(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
MesPartInspection existedInspection = partInspectionRepository.getById(model.getPartInspection().getId());
if (existedInspection != null && !Objects.equals(existedInspection.getNcStatus(), MesExtEnumUtil.PART_INSPECTION_NC_STATUS.CREATE.getValue())) {
throw new ImppBusiException(String.format("零件【%s】已进行过NC处理请勿重复操作", part.getPartNo()));
}
MesProduceSn sn = getProduceSn(model.getSn(), org);
//武汉 会输入客户条码 todo 更新工单对应qcStatus
boolean isWorkOrderQcStatus=false;

@ -552,8 +552,7 @@ public class MesWorkOrderService implements IMesWorkOrderService {
MesWorkOrder oldMesWorkOrder = getBestWorkOrder(productionRecord, oldMesWorkOrderList, mesWorkCenter);
if (oldMesWorkOrder == null) {
LOGGER.error(String.format("未找到匹配的加工单, 条码=%s", productionRecord.getCustSn()));
return;
//throw new ImppBusiException(String.format("未找到匹配的加工单"));
throw new ImppBusiException(String.format("未找到匹配的加工单"));
}
//获取生产版本
@ -1244,14 +1243,17 @@ public class MesWorkOrderService implements IMesWorkOrderService {
@Override
public void doMesWorkOrderNoSortReport(String organizeCode, Integer pageSize, String userName) {
String workCenterCodes = configService.getCfgValue(organizeCode, "MES_PCN_REPORT_CENTER");
//查询所有非排序工单
List<MesProductionRecord> recordNoReportList = mesProductionRecordDao.findMesProductionRecordNoReport(organizeCode, MesExtEnumUtil.WORK_CENTER_TYPE.NOSORT.getValue(), pageSize, !StringUtils.isEmpty(workCenterCodes) ? Arrays.asList(workCenterCodes.split(",")) : null);
if (CollectionUtils.isEmpty(recordNoReportList)) {
LOGGER.error("非排序加工单加工记录中没有数据,无需处理");
return;
//查询非排序工单 有工单
List<MesProductionRecord> recordNoReportHasOrderNoList = mesProductionRecordDao.findMesProductionRecordNoReport(organizeCode, MesExtEnumUtil.WORK_CENTER_TYPE.NOSORT.getValue(), pageSize, !StringUtils.isEmpty(workCenterCodes) ? Arrays.asList(workCenterCodes.split(",")) : null, true);
if (CollectionUtils.isEmpty(recordNoReportHasOrderNoList)) {
LOGGER.error("非排序有加工单加工记录中没有数据,无需处理");
}
List<MesProductionRecord> recordNoReportNotHasOrderNoList = recordNoReportList.stream().filter(item -> StringUtils.isEmpty(item.getWorkOrderNo())).collect(Collectors.toList());
List<MesProductionRecord> recordNoReportHasOrderNoList = recordNoReportList.stream().filter(item -> !StringUtils.isEmpty(item.getWorkOrderNo())).collect(Collectors.toList());
//查询非排序工单 有工单
List<MesProductionRecord> recordNoReportNotHasOrderNoList = mesProductionRecordDao.findMesProductionRecordNoReport(organizeCode, MesExtEnumUtil.WORK_CENTER_TYPE.NOSORT.getValue(), pageSize, !StringUtils.isEmpty(workCenterCodes) ? Arrays.asList(workCenterCodes.split(",")) : null, false);
if (CollectionUtils.isEmpty(recordNoReportNotHasOrderNoList)) {
LOGGER.error("非排序无加工单加工记录中没有数据,无需处理");
}
//处理无工单加工记录
if(!CollectionUtils.isEmpty(recordNoReportNotHasOrderNoList)){
for (MesProductionRecord mesProductionRecord : recordNoReportNotHasOrderNoList) {
@ -1475,7 +1477,7 @@ public class MesWorkOrderService implements IMesWorkOrderService {
}
public MesWorkOrderSortReportModel initMesWorkOrderSortReportModel(String organizeCode, Integer pageSize, String userName) {
MesWorkOrderSortReportModel model = new MesWorkOrderSortReportModel(organizeCode, userName, mesProductionRecordDao.findMesProductionRecordNoReport(organizeCode, MesExtEnumUtil.WORK_CENTER_TYPE.SORT.getValue(), pageSize,null));
MesWorkOrderSortReportModel model = new MesWorkOrderSortReportModel(organizeCode, userName, mesProductionRecordDao.findMesProductionRecordNoReport(organizeCode, MesExtEnumUtil.WORK_CENTER_TYPE.SORT.getValue(), pageSize,null,true));
model.setMesWorkOrderList(workOrderExtService.getWorkOrderList(organizeCode, model.getWorkOrderList()));
model.setMesMoveRuleList(mesMoveRuleService.findMesMoveRuleByPartProdGroupCode(model.getPartProdGroupCodeList(), organizeCode,MesExtEnumUtil.MOVE_RULE_GROUP_TYPE.MOVE_RULE_GROUP_TYPE_20.getValue()));
model.setMesWorkOrderPartList(findMesWorkOrderPartByOrderNo(organizeCode, model.getWorkOrderList()));

@ -0,0 +1,140 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.ford;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ford.IFordFetchWebService;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.ford.MesFordFetchParameter;
import cn.estsh.i3plus.pojo.mes.bean.ford.MesFordJsaSortInfoWithFetchWeb;
import cn.estsh.i3plus.pojo.mes.repository.ford.MesFordFetchParameterRepository;
import cn.estsh.i3plus.pojo.mes.repository.ford.MesFordJsaSortInfoWithFetchWebRepository;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.net.HttpCookie;
import java.util.*;
@Service
@Slf4j
public class MesFordFetchWebServiceImpl implements IFordFetchWebService {
@Autowired
private MesFordFetchParameterRepository paramRao;
@Autowired
private MesFordJsaSortInfoWithFetchWebRepository fetchWebRao;
@Override
public void insertParams(MesFordFetchParameter parameter) {
ConvertBean.saveOrUpdate(parameter, parameter.getCreateUser());
paramRao.insert(parameter);
}
@Override
public void updateParams(MesFordFetchParameter parameter) {
ConvertBean.saveOrUpdate(parameter, parameter.getCreateUser());
paramRao.update(parameter);
}
@Override
public void deleteParams(Long id,String userName) {
paramRao.deleteWeaklyById(id,userName);
}
@Override
public MesFordFetchParameter queryParams(Long id) {
Optional<MesFordFetchParameter> params = paramRao.findById(id);
return params.orElseGet(MesFordFetchParameter::new);
}
@Override
public List<MesFordFetchParameter> queryParams(String organizeCode) {
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(organizeCode);
return paramRao.findByHqlWhere(ddlPackBean);
}
@Override
public List<MesFordJsaSortInfoWithFetchWeb> doFetchData(Long id, String organizeCode) {
List<MesFordJsaSortInfoWithFetchWeb> infoList = new ArrayList<>();
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getNumEqualPack(id,"id",ddlPackBean);
List<MesFordFetchParameter> list = paramRao.findByHqlWhere(ddlPackBean);
if (list.isEmpty()) {
throw ImppExceptionBuilder.newInstance().setErrorDetail("未查询出当前配置,请检查数据!").build();
}
MesFordFetchParameter parameter = list.get(0);
//尝试登录
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("username", parameter.getUid());
paramMap.put("password", parameter.getPwd());
paramMap.put("t", String.valueOf(System.currentTimeMillis()));
String body = "username="+parameter.getUid()+"&password="+parameter.getPwd()+"&t="+ System.currentTimeMillis();
String loginUrl = parameter.getLoginUrl();
HttpResponse loginResponse = HttpRequest.post(loginUrl).body(body)
.header("Content-Type","application/x-www-form-urlencoded").timeout(60000).execute();
log.info("doFetchData-打印的返回值是:{}",loginResponse.body());
if (loginResponse.getStatus() != 200){
log.info("doFetchData-登录失败,需要重新登录!返回内容为:{}",loginResponse.body());
}
List<HttpCookie> cookies = loginResponse.getCookies();
//拼接请求参数
//time=0.9656002469020775&maxpage=5&trigger=B100VR12&st=2023-05-12%2005:00:00&et=2023-05-12%2023:59:59&catacode=0&itemcode=0
Map<String,Object> map = new HashMap<>();
map.put("maxpage",parameter.getPageSize() != null ? parameter.getPageSize().toString() : "1");
map.put("trigger",parameter.getInfoPointCode());
map.put("st",parameter.getStartDateTime());
map.put("et",parameter.getEndDateTime());
map.put("catacode","0");
map.put("itemcode","0");
HttpResponse response = HttpRequest.get(parameter.getFetchUrl()).cookie(cookies).timeout(60000).form(map).execute();
log.info("doFetchData-查询出来的内容为:{}",response.body());
Document doc = Jsoup.parse(response.body());
Elements trList = doc.select("tr");
for (int i = 1; i < trList.size(); i++) {
Elements tdList = trList.get(i).select("td");
MesFordJsaSortInfoWithFetchWeb webInfo = new MesFordJsaSortInfoWithFetchWeb();
if (tdList.get(0).text().equals("无数据") || StringUtils.isBlank(tdList.get(0).text())){
break;
}
webInfo.setSeq(Long.parseLong(tdList.get(0).text()));
webInfo.setFetchDate(tdList.get(1).text());
webInfo.setFetchTime(tdList.get(2).text());
webInfo.setVinCode(tdList.get(3).text());
webInfo.setPartNo(tdList.get(4).text());
webInfo.setPartName(tdList.get(5).text());
webInfo.setColorCode(tdList.get(6).text());
webInfo.setInfo0008(tdList.get(7).text());
webInfo.setSeqContext(tdList.get(8).text());
webInfo.setRemark(tdList.get(9).text());
webInfo.setInfoPointDesc(tdList.get(10).text());
webInfo.setFetchType(1); //抓取类型
webInfo.setDataStatus(200);
webInfo.setOrganizeCode(organizeCode);
webInfo.setInfoPointCode(parameter.getInfoPointCode());
webInfo.setCustOrganizeCode(parameter.getCustOrganizeCode());
ConvertBean.saveOrUpdate(webInfo,"doFetchData");
//校验是否已经查询过
DdlPackBean webInfoPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getNumEqualPack(webInfo.getSeq(),"seq",webInfoPackBean);
DdlPreparedPack.getStringEqualPack(webInfo.getFetchDate(),"fetchDate",webInfoPackBean);
DdlPreparedPack.getStringEqualPack(webInfo.getFetchTime(),"fetchTime",webInfoPackBean);
int count = fetchWebRao.findByHqlWhereCount(webInfoPackBean);
if (count > 0){
continue;
}
fetchWebRao.insert(webInfo);
infoList.add(webInfo);
}
return infoList;
}
}

@ -0,0 +1,47 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.numberrule;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesCustomerPartService;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.MesPcnException;
import cn.estsh.i3plus.mes.pcn.api.iservice.busi.INumberRulePackAttributeStrategyService;
import cn.estsh.i3plus.pojo.mes.bean.MesCustomerPart;
import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Objects;
/**
* @Description : MES-
* @Reference :
* @Author : jason.niu
* @CreateDate 2025/03/13 16:47
* @Modify:
**/
@Component
public class ChengDuSimpleYearNumberRuleStrategyService implements INumberRulePackAttributeStrategyService {
@Autowired
private IMesCustomerPartService mesCustomerPartService;
@Override
public GenSerialNoModel execute(GenSerialNoModel genSerialNoModel) {
Map<String, Object> dataMap = genSerialNoModel.getDataMap();
MesCustomerPart customerPart = (!CollectionUtils.isEmpty(dataMap) && dataMap.containsKey(MesCustomerPart.class.getSimpleName())) ?
(MesCustomerPart)dataMap.get(MesCustomerPart.class.getSimpleName()) : mesCustomerPartService.getMesCustomerPart(genSerialNoModel.getOrganizeCode(), genSerialNoModel.getPartNo());
if (Objects.isNull(customerPart)) {
MesPcnException.throwMesBusiException("请检查客户零件信息,零件[%s]客户零件关系未维护", genSerialNoModel.getPartNo());
}
genSerialNoModel.setCustPartNo(customerPart.getCustPartNo());
Date date = new Date();
genSerialNoModel.setYear(getYear(date));
return genSerialNoModel;
}
private String getYear(Date date) {
return (new SimpleDateFormat("yy")).format(date);
}
}

@ -0,0 +1,167 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.strategy;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesCustomerPartService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesPartService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesPrintedSnLogService;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.IPrintTemplateStrategyService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesProduceSnPrintDataModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesProduceSnPrintModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.mes.pcn.api.iservice.busi.ISyncFuncService;
import cn.estsh.i3plus.mes.pcn.util.DateUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker;
import cn.estsh.i3plus.pojo.mes.bean.MesCustomerPart;
import cn.estsh.i3plus.pojo.mes.bean.MesNumberRule;
import cn.estsh.i3plus.pojo.mes.bean.MesPart;
import cn.estsh.i3plus.pojo.mes.bean.MesProduceSn;
import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel;
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StepResult;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.*;
/**
* @Description :
* @Reference :
* @Author : Castle
* @CreateDate : 2024/6/17 16:43
* @Modify:
**/
@Component
@Slf4j
public class ChengDuSplitFixCharPrintStrategy implements IPrintTemplateStrategyService {
@Autowired
private ISyncFuncService syncFuncService;
@Autowired
private SnowflakeIdMaker snowflakeIdMaker;
@Autowired
private IMesPartService mesPartService;
@Autowired
private IMesPrintedSnLogService mesPrintedSnLogService;
@Autowired
private IMesCustomerPartService mesCustomerPartService;
@Override
public MesProduceSnPrintModel execute(GenSerialNoModel genSerialNoModel, MesProduceSnPrintModel mesProduceSnPrintModel, MesNumberRule numberRule, StepResult stepResult, StationRequestBean reqBean, Boolean isStep) {
String organizeCode = mesProduceSnPrintModel.getOrganizeCode();
//物料信息
MesPart mesPart = mesPartService.getMesPartByPartNo(mesProduceSnPrintModel.getPartNo(), organizeCode);
MesCustomerPart customerPart = (!Objects.isNull(genSerialNoModel) && !CollectionUtils.isEmpty(genSerialNoModel.getDataMap()) && genSerialNoModel.getDataMap().containsKey(MesCustomerPart.class.getSimpleName())) ? (MesCustomerPart) genSerialNoModel.getDataMap().get(MesCustomerPart.class.getSimpleName()) : mesCustomerPartService.getMesCustomerPart(organizeCode,mesProduceSnPrintModel.getPartNo());
if (!isStep){
if (!Objects.isNull(customerPart)) {
genSerialNoModel.setCustPartNo(customerPart.getCustPartNo());
}
for (int i = 0; i < mesProduceSnPrintModel.getPrintQty(); i++) {
//保存条码信息
MesProduceSn produceSn = generateMesProduceSn(mesPart, syncFuncService.syncSerialNo(genSerialNoModel.partSnParam(mesPart.getPartSnParam()), mesProduceSnPrintModel.getUserName(), organizeCode, 1).getResultList().get(0).toString(), mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty());
//封装打印信息
MesProduceSnPrintDataModel printDataModel = getModel(produceSn, customerPart);
mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().clear();
mesProduceSnPrintModel.getMesProduceSnList().add(produceSn);
Map<String, Object> printTemplateData = new HashMap<>(getPrintContextMap(produceSn, customerPart));
mesProduceSnPrintModel.getPrintContextList().add(printTemplateData);
//保存打印记录
mesProduceSnPrintModel.getMesPrintedSnLogList().add(mesPrintedSnLogService.getMesCustomPrintedSnLog(mesProduceSnPrintModel.getUserName(), organizeCode, printDataModel, printTemplateData));
}
}else{
MesProduceSn mesProduceSn = mesProduceSnPrintModel.getMesProduceSnList().get(0);
//封装打印信息
MesProduceSnPrintDataModel printDataModel = getModel(mesProduceSn, customerPart);
mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().clear();
Map<String, Object> printTemplateData = new HashMap<>(getPrintContextMap(mesProduceSn, customerPart));
List<Map<String, Object>> printDataMapList = new ArrayList<>();
printDataMapList.add(printTemplateData);
mesProduceSnPrintModel.getPrintContextList().add(packResultMap(mesProduceSnPrintModel, printDataMapList));
//保存打印记录
mesProduceSnPrintModel.getMesPrintedSnLogList().add(mesPrintedSnLogService.getMesCustomPrintedSnLog(mesProduceSnPrintModel.getUserName(), organizeCode, printDataModel, printTemplateData));
}
return mesProduceSnPrintModel;
}
private MesProduceSn generateMesProduceSn(MesPart mesPart, String sn, String userName, Double qty) {
MesProduceSn mesProduceSn = new MesProduceSn();
mesProduceSn.setSerialNumber(snowflakeIdMaker.nextId() + "");
mesProduceSn.setProductSn(sn);
mesProduceSn.setCustSn(sn);
mesProduceSn.setPartNo(mesPart.getPartNo());
mesProduceSn.setPartName(mesPart.getPartName());
mesProduceSn.setProcessLabelTemplate(mesPart.getProcessLabelTemplate());
mesProduceSn.setCustLabelTemplate(mesPart.getCustLabelTemplate());
mesProduceSn.setProdLabelTemplate(mesPart.getProductLabelTemplate());
mesProduceSn.setQty(qty);
mesProduceSn.setSnStatus(MesExtEnumUtil.PRODUCE_SN_STATUS.CREATE.getValue());
mesProduceSn.setQcStatus(MesExtEnumUtil.PRODUCE_QC_STATUS.QUALIFIED.getValue());
mesProduceSn.setLotNo(TimeTool.getToday());
mesProduceSn.setPrintCount(MesPcnExtConstWords.ONE);
mesProduceSn.setPrintStatus(MesExtEnumUtil.PRINT_STATUS.PRINTED.getValue());
mesProduceSn.setOrganizeCode(mesPart.getOrganizeCode());
ConvertBean.serviceModelInitialize(mesProduceSn, userName);
return mesProduceSn;
}
private MesProduceSnPrintDataModel getModel(MesProduceSn produceSn, MesCustomerPart customerPart) {
MesProduceSnPrintDataModel mesProduceSnPrintDataModel = new MesProduceSnPrintDataModel();
mesProduceSnPrintDataModel.setPartNo(produceSn.getPartNo());
mesProduceSnPrintDataModel.setPartName(produceSn.getPartName());
if (!Objects.isNull(customerPart)) {
mesProduceSnPrintDataModel.setCustPartNo(customerPart.getCustPartNo());
}
mesProduceSnPrintDataModel.setBarcode(produceSn.getProductSn());
mesProduceSnPrintDataModel.setPrintDate(TimeTool.getNowTime(true));
mesProduceSnPrintDataModel.setUserName(produceSn.getCreateUser());
mesProduceSnPrintDataModel.setProductDate(TimeTool.parseStringFormat(produceSn.getLotNo(), DateUtil.SHORT_FORMAT, "yyyy/MM/dd"));
return mesProduceSnPrintDataModel;
}
private Map<String, Object> getPrintContextMap(MesProduceSn produceSn, MesCustomerPart customerPart) {
Map<String, Object> result = new HashMap<>();
String[] splitSn = produceSn.getProductSn().split("#");
if (splitSn.length < 3) {
return result;
}
result.put(MesPcnExtConstWords.PART_NO, produceSn.getPartNo());
result.put(MesPcnExtConstWords.PART_NAME, produceSn.getPartName());
if (!Objects.isNull(customerPart)) {
result.put(MesPcnExtConstWords.CUST_PART_NO, customerPart.getCustPartNo());
}
if (!StringUtils.isEmpty(splitSn[0])) {
result.put("FIX_PART", splitSn[0].substring(0, 1));
result.put(MesPcnExtConstWords.CUST_PART_NO, splitSn[0].substring(1));
}
if (!StringUtils.isEmpty(splitSn[1])) {
result.put("FIX_DATE", splitSn[1].substring(0, 1));
result.put(MesPcnExtConstWords.PRODUCT_DATE, splitSn[1].substring(1));
}
if (!StringUtils.isEmpty(splitSn[2])) {
result.put("FIX_SUPPLIER", splitSn[2].substring(0, 1));
result.put(MesPcnExtConstWords.SUPPLIER_CODE_L, splitSn[2].substring(1));
}
result.put(MesPcnExtConstWords.PRINT_BAR_CODE, produceSn.getProductSn());
result.put(MesPcnExtConstWords.PRINT_DATE, TimeTool.getNowTime(true));
result.put(MesPcnExtConstWords.USER_NAME, produceSn.getCreateUser());
return result;
}
private Map<String, Object> packResultMap(MesProduceSnPrintModel printModel, List<Map<String, Object>> printTemplateDateList) {
Map<String, Object> resultMap = new HashMap<>();
resultMap.put(MesPcnExtConstWords.LABEL_TEMPLATE, printModel.getMesLabelTemplate());
resultMap.put(MesPcnExtConstWords.TEMPLATE_DATA, printTemplateDateList);
resultMap.put(MesPcnExtConstWords.TEMPLATE_CODE, printModel.getMesLabelTemplate().getTemplateCode());
resultMap.put(MesPcnExtConstWords.PRINTER, printModel.getPrinter());
return resultMap;
}
}

@ -0,0 +1,125 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.strategy;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesCustomerPartService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesPartService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesPrintedSnLogService;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.IPrintTemplateStrategyService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesProduceSnPrintDataModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesProduceSnPrintModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.mes.pcn.api.iservice.busi.ISyncFuncService;
import cn.estsh.i3plus.mes.pcn.util.DateUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker;
import cn.estsh.i3plus.pojo.mes.bean.MesCustomerPart;
import cn.estsh.i3plus.pojo.mes.bean.MesNumberRule;
import cn.estsh.i3plus.pojo.mes.bean.MesPart;
import cn.estsh.i3plus.pojo.mes.bean.MesProduceSn;
import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel;
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StepResult;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Objects;
/**
* @Description :
* @Reference :
* @Author : Castle
* @CreateDate : 2024/6/17 16:43
* @Modify:
**/
@Component
@Slf4j
public class ChengDuSplitPrintStrategy implements IPrintTemplateStrategyService {
@Autowired
private ISyncFuncService syncFuncService;
@Autowired
private SnowflakeIdMaker snowflakeIdMaker;
@Autowired
private IMesPartService mesPartService;
@Autowired
private IMesPrintedSnLogService mesPrintedSnLogService;
@Autowired
private IMesCustomerPartService mesCustomerPartService;
@Override
public MesProduceSnPrintModel execute(GenSerialNoModel genSerialNoModel, MesProduceSnPrintModel mesProduceSnPrintModel, MesNumberRule numberRule, StepResult stepResult, StationRequestBean reqBean, Boolean isStep) {
String organizeCode = mesProduceSnPrintModel.getOrganizeCode();
//物料信息
MesPart mesPart = mesPartService.getMesPartByPartNo(mesProduceSnPrintModel.getPartNo(), organizeCode);
MesCustomerPart customerPart = (!Objects.isNull(genSerialNoModel) && !CollectionUtils.isEmpty(genSerialNoModel.getDataMap()) && genSerialNoModel.getDataMap().containsKey(MesCustomerPart.class.getSimpleName())) ? (MesCustomerPart) genSerialNoModel.getDataMap().get(MesCustomerPart.class.getSimpleName()) : mesCustomerPartService.getMesCustomerPart(organizeCode,mesProduceSnPrintModel.getPartNo());
if (!isStep){
if (!Objects.isNull(customerPart)) {
genSerialNoModel.setCustPartNo(customerPart.getCustPartNo());
}
for (int i = 0; i < mesProduceSnPrintModel.getPrintQty(); i++) {
//保存条码信息
MesProduceSn produceSn = generateMesProduceSn(mesPart, syncFuncService.syncSerialNo(genSerialNoModel.partSnParam(mesPart.getPartSnParam()), mesProduceSnPrintModel.getUserName(), organizeCode, 1).getResultList().get(0).toString(), mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty());
//封装打印信息
MesProduceSnPrintDataModel printDataModel = getModel(produceSn, customerPart);
mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(printDataModel);
mesProduceSnPrintModel.getMesProduceSnList().add(produceSn);
//保存打印记录
mesProduceSnPrintModel.getMesPrintedSnLogList().add(mesPrintedSnLogService.getMesPrintedSnLog(mesProduceSnPrintModel.getUserName(), organizeCode, printDataModel));
}
}else{
MesProduceSn mesProduceSn = mesProduceSnPrintModel.getMesProduceSnList().get(0);
//封装打印信息
MesProduceSnPrintDataModel printDataModel = getModel(mesProduceSn, customerPart);
mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(printDataModel);
//保存打印记录
mesProduceSnPrintModel.getMesPrintedSnLogList().add(mesPrintedSnLogService.getMesPrintedSnLog(mesProduceSnPrintModel.getUserName(), organizeCode, printDataModel));
}
return mesProduceSnPrintModel;
}
private MesProduceSn generateMesProduceSn(MesPart mesPart, String sn, String userName, Double qty) {
MesProduceSn mesProduceSn = new MesProduceSn();
mesProduceSn.setSerialNumber(snowflakeIdMaker.nextId() + "");
mesProduceSn.setProductSn(sn);
mesProduceSn.setCustSn(sn);
mesProduceSn.setPartNo(mesPart.getPartNo());
mesProduceSn.setPartName(mesPart.getPartName());
mesProduceSn.setProcessLabelTemplate(mesPart.getProcessLabelTemplate());
mesProduceSn.setCustLabelTemplate(mesPart.getCustLabelTemplate());
mesProduceSn.setProdLabelTemplate(mesPart.getProductLabelTemplate());
mesProduceSn.setQty(qty);
mesProduceSn.setSnStatus(MesExtEnumUtil.PRODUCE_SN_STATUS.CREATE.getValue());
mesProduceSn.setQcStatus(MesExtEnumUtil.PRODUCE_QC_STATUS.QUALIFIED.getValue());
mesProduceSn.setLotNo(TimeTool.getToday());
mesProduceSn.setPrintCount(MesPcnExtConstWords.ONE);
mesProduceSn.setPrintStatus(MesExtEnumUtil.PRINT_STATUS.PRINTED.getValue());
mesProduceSn.setOrganizeCode(mesPart.getOrganizeCode());
ConvertBean.serviceModelInitialize(mesProduceSn, userName);
return mesProduceSn;
}
private MesProduceSnPrintDataModel getModel(MesProduceSn produceSn, MesCustomerPart customerPart) {
MesProduceSnPrintDataModel mesProduceSnPrintDataModel = new MesProduceSnPrintDataModel();
String[] splitSn = produceSn.getProductSn().split("#");
if (splitSn.length < 3) {
return mesProduceSnPrintDataModel;
}
mesProduceSnPrintDataModel.setPartNo(produceSn.getPartNo());
mesProduceSnPrintDataModel.setPartName(produceSn.getPartName());
mesProduceSnPrintDataModel.setCustPartNo(splitSn[0] + "#");
mesProduceSnPrintDataModel.setProductDate(splitSn[1] + "#");
mesProduceSnPrintDataModel.setSupplierCode(splitSn[2] + "#");
mesProduceSnPrintDataModel.setBarcode(produceSn.getProductSn());
mesProduceSnPrintDataModel.setPrintDate(TimeTool.getNowTime(true));
mesProduceSnPrintDataModel.setUserName(produceSn.getCreateUser());
return mesProduceSnPrintDataModel;
}
}

@ -886,4 +886,5 @@ public class MesPcnExtConstWords {
//螺钉包保存生产版本标记
public static final String SAVE_PRODUCT_VERSION_FLAG = "ZFBT";
public static final String SAP_TRANS_JOB_LOCK_TAG = "MES:JOB:MES_NC_PROCESSING_LOCK_TAG:";
}

@ -41,6 +41,11 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
<!-- CXF依赖 -->
<dependency>
<groupId>org.apache.cxf</groupId>

Loading…
Cancel
Save