|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
package com.foreverwin.mesnac.common.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
@ -7,34 +10,41 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.foreverwin.mesnac.common.constant.Constants;
|
|
|
|
|
import com.foreverwin.mesnac.common.constant.CustomFieldConstant;
|
|
|
|
|
import com.foreverwin.mesnac.common.dto.LabelPrintDto;
|
|
|
|
|
import com.foreverwin.mesnac.common.dto.SfcDispatchDto;
|
|
|
|
|
import com.foreverwin.mesnac.common.enums.DispatchStatusEnum;
|
|
|
|
|
import com.foreverwin.mesnac.common.enums.HandleEnum;
|
|
|
|
|
import com.foreverwin.mesnac.common.mapper.ProdReadyTaskMapper;
|
|
|
|
|
import com.foreverwin.mesnac.common.model.PrintLog;
|
|
|
|
|
import com.foreverwin.mesnac.common.model.ProdReadyTask;
|
|
|
|
|
import com.foreverwin.mesnac.common.model.ProdReadyTaskDetail;
|
|
|
|
|
import com.foreverwin.mesnac.common.service.PrintLogService;
|
|
|
|
|
import com.foreverwin.mesnac.common.service.ProdReadyTaskDetailService;
|
|
|
|
|
import com.foreverwin.mesnac.common.service.ProdReadyTaskService;
|
|
|
|
|
import com.foreverwin.mesnac.common.service.SfcDispatchCommonService;
|
|
|
|
|
import com.foreverwin.mesnac.common.util.StringUtil;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.dto.BomComponentDto;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.model.Item;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.model.Sfc;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.model.ShopOrder;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.model.WorkCenter;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.BomComponentService;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.CustomFieldsService;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.ShopOrderService;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.WorkCenterService;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.*;
|
|
|
|
|
import com.foreverwin.modular.core.exception.BaseException;
|
|
|
|
|
import com.foreverwin.modular.core.exception.BusinessException;
|
|
|
|
|
import com.foreverwin.modular.core.util.CommonMethods;
|
|
|
|
|
import com.foreverwin.modular.core.util.FrontPage;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
@ -56,11 +66,15 @@ public class ProdReadyTaskServiceImpl extends ServiceImpl<ProdReadyTaskMapper, P
|
|
|
|
|
public static final String STATUS_FINISH = "FINISH";
|
|
|
|
|
public static final String STATUS_CANCEL = "CANCEL";
|
|
|
|
|
|
|
|
|
|
@Value("${print.server}")
|
|
|
|
|
private String printServer;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ProdReadyTaskMapper prodReadyTaskMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ProdReadyTaskDetailService prodReadyTaskDetailService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SfcDispatchCommonService sfcDispatchCommonService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private BomComponentService bomComponentService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private CustomFieldsService customFieldsService;
|
|
|
|
@ -68,6 +82,12 @@ public class ProdReadyTaskServiceImpl extends ServiceImpl<ProdReadyTaskMapper, P
|
|
|
|
|
private ShopOrderService shopOrderService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private WorkCenterService workCenterService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private PrintLogService printLogService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ItemService itemService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SfcService sfcService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public IPage<ProdReadyTask> selectPage(FrontPage<ProdReadyTask> frontPage, ProdReadyTask prodReadyTask) {
|
|
|
|
@ -289,5 +309,102 @@ public class ProdReadyTaskServiceImpl extends ServiceImpl<ProdReadyTaskMapper, P
|
|
|
|
|
return update;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void doPrint(ProdReadyTask prodReadyTask) {
|
|
|
|
|
String site = CommonMethods.getSite();
|
|
|
|
|
String user = CommonMethods.getUser();
|
|
|
|
|
String dispatchNo = prodReadyTask.getDispatchNo();
|
|
|
|
|
SfcDispatchDto sfcDispatchDto=new SfcDispatchDto();
|
|
|
|
|
sfcDispatchDto.setHandle(HandleEnum.SFC_DISPATCH.getHandle(site,dispatchNo));
|
|
|
|
|
sfcDispatchDto = sfcDispatchCommonService.findSfcDispatchBySfc(sfcDispatchDto);
|
|
|
|
|
List<PrintLog> printList=new ArrayList<>();
|
|
|
|
|
List<LabelPrintDto> labelPrintDtoList = new ArrayList<>();
|
|
|
|
|
String printData = null;
|
|
|
|
|
PrintLog printTag=new PrintLog();
|
|
|
|
|
|
|
|
|
|
String resrce = sfcDispatchDto.getResrce();
|
|
|
|
|
String printName = customFieldsService.getCustomFieldsValue(HandleEnum.RESOURCE.getHandle(site, resrce), CustomFieldConstant.RESRCE_CUSTOM_FIELD_PRINT_NAME);
|
|
|
|
|
if (StringUtil.isBlank(printName)){
|
|
|
|
|
throw new BaseException("资源维护的打印机不能为空");
|
|
|
|
|
}
|
|
|
|
|
String item = prodReadyTask.getItem();
|
|
|
|
|
Item selectCurrent = itemService.selectCurrent(site, item);
|
|
|
|
|
QueryWrapper<PrintLog> queryWrapper=new QueryWrapper();
|
|
|
|
|
queryWrapper.eq(PrintLog.SFC,prodReadyTask.getSfc());
|
|
|
|
|
queryWrapper.eq(PrintLog.STEP_ID,prodReadyTask.getStepId());
|
|
|
|
|
queryWrapper.eq(PrintLog.RESRCE,prodReadyTask.getResrce());
|
|
|
|
|
queryWrapper.eq(PrintLog.CATEGORY,Constants.PRINT_TYPE_SFC);
|
|
|
|
|
queryWrapper.eq(PrintLog.CATEGORY,Constants.PRINT_TYPE_SFC);
|
|
|
|
|
List<PrintLog> printLogList = printLogService.list(queryWrapper);
|
|
|
|
|
if (printLogList.isEmpty()){
|
|
|
|
|
//打印参数
|
|
|
|
|
LabelPrintDto labelPrintDto = new LabelPrintDto();
|
|
|
|
|
labelPrintDto.setPrinter(printName);
|
|
|
|
|
labelPrintDto.setPrintTemplate(Constants.PRINT_TYPE_SFC);
|
|
|
|
|
labelPrintDto.setItem(sfcDispatchDto.getItem());
|
|
|
|
|
labelPrintDto.setItemDescription(selectCurrent.getDescription());
|
|
|
|
|
labelPrintDto.setSfc(prodReadyTask.getSfc());
|
|
|
|
|
Sfc sfcServiceById = sfcService.getById(HandleEnum.SFC.getHandle(site, prodReadyTask.getSfc()));
|
|
|
|
|
String drawingRevision = customFieldsService.getCustomFieldsValue(sfcServiceById.getItemBo(), CustomFieldConstant.ITEM_DRAWING_REVISION);
|
|
|
|
|
labelPrintDto.setDrawingVersion(drawingRevision);
|
|
|
|
|
labelPrintDto.setQty(new BigDecimal(sfcServiceById.getQty()));
|
|
|
|
|
String workOrder = customFieldsService.getCustomFieldsValue(sfcServiceById.getShopOrderBo(), "WORK_ORDER");
|
|
|
|
|
labelPrintDto.setWorkOrder(workOrder);
|
|
|
|
|
labelPrintDto.setBlankingSize(sfcDispatchDto.getBlankingSize());
|
|
|
|
|
labelPrintDto.setOperation(sfcDispatchDto.getOperation());
|
|
|
|
|
labelPrintDtoList.add(labelPrintDto);
|
|
|
|
|
printData = JSON.toJSONString(labelPrintDtoList);
|
|
|
|
|
List<PrintLog> list = printLogService.list();
|
|
|
|
|
//打印记录
|
|
|
|
|
printTag.setHandle(UUID.randomUUID().toString());
|
|
|
|
|
printTag.setPrintName(printName);
|
|
|
|
|
printTag.setPrintTemplate(Constants.PRINT_TYPE_SFC);
|
|
|
|
|
printTag.setSite(site);
|
|
|
|
|
printTag.setCategory(Constants.PRINT_TYPE_SFC);
|
|
|
|
|
printTag.setPrintParam(JSON.toJSONString(labelPrintDtoList));
|
|
|
|
|
printTag.setSfc(prodReadyTask.getSfc());
|
|
|
|
|
printTag.setResrce(prodReadyTask.getResrce());
|
|
|
|
|
printTag.setStepId(prodReadyTask.getStepId());
|
|
|
|
|
printTag.setOperation(prodReadyTask.getOperation());
|
|
|
|
|
printTag.setItemBo(selectCurrent.getHandle());
|
|
|
|
|
printTag.setIsPrint("false");
|
|
|
|
|
printTag.setPrintNum(0);
|
|
|
|
|
printTag.setItem(item);
|
|
|
|
|
printTag.setItemDescription(selectCurrent.getDescription());
|
|
|
|
|
|
|
|
|
|
printList.add(printTag);
|
|
|
|
|
printLogService.savePrintLog(site,user,printTag);
|
|
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
printData = printLogList.get(0).getPrintParam();
|
|
|
|
|
}
|
|
|
|
|
String post = HttpUtil.post(printServer,printData , 30000);
|
|
|
|
|
/**
|
|
|
|
|
* {"msg":"打印成功","code":0}
|
|
|
|
|
* {"msg":"打印失败","code":500}
|
|
|
|
|
* 根据返回值,更新打印机信息-printName及打印是否成功信息isPrint
|
|
|
|
|
*/
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(post);
|
|
|
|
|
String code = jsonObject.getString("code");
|
|
|
|
|
if (code == null){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (post.indexOf("500") != -1){
|
|
|
|
|
throw BusinessException.build("打印失败!");
|
|
|
|
|
}
|
|
|
|
|
if (printLogList.isEmpty()){
|
|
|
|
|
printTag.setIsPrint("true");
|
|
|
|
|
printTag.setPrintNum(1);
|
|
|
|
|
printLogService.updateById(printTag);
|
|
|
|
|
}else {
|
|
|
|
|
PrintLog printLog = printLogList.get(0);
|
|
|
|
|
printTag.setIsPrint("true");
|
|
|
|
|
printTag.setPrintNum(printLog.getPrintNum()+1);
|
|
|
|
|
printTag.setModifiedDateTime(LocalDateTime.now());
|
|
|
|
|
printTag.setModifyUser(user);
|
|
|
|
|
printLogService.updateById(printLog);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|