| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | |
| | | |
| | | @Override |
| | | public IPage<SalesLedgerSchedulingDto> listPage(Page page, SalesLedgerSchedulingDto salesLedgerSchedulingDto) { |
| | | salesLedgerSchedulingDto.setProductionUserId(SecurityUtils.getLoginUser().getUser().getUserId()); |
| | | salesLedgerSchedulingDto.setProductionUserName(SecurityUtils.getLoginUser().getUser().getNickName()); |
| | | IPage<SalesLedgerSchedulingDto> list = salesLedgerSchedulingMapper.listPage(page, salesLedgerSchedulingDto); |
| | | if(list.getTotal() == 0){ |
| | | return list; |
| | |
| | | i++; |
| | | continue; |
| | | } |
| | | // 获取空余炒机 |
| | | String[] split = productionDispatchAddDto.getSpeculativeTradingName().split(","); |
| | | if(split != null && split.length == 0){ |
| | | SysUser sysUser1 = sysUserMapper.selectUserById(productionDispatchAddDto.getProductionUserId() == null ? loginUser.getUser().getUserId() : productionDispatchAddDto.getSchedulingUserId()); |
| | | if(sysUser1 == null){ |
| | | i++; |
| | | continue; |
| | | } |
| | | List<SpeculativeTradingInfo> speculativeTradingInfos = speculativeTradingInfoMapper.selectList(new LambdaQueryWrapper<SpeculativeTradingInfo>() |
| | | .in(SpeculativeTradingInfo::getName, Arrays.asList(split)) |
| | | .orderByAsc(SpeculativeTradingInfo::getSort)); |
| | | if(CollectionUtils.isEmpty(speculativeTradingInfos)){ |
| | | i++; |
| | | continue; |
| | | } |
| | | AtomicReference<String> name = new AtomicReference<>(""); //需要绑定的炒机 |
| | | //通过规格型号和排产数量计算本次生产产量 |
| | | String[] split1 = productionDispatchAddDto.getSpecificationModel().split("\\*"); |
| | | if(split1.length != 2){ |
| | | i++; |
| | | continue; |
| | | } |
| | | // 本次生产产量 |
| | | BigDecimal productionNum = new BigDecimal(split1[0]) |
| | | .multiply(new BigDecimal(split1[1]).multiply(productionDispatchAddDto.getSchedulingNum())); |
| | | // 多个炒机情况 |
| | | if(speculativeTradingInfos.size() > 1){ |
| | | for (SpeculativeTradingInfo speculativeTradingInfo : speculativeTradingInfos) { |
| | | // 获取该炒机正在排产量 |
| | | BigDecimal schedulingNumBySpeculativeTradingName = getSchedulingNumBySpeculativeTradingName(speculativeTradingInfo.getName()); |
| | | // 如果该炒机总量(单位kg需要乘1000) - 正在排产量 >=本次生产产量就分配此炒机 |
| | | if(speculativeTradingInfo.getWorkLoad().multiply(new BigDecimal(1000)).subtract(schedulingNumBySpeculativeTradingName).compareTo(productionNum) >= 0){ |
| | | name.set(speculativeTradingInfo.getName()); |
| | | break; |
| | | } |
| | | } |
| | | }else{ |
| | | // 单个炒机情况 |
| | | name.set(speculativeTradingInfos.get(0).getName()); |
| | | } |
| | | if(name.get().isEmpty()){ |
| | | i++; |
| | | continue; |
| | | } |
| | | // // 获取空余炒机 |
| | | // String[] split = productionDispatchAddDto.getSpeculativeTradingName().split(","); |
| | | // if(split != null && split.length == 0){ |
| | | // i++; |
| | | // continue; |
| | | // } |
| | | // List<SpeculativeTradingInfo> speculativeTradingInfos = speculativeTradingInfoMapper.selectList(new LambdaQueryWrapper<SpeculativeTradingInfo>() |
| | | // .in(SpeculativeTradingInfo::getName, Arrays.asList(split)) |
| | | // .orderByAsc(SpeculativeTradingInfo::getSort)); |
| | | // if(CollectionUtils.isEmpty(speculativeTradingInfos)){ |
| | | // i++; |
| | | // continue; |
| | | // } |
| | | // AtomicReference<String> name = new AtomicReference<>(""); //需要绑定的炒机 |
| | | // //通过规格型号和排产数量计算本次生产产量 |
| | | // String[] split1 = productionDispatchAddDto.getSpecificationModel().split("\\*"); |
| | | // if(split1.length != 2){ |
| | | // i++; |
| | | // continue; |
| | | // } |
| | | // // 本次生产产量 |
| | | // BigDecimal productionNum = new BigDecimal(split1[0]) |
| | | // .multiply(new BigDecimal(split1[1]).multiply(productionDispatchAddDto.getSchedulingNum())); |
| | | // // 多个炒机情况 |
| | | // if(speculativeTradingInfos.size() > 1){ |
| | | // for (SpeculativeTradingInfo speculativeTradingInfo : speculativeTradingInfos) { |
| | | // // 获取该炒机正在排产量 |
| | | // BigDecimal schedulingNumBySpeculativeTradingName = getSchedulingNumBySpeculativeTradingName(speculativeTradingInfo.getName()); |
| | | // // 如果该炒机总量(单位kg需要乘1000) - 正在排产量 >=本次生产产量就分配此炒机 |
| | | // if(speculativeTradingInfo.getWorkLoad().multiply(new BigDecimal(1000)).subtract(schedulingNumBySpeculativeTradingName).compareTo(productionNum) >= 0){ |
| | | // name.set(speculativeTradingInfo.getName()); |
| | | // break; |
| | | // } |
| | | // } |
| | | // }else{ |
| | | // // 单个炒机情况 |
| | | // name.set(speculativeTradingInfos.get(0).getName()); |
| | | // } |
| | | // if(name.get().isEmpty()){ |
| | | // i++; |
| | | // continue; |
| | | // } |
| | | SalesLedgerScheduling salesLedgerScheduling = SalesLedgerScheduling.builder() |
| | | .salesLedgerId(productionDispatchAddDto.getSalesLedgerId()) |
| | | .salesLedgerProductId(productionDispatchAddDto.getSalesLedgerProductId()) |
| | | .speculativeTradingName(name.get()) |
| | | // .speculativeTradingName(name.get()) |
| | | .productionUserId(sysUser1.getUserId()) |
| | | .productionUserName(sysUser1.getNickName()) |
| | | .productionLineId(productionDispatchAddDto.getLineId()) |
| | | .schedulingUserId(sysUser.getUserId()) |
| | | .schedulingUserName(sysUser.getNickName()) |
| | | .schedulingNum(productionDispatchAddDto.getSchedulingNum()) |
| | |
| | | return new BigDecimal(totalNum.get()).multiply(new BigDecimal(100)).divide(lossNum, 2,RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | private LossMapper lossMapper; |
| | | private final LossMapper lossMapper; |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | @Override |
| | | public IPage<SalesLedgerSchedulingProcessDto> listPageProcess(Page page, SalesLedgerSchedulingProcessDto salesLedgerSchedulingDto) { |
| | | Long userId = SecurityUtils.getLoginUser().getUserId(); |
| | | salesLedgerSchedulingDto.setProductionUserId(userId); |
| | | IPage<SalesLedgerSchedulingProcessDto> list = salesLedgerSchedulingMapper.listPageProcess(page, salesLedgerSchedulingDto); |
| | | // Set<Long> collect = list.getRecords().stream().map(SalesLedgerSchedulingProcessDto::getId).collect(Collectors.toSet()); |
| | | // if(CollectionUtils.isEmpty(collect)) return list; |
| | |
| | | SalesLedgerWork.SalesLedgerWorkBuilder salesLedgerWorkBuilder = SalesLedgerWork.builder() |
| | | .salesLedgerSchedulingId(salesLedgerScheduling.getId()) |
| | | .salesLedgerId(salesLedgerScheduling.getSalesLedgerId()) |
| | | .productionUserId(salesLedgerScheduling.getProductionUserId()) |
| | | .productionUserName(salesLedgerScheduling.getProductionUserName()) |
| | | .remark(processSchedulingDto.getRemark()) |
| | | .type(processSchedulingDto.getType()) |
| | | .loss(processSchedulingDto.getLoss()) |