package com.aps.core.service.impl; import java.time.LocalDateTime; import java.util.List; import java.util.Map; import com.aps.common.core.utils.uuid.IdUtils; import com.aps.common.core.utils.uuid.UUID; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.commons.config.DefaultsBindHandlerAdvisor; import org.springframework.stereotype.Service; import com.aps.core.mapper.ApsPartRouteStatMapper; import com.aps.core.domain.ApsPartRouteStat; import com.aps.core.service.IApsPartRouteStatService; import static java.util.stream.Collectors.groupingBy; /** * 零件统计表Service业务层处理 * * @author zhl * @date 2025-04-11 */ @Service public class ApsPartRouteStatServiceImpl implements IApsPartRouteStatService { @Autowired private ApsPartRouteStatMapper apsPartRouteStatMapper; private DefaultsBindHandlerAdvisor.MappingsProvider mappingsProvider; /** * 查询零件统计表 * * @param id 零件统计表主键 * @return 零件统计表 */ @Override public ApsPartRouteStat selectApsPartRouteStatById(String id) { return apsPartRouteStatMapper.selectApsPartRouteStatById(id); } /** * 查询零件统计表列表 * * @param apsPartRouteStat 零件统计表 * @return 零件统计表 */ @Override public List selectApsPartRouteStatList(ApsPartRouteStat apsPartRouteStat) { return apsPartRouteStatMapper.selectApsPartRouteStatList(apsPartRouteStat); } /** * 新增零件统计表 * * @param apsPartRouteStat 零件统计表 * @return 结果 */ @Override public int insertApsPartRouteStat(ApsPartRouteStat apsPartRouteStat) { return apsPartRouteStatMapper.insertApsPartRouteStat(apsPartRouteStat); } /** * 修改零件统计表 * * @param apsPartRouteStat 零件统计表 * @return 结果 */ @Override public int updateApsPartRouteStat(ApsPartRouteStat apsPartRouteStat) { return apsPartRouteStatMapper.updateApsPartRouteStat(apsPartRouteStat); } /** * 批量删除零件统计表 * * @param ids 需要删除的零件统计表主键 * @return 结果 */ @Override public int deleteApsPartRouteStatByIds(String[] ids) { return apsPartRouteStatMapper.deleteApsPartRouteStatByIds(ids); } /** * 删除零件统计表信息 * * @param id 零件统计表主键 * @return 结果 */ @Override public int deleteApsPartRouteStatById(String id) { return apsPartRouteStatMapper.deleteApsPartRouteStatById(id); } public void updatePartRoutPlanDate() { List tempList = apsPartRouteStatMapper.selectPartRoutStat(); /*对tempList 按照 workOrderNo 进行分组*/ Map> groupByWorkOrderNo = tempList.stream().collect(groupingBy(ApsPartRouteStat::getWorkOrderNo)); /*本次计算批次号*/ String batchNum = IdUtils.fastSimpleUUID(); apsPartRouteStatMapper.deleteLastBatch(batchNum); for (Map.Entry> entry : groupByWorkOrderNo.entrySet()) { /*取出每个零件工单的工艺路线信息*/ List apsPartRouteStatList = entry.getValue(); /*按照工序号进行排序*/ apsPartRouteStatList.sort((a, b)->a.getRoadProcessNumber().compareTo(b.getRoadProcessNumber())); /*临时保存 上一道工序的工序总工时*/ ApsPartRouteStat last=null; for (int i = 0; i 0) { if (last != null) { stat.setProcessPlanStartDay(last.getProcessPlanStartDay().plusHours(last.getProcessTotalTime())); } } /*保存上一步计算的 开工日*/ last = stat; stat.setId(IdUtils.fastUUID().toString()); stat.setBatchNumber(batchNum); apsPartRouteStatMapper.insertApsPartRouteStat(stat); } } apsPartRouteStatMapper.deleteLastBatch(batchNum); } }