|
|
|
|
@ -26,7 +26,9 @@ import org.dromara.mes.enums.PlanStatusEnum;
|
|
|
|
|
import org.dromara.mes.mapper.ProdPlanInfoMapper;
|
|
|
|
|
import org.dromara.mes.service.IProdPlanInfoService;
|
|
|
|
|
import org.dromara.mes.service.IProdOrderInfoService;
|
|
|
|
|
import org.dromara.mes.service.IProdProductPlanDetailService;
|
|
|
|
|
import org.dromara.mes.domain.bo.ProdOrderInfoBo;
|
|
|
|
|
import org.dromara.mes.domain.bo.ProdProductPlanDetailBo;
|
|
|
|
|
import org.dromara.system.api.RemoteCodeRuleService;
|
|
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
@ -67,6 +69,9 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService {
|
|
|
|
|
@Autowired(required = false)
|
|
|
|
|
private IProdOrderInfoService prodOrderInfoService;
|
|
|
|
|
|
|
|
|
|
@Autowired(required = false)
|
|
|
|
|
private IProdProductPlanDetailService prodProductPlanDetailService;
|
|
|
|
|
|
|
|
|
|
@DubboReference
|
|
|
|
|
private RemoteCodeRuleService remoteCodeRuleService;
|
|
|
|
|
|
|
|
|
|
@ -116,7 +121,6 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MPJLambdaWrapper<ProdPlanInfo> buildQueryWrapper(ProdPlanInfoBo bo) {
|
|
|
|
|
System.out.println("wo;" + bo.getWorkshopId());
|
|
|
|
|
Map<String, Object> params = bo.getParams();
|
|
|
|
|
MPJLambdaWrapper<ProdPlanInfo> lqw = JoinWrappers.lambda(ProdPlanInfo.class)
|
|
|
|
|
.selectAll(ProdPlanInfo.class)
|
|
|
|
|
@ -244,6 +248,15 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService {
|
|
|
|
|
return Seq.getId(Seq.mesPlanCodeSeqType, Seq.mesPlanCodeCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取生产明细编号
|
|
|
|
|
*
|
|
|
|
|
* @return 生产明细编号
|
|
|
|
|
*/
|
|
|
|
|
private String getPlanDetailCode() {
|
|
|
|
|
return remoteCodeRuleService.selectCodeRuleCode("6");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询生产派工列表,join process
|
|
|
|
|
*
|
|
|
|
|
@ -279,6 +292,47 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService {
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public int orderAddMesProductPlanList(MesProductPlanEditVo mesProductPlanEditVo) {
|
|
|
|
|
Long[] machineIds = mesProductPlanEditVo.getMachineIds();
|
|
|
|
|
//要新增的派工数据列表
|
|
|
|
|
List<ProdPlanInfoBo> mesProductPlanList = mesProductPlanEditVo.getMesProductPlanList();
|
|
|
|
|
if (ObjectUtils.isEmpty(mesProductPlanList)) {
|
|
|
|
|
throw new ServiceException("无有效的派工数据提交");
|
|
|
|
|
}else {
|
|
|
|
|
for (ProdPlanInfoBo mesProductPlanBo : mesProductPlanList) {
|
|
|
|
|
//设置编号
|
|
|
|
|
mesProductPlanBo.setProductOrderId(mesProductPlanEditVo.getProductOrderId());
|
|
|
|
|
mesProductPlanBo.setPlanCode(getDispatchCode());
|
|
|
|
|
mesProductPlanBo.setDispatchAmount(mesProductPlanBo.getPlanAmount());
|
|
|
|
|
mesProductPlanBo.setImportFlag("0");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int successCount = 0;
|
|
|
|
|
for (Long machineId : machineIds) {
|
|
|
|
|
for (ProdPlanInfoBo productPlanBo : mesProductPlanList) {
|
|
|
|
|
productPlanBo.setReleaseId(machineId);
|
|
|
|
|
boolean flag = this.insertByBo(productPlanBo);
|
|
|
|
|
if (flag) {
|
|
|
|
|
successCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (successCount == 0) {
|
|
|
|
|
throw new ServiceException("派工数据保存失败");
|
|
|
|
|
}
|
|
|
|
|
return successCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 机加生产工单新增生产派工List
|
|
|
|
|
*
|
|
|
|
|
* @param mesProductPlanEditVo 生产派工VO对象
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public int orderAddMesProductPlanJJList(MesProductPlanEditVo mesProductPlanEditVo) {
|
|
|
|
|
Long productOrderId = mesProductPlanEditVo.getProductOrderId();
|
|
|
|
|
Long dispatchAmount = mesProductPlanEditVo.getDispatchAmount();
|
|
|
|
|
List<ProdPlanInfoBo> mesProductPlanList = mesProductPlanEditVo.getMesProductPlanList();
|
|
|
|
|
@ -370,6 +424,9 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean issuePlanByPlanIds(Long workshopId, List<Long> planIds) {
|
|
|
|
|
ProdPlanInfoBo bo = new ProdPlanInfoBo();
|
|
|
|
|
if (workshopId.equals(0L)){
|
|
|
|
|
workshopId = null;
|
|
|
|
|
}
|
|
|
|
|
bo.setWorkshopId(workshopId);
|
|
|
|
|
bo.setPlanIds(planIds);
|
|
|
|
|
List<ProdPlanInfoVo> prodPlanInfoVoList = queryList(bo);
|
|
|
|
|
@ -387,6 +444,206 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 开始工单(更新工单状态为已开始)
|
|
|
|
|
*
|
|
|
|
|
* @param planId 工单ID
|
|
|
|
|
* @return 是否成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean startPlan(Long planId) {
|
|
|
|
|
// 查询工单信息
|
|
|
|
|
ProdPlanInfoVo planInfoVo = queryById(planId);
|
|
|
|
|
if ("3".equals(planInfoVo.getReleaseType()) && planInfoVo.getReleaseId() != null) {
|
|
|
|
|
ProdPlanInfoBo queryBo = new ProdPlanInfoBo();
|
|
|
|
|
queryBo.setReleaseType("3");
|
|
|
|
|
queryBo.setReleaseId(planInfoVo.getReleaseId());
|
|
|
|
|
queryBo.setPlanStatus("2"); // 已开始状态
|
|
|
|
|
List<ProdPlanInfoVo> existingPlans = queryList(queryBo);
|
|
|
|
|
if (existingPlans != null && !existingPlans.isEmpty()) {
|
|
|
|
|
// 检查是否有其他工单(不是当前工单)已开始
|
|
|
|
|
boolean hasOtherStartedPlan = existingPlans.stream()
|
|
|
|
|
.anyMatch(p -> !p.getPlanId().equals(planId));
|
|
|
|
|
if (hasOtherStartedPlan) {
|
|
|
|
|
throw new ServiceException("该工位已有工单正在执行,每个工位只能有一个工单处于已开始状态!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 更新工单状态为已开始
|
|
|
|
|
ProdPlanInfoBo updateBo = new ProdPlanInfoBo();
|
|
|
|
|
updateBo.setPlanId(planId);
|
|
|
|
|
updateBo.setPlanStatus("2"); // 已开始
|
|
|
|
|
updateBo.setRealBeginTime(new Date()); // 记录实际开始时间
|
|
|
|
|
return this.updateByBo(updateBo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 停工(更新工单状态为已下发)
|
|
|
|
|
*
|
|
|
|
|
* @param planId 工单ID
|
|
|
|
|
* @return 是否成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean stopPlan(Long planId) {
|
|
|
|
|
// 查询工单信息
|
|
|
|
|
ProdPlanInfoVo planInfoVo = queryById(planId);
|
|
|
|
|
if (planInfoVo == null) {
|
|
|
|
|
throw new ServiceException("工单不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 校验工单状态,必须是已开始状态(2)才能停工
|
|
|
|
|
if (!"2".equals(planInfoVo.getPlanStatus())) {
|
|
|
|
|
throw new ServiceException("工单状态不是已开始,无法停工!当前状态:" + planInfoVo.getPlanStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新工单状态为已下发
|
|
|
|
|
ProdPlanInfoBo updateBo = new ProdPlanInfoBo();
|
|
|
|
|
updateBo.setPlanId(planId);
|
|
|
|
|
updateBo.setPlanStatus("1"); // 已下发
|
|
|
|
|
return this.updateByBo(updateBo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 复工(更新工单状态为已开始)
|
|
|
|
|
*
|
|
|
|
|
* @param planId 工单ID
|
|
|
|
|
* @return 是否成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean resumePlan(Long planId) {
|
|
|
|
|
// 查询工单信息
|
|
|
|
|
ProdPlanInfoVo planInfoVo = queryById(planId);
|
|
|
|
|
if (planInfoVo == null) {
|
|
|
|
|
throw new ServiceException("工单不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 校验工单状态,必须是已下发状态(1)才能复工
|
|
|
|
|
if (!"1".equals(planInfoVo.getPlanStatus())) {
|
|
|
|
|
throw new ServiceException("工单状态不是已下发,无法复工!当前状态:" + planInfoVo.getPlanStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果下达类型是工位(releaseType = "3"),需要检查该工位是否已有已开始的工单
|
|
|
|
|
if ("3".equals(planInfoVo.getReleaseType()) && planInfoVo.getReleaseId() != null) {
|
|
|
|
|
ProdPlanInfoBo queryBo = new ProdPlanInfoBo();
|
|
|
|
|
queryBo.setReleaseType("3");
|
|
|
|
|
queryBo.setReleaseId(planInfoVo.getReleaseId());
|
|
|
|
|
queryBo.setPlanStatus("2"); // 已开始状态
|
|
|
|
|
List<ProdPlanInfoVo> existingPlans = queryList(queryBo);
|
|
|
|
|
if (existingPlans != null && !existingPlans.isEmpty()) {
|
|
|
|
|
// 检查是否有其他工单(不是当前工单)已开始
|
|
|
|
|
boolean hasOtherStartedPlan = existingPlans.stream()
|
|
|
|
|
.anyMatch(p -> !p.getPlanId().equals(planId));
|
|
|
|
|
if (hasOtherStartedPlan) {
|
|
|
|
|
throw new ServiceException("该工位已有工单正在执行,每个工位只能有一个工单处于已开始状态!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新工单状态为已开始
|
|
|
|
|
ProdPlanInfoBo updateBo = new ProdPlanInfoBo();
|
|
|
|
|
updateBo.setPlanId(planId);
|
|
|
|
|
updateBo.setPlanStatus("2"); // 已开始
|
|
|
|
|
return this.updateByBo(updateBo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 报工(更新报工数量和不良数量,存入生产信息)
|
|
|
|
|
*
|
|
|
|
|
* @param bo 报工信息
|
|
|
|
|
* @return 是否成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean reportWork(ProdPlanInfoBo bo) {
|
|
|
|
|
// 参数校验
|
|
|
|
|
if (bo.getPlanId() == null) {
|
|
|
|
|
throw new ServiceException("工单ID不能为空");
|
|
|
|
|
}
|
|
|
|
|
BigDecimal reportQuantity = bo.getReportQuantity() != null ? bo.getReportQuantity() : BigDecimal.ZERO;
|
|
|
|
|
BigDecimal defectiveQuantity = bo.getDefectiveQuantity() != null ? bo.getDefectiveQuantity() : BigDecimal.ZERO;
|
|
|
|
|
|
|
|
|
|
if (reportQuantity.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
throw new ServiceException("报工数量必须大于0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询并校验工单
|
|
|
|
|
ProdPlanInfoVo planInfoVo = queryById(bo.getPlanId());
|
|
|
|
|
if (planInfoVo == null) {
|
|
|
|
|
throw new ServiceException("工单不存在");
|
|
|
|
|
}
|
|
|
|
|
if (!"2".equals(planInfoVo.getPlanStatus())) {
|
|
|
|
|
throw new ServiceException("工单状态不是已开始,无法报工!当前状态:" + planInfoVo.getPlanStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算并校验可报工量
|
|
|
|
|
BigDecimal planAmount = planInfoVo.getPlanAmount() != null ? planInfoVo.getPlanAmount() : BigDecimal.ZERO;
|
|
|
|
|
BigDecimal currentCompleteAmount = planInfoVo.getCompleteAmount() != null ? planInfoVo.getCompleteAmount() : BigDecimal.ZERO;
|
|
|
|
|
BigDecimal reportableQuantity = planAmount.subtract(currentCompleteAmount);
|
|
|
|
|
|
|
|
|
|
if (reportQuantity.compareTo(reportableQuantity) > 0) {
|
|
|
|
|
throw new ServiceException("报工数量不能超过可报工量,可报工量:" + reportableQuantity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新工单完成数量
|
|
|
|
|
BigDecimal newCompleteAmount = currentCompleteAmount.add(reportQuantity);
|
|
|
|
|
ProdPlanInfoBo updateBo = new ProdPlanInfoBo();
|
|
|
|
|
updateBo.setPlanId(bo.getPlanId());
|
|
|
|
|
updateBo.setCompleteAmount(newCompleteAmount);
|
|
|
|
|
|
|
|
|
|
// 如果完成数量达到计划数量,更新状态为已完成
|
|
|
|
|
if (newCompleteAmount.compareTo(planAmount) >= 0) {
|
|
|
|
|
updateBo.setPlanStatus("3");
|
|
|
|
|
updateBo.setRealEndTime(new Date());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新工单
|
|
|
|
|
Boolean updateResult = this.updateByBo(updateBo);
|
|
|
|
|
if (!updateResult) {
|
|
|
|
|
throw new ServiceException("更新工单完成数量失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建报工记录到生产信息表
|
|
|
|
|
createReportDetail(planInfoVo, reportQuantity, defectiveQuantity);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建报工明细记录
|
|
|
|
|
*
|
|
|
|
|
* @param planInfoVo 工单信息
|
|
|
|
|
* @param reportQuantity 报工数量(对应complete_amount)
|
|
|
|
|
* @param defectiveQuantity 不良数量(对应defective_amount)
|
|
|
|
|
*/
|
|
|
|
|
private void createReportDetail(ProdPlanInfoVo planInfoVo, BigDecimal reportQuantity, BigDecimal defectiveQuantity) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
ProdProductPlanDetailBo detailBo = new ProdProductPlanDetailBo();
|
|
|
|
|
detailBo.setPlanDetailCode(getPlanDetailCode()); // 通过编码规则生成明细编号
|
|
|
|
|
detailBo.setPlanId(planInfoVo.getPlanId());
|
|
|
|
|
detailBo.setPlanCode(planInfoVo.getPlanCode());
|
|
|
|
|
detailBo.setCompleteAmount(reportQuantity);
|
|
|
|
|
detailBo.setRemainingAmount(defectiveQuantity);
|
|
|
|
|
detailBo.setRealBeginTime(new Date());
|
|
|
|
|
detailBo.setPlanDetailStatus("3");
|
|
|
|
|
detailBo.setShiftId(planInfoVo.getShiftId());
|
|
|
|
|
detailBo.setClassTeamId(planInfoVo.getClassTeamId());
|
|
|
|
|
|
|
|
|
|
String remark = "报工数量:" + reportQuantity;
|
|
|
|
|
if (defectiveQuantity.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
remark += ",不良数量:" + defectiveQuantity;
|
|
|
|
|
}
|
|
|
|
|
detailBo.setRemark(remark);
|
|
|
|
|
|
|
|
|
|
prodProductPlanDetailService.insertJJByBo(detailBo);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.warn("创建报工记录失败: {}", e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询生产计划监控列表(不分页)
|
|
|
|
|
*/
|
|
|
|
|
|