| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | if (orderDao.exists(p.name, p.id)) { |
| | | throw new RuntimeException("订单名称不能重复"); |
| | | } |
| | | p.setDeleted(false); |
| | | extractedCheck(p); |
| | | p.deleted = false; |
| | | BaUser loginUser = userUtil.getUser(UserTokenContext.get()); |
| | | if (loginUser != null) { |
| | | p.creator = loginUser.id; |
| | |
| | | if (orderDao.exists(p.name, p.id)) { |
| | | throw new RuntimeException("订单名称不能重复"); |
| | | } |
| | | extractedCheck(p); |
| | | int count = orderDao.updateByPrimaryKeySelective(p); |
| | | if (count > 0) { |
| | | saveOrderItems(p); |
| | |
| | | } |
| | | return orderList; |
| | | } |
| | | /** |
| | | * 只更新状态,不更新其他字段 |
| | | * @param order |
| | | * 更新状态 如果有在执行中的任务,不让暂停 |
| | | * @return |
| | | */ |
| | | @Transactional |
| | | public int updateStatus(PrOrder order) { |
| | | if(order.status == OrderStatusEnum.NORMAL.getCode()){ |
| | | PrOrder prOrder = orderDao.selectByPrimaryKey(order.id); |
| | | prOrder.status = order.status; |
| | | extractedCheck(prOrder); |
| | | } |
| | | PrOrder param = new PrOrder(); |
| | | param.id =order.id; |
| | | param.status = order.status; |
| | | return orderDao.updateByPrimaryKeySelective(param); |
| | | } |
| | | //如果交期小于当前时间,不允许设置为正常 |
| | | private void extractedCheck(PrOrder order) { |
| | | if(order.status == OrderStatusEnum.NORMAL.getCode()){ |
| | | String deliveryDateStr = order.getDeliveryDate(); |
| | | LocalDate endDate = LocalDate.parse(deliveryDateStr, DateTimeFormatter.ISO_LOCAL_DATE); |
| | | LocalDate nextDay = endDate.plusDays(1); |
| | | LocalDate today = LocalDate.now(); // 获取当前日期 |
| | | if (nextDay.isBefore(today)) { |
| | | throw new RuntimeException("交付日期必须大于等于当前日期,请修改交付日期"); |
| | | } |
| | | } |
| | | //如果有在生产的任务不能设置为暂停 或 结束 |
| | | /* |
| | | PrProductionProcess process = processDao.selectByPrimaryKey(order.processId); |
| | | if(process == null || !process.proId.equals(order.proId)){ |
| | | throw new RuntimeException("产品与生产流程不匹配"); |
| | | } |
| | | //开始日期要小于结束日期 |
| | | if(order.startDate.compareTo(order.endDate) > 0){ |
| | | throw new RuntimeException("开始日期不能大于结束日期"); |
| | | }*/ |
| | | } |
| | | } |