| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | |
| | | import com.ruoyi.technology.mapper.TechnologyBomStructureMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyRoutingMapper; |
| | | import com.ruoyi.technology.pojo.TechnologyRouting; |
| | | import org.apache.commons.lang3.BooleanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | |
| | | * 新增生产数据 |
| | | */ |
| | | public void addProductionData(SalesLedgerProduct salesLedgerProduct) { |
| | | //先判断该产品是否需要生产 |
| | | if (!salesLedgerProduct.getIsProduction()) { |
| | | SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerProduct.getSalesLedgerId()); |
| | | if (salesLedger == null) { |
| | | return; |
| | | } |
| | | SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerProduct.getSalesLedgerId()); |
| | | boolean isFrameworkOrder = Objects.equals(salesLedger.getContractType(), 3); |
| | | // 框架合同不生成生产计划;框架订单固定生成(数量留空,下发时填写) |
| | | if (Objects.equals(salesLedger.getContractType(), 2)) { |
| | | return; |
| | | } |
| | | if (!isFrameworkOrder && !BooleanUtils.isTrue(salesLedgerProduct.getIsProduction())) { |
| | | return; |
| | | } |
| | | ProductionPlan productionPlan = new ProductionPlan(); |
| | | productionPlan.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId()); |
| | | productionPlan.setSalesLedgerProductId(salesLedgerProduct.getId()); |
| | | productionPlan.setMpsNo(generateNextPlanNo(com.ruoyi.common.utils.DateUtils.toLocalDate(salesLedger.getEntryDate()) |
| | | .format(DateTimeFormatter.ofPattern("yyyyMMdd")))); |
| | | // 计划单号日期前缀:登记日期为空时取当前日期 |
| | | java.time.LocalDate planDate = salesLedger.getEntryDate() != null |
| | | ? com.ruoyi.common.utils.DateUtils.toLocalDate(salesLedger.getEntryDate()) |
| | | : java.time.LocalDate.now(); |
| | | productionPlan.setMpsNo(generateNextPlanNo(planDate.format(DateTimeFormatter.ofPattern("yyyyMMdd")))); |
| | | productionPlan.setProductModelId(salesLedgerProduct.getProductModelId()); |
| | | productionPlan.setQtyRequired(salesLedgerProduct.getQuantity()); |
| | | productionPlan.setSource("销售"); |
| | | productionPlan.setStatus(0); |
| | | productionPlan.setRequiredDate(salesLedger.getDeliveryDate());//需求日期=交货日期 |
| | | productionPlan.setPromisedDeliveryDate(salesLedger.getDeliveryDate());//承诺日期=交货日期 |
| | | // 需求日期=交货日期,框架订单取产品交货日期,其余取主表交货日期 |
| | | LocalDate deliveryDate = isFrameworkOrder ? salesLedgerProduct.getDeliveryDate() : salesLedger.getDeliveryDate(); |
| | | productionPlan.setRequiredDate(deliveryDate);//需求日期=交货日期 |
| | | productionPlan.setPromisedDeliveryDate(deliveryDate);//承诺日期=交货日期 |
| | | productionPlanMapper.insert(productionPlan); |
| | | |
| | | } |
| | |
| | | .filter(Objects::nonNull) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | try { |
| | | S entity = mainEntityClass.getDeclaredConstructor().newInstance(); |
| | | Field idField = mainEntityClass.getDeclaredField("id"); |
| | | idField.setAccessible(true); |
| | | idField.set(entity, mainId); |
| | | |
| | | Field amountField = mainEntityClass.getDeclaredField("contractAmount"); |
| | | amountField.setAccessible(true); |
| | | amountField.set(entity, totalAmount); |
| | | |
| | | mainMapper.updateById(entity); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("动态更新主表金额失败", e); |
| | | } |
| | | // 仅更新金额列,避免整实体 updateById 把其它非空字段(如 contract_type 默认值 1)一并覆盖 |
| | | UpdateWrapper<S> wrapper = Wrappers.update(); |
| | | wrapper.eq("id", mainId) |
| | | .set("contract_amount", totalAmount); |
| | | mainMapper.update(null, wrapper); |
| | | } |
| | | @Override |
| | | public R judgmentInventory(SalesLedgerProduct salesLedgerProduct) { |