update 机加生产工单新增生产派工,新增机加生产信息,开始、报工工单

master
yinq 3 days ago
parent 61e09f6d8e
commit 9d5753abdb

@ -26,16 +26,25 @@ public class DynamicBaseSqlProvider {
"#{entity.productOrderId}", "#{entity.dispatchCode}", "#{entity.processOrder}", "#{entity.materialBomId}");
break;
case "prod_product_plan_detail":
sql.INTO_COLUMNS("plan_detail_code", "plan_id", "plan_code", "user_id", "user_name",
"classes_id", "team_id", "complete_amount", "unit_id", "unit_name", "real_begin_time", "real_end_time",
"attach_id", "material_barcode", "return_barcode", "train_number", "tooling_id", "capsule_id", "shift_change_id",
"alarm_flag", "supple_flag", "remark", "create_dept", "create_by", "create_time");
sql.INTO_VALUES("#{entity.planDetailCode}", "#{entity.planId}", "#{entity.planCode}",
"#{entity.userId}", "#{entity.userName}", "#{entity.classesId}", "#{entity.teamId}", "#{entity.completeAmount}",
"#{entity.unitId}", "#{entity.unitName}", "#{entity.realBeginTime}", "#{entity.realEndTime}", "#{entity.attachId}",
"#{entity.materialBarcode}", "#{entity.returnBarcode}", "#{entity.trainNumber}", "#{entity.toolingId}",
"#{entity.capsuleId}", "#{entity.shiftChangeId}", "#{entity.alarmFlag}",
"#{entity.suppleFlag}", "#{entity.remark}", "#{entity.createDept}", "#{entity.createBy}", "#{entity.createTime}");
sql.INTO_COLUMNS("plan_detail_code", "plan_id", "plan_code",
"user_id", "user_name", "shift_id", "class_team_id",
"complete_amount", "unit_id", "unit_name", "real_begin_time",
"real_end_time", "attach_id", "material_barcode", "return_barcode",
"train_number", "tooling_id", "capsule_id", "shift_change_id",
"sfp_detail_id", "forming_detail_id", "vul_detail_id",
"plan_detail_status", "first_flag", "alarm_flag", "supple_flag",
"remark", "create_dept", "create_by", "create_time", "remaining_amount");
sql.INTO_VALUES("#{entity.planDetailCode}", "#{entity.planId}",
"#{entity.planCode}", "#{entity.userId}", "#{entity.userName}",
"#{entity.shiftId}", "#{entity.classTeamId}", "#{entity.completeAmount}",
"#{entity.unitId}", "#{entity.unitName}", "#{entity.realBeginTime}",
"#{entity.realEndTime}", "#{entity.attachId}", "#{entity.materialBarcode}",
"#{entity.returnBarcode}", "#{entity.trainNumber}", "#{entity.toolingId}",
"#{entity.capsuleId}", "#{entity.shiftChangeId}", "#{entity.sfpDetailId}",
"#{entity.formingDetailId}", "#{entity.vulDetailId}", "#{entity.planDetailStatus}",
"#{entity.firstFlag}", "#{entity.alarmFlag}", "#{entity.suppleFlag}",
"#{entity.remark}", "#{entity.createDept}", "#{entity.createBy}",
"#{entity.createTime}", "#{entity.remainingAmount}");
break;
}
return sql.toString();
@ -67,6 +76,9 @@ public class DynamicBaseSqlProvider {
if (hasFieldValue(entity, "dispatchAmount")) {
sql.SET("dispatch_amount = #{entity.dispatchAmount}");
}
if (hasFieldValue(entity, "completeAmount")) {
sql.SET("complete_amount = #{entity.completeAmount}");
}
if (hasFieldValue(entity, "planBeginTime")) {
sql.SET("plan_begin_time = #{entity.planBeginTime}");
}

@ -180,6 +180,15 @@ public class ProdPlanInfoController extends BaseController {
return toAjax(prodPlanInfoService.orderAddMesProductPlanList(productPlanEditVo));
}
/**
* List
*/
@PostMapping("/orderAddProductPlanJJList")
@RepeatSubmit(message = "正在提交,请稍后")
public R<Void> orderAddMesProductPlanJJList(@RequestBody MesProductPlanEditVo productPlanEditVo) {
return toAjax(prodPlanInfoService.orderAddMesProductPlanJJList(productPlanEditVo));
}
/**
*
* @param workshopId
@ -232,6 +241,57 @@ public class ProdPlanInfoController extends BaseController {
return prodPlanInfoService.sendEvent(planId, event);
}
/**
*
* @param planId ID
* @return
*/
@SaCheckPermission("mes:planInfo:edit")
@Log(title = "生产工单信息", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping("/start/{planId}")
public R<Void> startPlan(@NotNull(message = "主键不能为空") @PathVariable Long planId) {
return toAjax(prodPlanInfoService.startPlan(planId));
}
/**
*
* @param planId ID
* @return
*/
@SaCheckPermission("mes:planInfo:edit")
@Log(title = "生产工单信息", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping("/stop/{planId}")
public R<Void> stopPlan(@NotNull(message = "主键不能为空") @PathVariable Long planId) {
return toAjax(prodPlanInfoService.stopPlan(planId));
}
/**
*
* @param planId ID
* @return
*/
@SaCheckPermission("mes:planInfo:edit")
@Log(title = "生产工单信息", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping("/resume/{planId}")
public R<Void> resumePlan(@NotNull(message = "主键不能为空") @PathVariable Long planId) {
return toAjax(prodPlanInfoService.resumePlan(planId));
}
/**
*
* @param bo
* @return
*/
@SaCheckPermission("mes:planInfo:edit")
@Log(title = "生产工单信息", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PostMapping("/report")
public R<Void> reportWork(@Validated @RequestBody ProdPlanInfoBo bo) {
return toAjax(prodPlanInfoService.reportWork(bo));
}
// @SaCheckPermission("mes:planInfo:export")
// @Log(title = "生产计划监控", businessType = BusinessType.EXPORT)

@ -198,5 +198,15 @@ public class ProdPlanInfoBo extends BaseEntity {
private List<Long> planIds;
/**
*
*/
private BigDecimal reportQuantity;
/**
*
*/
private BigDecimal defectiveQuantity;
}

@ -31,4 +31,9 @@ public class MesProductPlanEditVo {
* ID
*/
private Long[] toDeletedPlanIds;
/**
* Ids
*/
private Long[] machineIds;
}

@ -102,6 +102,14 @@ public interface IProdPlanInfoService {
*/
int orderAddMesProductPlanList(MesProductPlanEditVo mesProductPlanEditVo);
/**
* List
*
* @param mesProductPlanEditVo VO
* @return
*/
int orderAddMesProductPlanJJList(MesProductPlanEditVo mesProductPlanEditVo);
/**
*
* @param workshopId
@ -120,7 +128,33 @@ public interface IProdPlanInfoService {
public boolean sendEvent(Long planId, PlanEventEnum event);
/**
*
* @param planId ID
* @return
*/
Boolean startPlan(Long planId);
/**
*
* @param planId ID
* @return
*/
Boolean stopPlan(Long planId);
/**
*
* @param planId ID
* @return
*/
Boolean resumePlan(Long planId);
/**
*
* @param bo
* @return
*/
Boolean reportWork(ProdPlanInfoBo bo);
/**
*

@ -49,6 +49,14 @@ public interface IProdProductPlanDetailService {
*/
Boolean insertByBo(ProdProductPlanDetailBo bo);
/**
*
*
* @param bo
* @return
*/
Boolean insertJJByBo(ProdProductPlanDetailBo bo);
/**
*
*

@ -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);
}
}
/**
* ()
*/

@ -146,6 +146,23 @@ public class ProdProductPlanDetailServiceImpl implements IProdProductPlanDetailS
return flag;
}
/**
*
*
* @param bo
* @return
*/
@Override
public Boolean insertJJByBo(ProdProductPlanDetailBo bo) {
ProdProductPlanDetail add = MapstructUtils.convert(bo, ProdProductPlanDetail.class);
validEntityBeforeSave(add);
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setPlanDetailId(add.getPlanDetailId());
}
return flag;
}
/**
*
*

@ -32,8 +32,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mbpi.process_name,mbpi.process_type,mbpi.production_time
from prod_base_route_process mbrp
left join prod_base_process_info mbpi on mbrp.process_id=mbpi.process_id
<where>
and mbrp.del_flag = '0'
<if test="routeId != null "> and mbrp.route_id = #{routeId}</if>
<if test="processId != null "> and mbrp.process_id = #{processId}</if>
<if test="processOrder != null "> and mbrp.process_order = #{processOrder}</if>

Loading…
Cancel
Save