| | |
| | | import com.aps.common.core.annotation.Excel; |
| | | import com.aps.common.core.web.domain.BaseEntity; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | |
| | | */ |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @Data |
| | | |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class ApsBom extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | |
| | | */ |
| | | public int deleteApsPlateStandardRequireBomStockDetailById(Long id); |
| | | |
| | | void saveStorageAndDetail(ApsMaterialStorageManagement itemStorage, ApsPlatePlan plan, ApsBom bomLine, String batchNum, BigDecimal deductionAmount, BigDecimal afterStockAmount,Long requireId); |
| | | void saveStorageAndDetail(ApsMaterialStorageManagement itemStorage, ApsPlatePlan plan, String bomLineId,String itemCode, String batchNum, BigDecimal deductionAmount, BigDecimal afterStockAmount,Long requireId); |
| | | } |
| | |
| | | ApsBom build = new ApsBom(); |
| | | build.setBomHeaderId(apsBomHeader.getBomHeaderId()); |
| | | build.setOrgCode(apsBomHeader.getOrgCode()); |
| | | List<ApsBom> apsBoms = apsBomMapper.selectApsBomList(build); |
| | | return apsBoms; |
| | | bomLineList = apsBomMapper.selectApsBomList(build); |
| | | } |
| | | return bomLineList; |
| | | } |
| | |
| | | |
| | | import cn.hutool.core.util.IdUtil; |
| | | import com.aps.common.core.utils.DateUtils; |
| | | import com.aps.common.security.utils.SecurityUtils; |
| | | import com.aps.core.domain.ApsPlatePlan; |
| | | import com.aps.core.domain.ApsPlateStandardRequire; |
| | | import com.aps.core.mapper.ApsPlatePlanMapper; |
| | |
| | | .deductionAmount(netRequirement) |
| | | .afterProdAmount(subtract) |
| | | .batchNumber(require.getBatchNumber()) |
| | | .orgCode(require.getOrgCode()) |
| | | .delFlag("0") |
| | | .build(); |
| | | bomOrderDetail.setCreateTime(DateUtils.getNowDate()); |
| | | bomOrderDetail.setCreateBy(SecurityUtils.getUsername()); |
| | | apsPlateStandardRequireBomOrderDetailMapper.insertApsPlateStandardRequireBomOrderDetail(bomOrderDetail); |
| | | } |
| | | } |
| | |
| | | * 计算物料剩余库存 并保存物料剩余库存明细。 |
| | | * */ |
| | | @Override |
| | | public void saveStorageAndDetail(ApsMaterialStorageManagement itemStorage, ApsPlatePlan plan, ApsBom bomLine, String batchNum, BigDecimal deductionAmount, BigDecimal afterStockAmount,Long requireId){ |
| | | public void saveStorageAndDetail(ApsMaterialStorageManagement itemStorage, ApsPlatePlan plan, String bomLineId,String itemCode, String batchNum, BigDecimal deductionAmount, BigDecimal afterStockAmount,Long requireId){ |
| | | /*更新物料剩余库存*/ |
| | | itemStorageMapper.updateMaterialStorageByVersion(itemStorage.getId(), afterStockAmount,itemStorage.getVersion()); |
| | | /*记录扣减明细*/ |
| | |
| | | .id(IdUtil.getSnowflakeNextId()) |
| | | .requireId(requireId) |
| | | .requireTrackId(plan.getRequireId()) |
| | | .bomLineId(bomLine.getBomLineId()) |
| | | .bomLineCode(bomLine.getItemCode()) |
| | | .bomLineId(bomLineId) |
| | | .bomLineCode(itemCode) |
| | | .beforeStockAmount(itemStorage.getRemainderStock()) |
| | | .deductionAmount(deductionAmount) |
| | | .afterStockAmount(afterStockAmount) |
| | |
| | | String itemNumber = mainPlan.getItemNumber(); |
| | | /*根据料号 获取BOM Header */ |
| | | /*当前Bom节点处理完成后,处理下级BOM*/ |
| | | List<ApsBom> bomLineList = bomLineService.selectApsBomLineList(plantCode, itemNumber); |
| | | |
| | | List<ApsPlateStandardRequire> requiresList=new ArrayList<>(); |
| | | if(!bomLineList.isEmpty()){ |
| | | bomLineList.forEach(line -> { |
| | | getBomRequires(plantCode, line, batchNum, null, mainPlan, requiresList, 0L); |
| | | }); |
| | | } |
| | | |
| | | getBomRequires(plantCode, "0",itemNumber,BigDecimal.ONE, batchNum, null, mainPlan, requiresList, 0L); |
| | | |
| | | // 批量插入以提高性能 |
| | | if (!requiresList.isEmpty()) { |
| | | int batchSize = 1000; |
| | |
| | | |
| | | /** |
| | | * 构建需求信息 |
| | | * */ |
| | | private void getBomRequires(String plant, ApsBom bomLine, String batchNum, Date upLevelStartDate, ApsPlatePlan plan, List<ApsPlateStandardRequire> allRequires, Long level) { |
| | | |
| | | String itemNumber = bomLine.getItemCode(); |
| | | * |
| | | * @param plant 工厂代码 |
| | | * @param bomLineId BOM行ID |
| | | * @param itemCode 物料代码 |
| | | * @param itemNum 物料数量 |
| | | * @param batchNum 批次号 |
| | | * @param upLevelStartDate 上级工序的开始日期 |
| | | * @param plan 计划对象 |
| | | * @param allRequires 所有需求的列表 |
| | | * @param level 层级 |
| | | */ |
| | | private void getBomRequires(String plant, String bomLineId,String itemCode,BigDecimal itemNum, String batchNum, Date upLevelStartDate, ApsPlatePlan plan, List<ApsPlateStandardRequire> allRequires, Long level) { |
| | | /*构建需求信息*/ |
| | | ApsPlateStandardRequire require = new ApsPlateStandardRequire(); |
| | | require.setId(IdUtil.getSnowflakeNextId()); |
| | |
| | | require.setBatchNumber(batchNum); |
| | | require.setDocNum(plan.getDocumentNumber()); |
| | | require.setOrgCode(plant); |
| | | require.setBomLineCode(itemNumber); |
| | | require.setBomLineId(bomLineId); |
| | | require.setBomLineCode(itemCode); |
| | | require.setBomLineLevel(level); |
| | | require.setBomUseAmount(bomLine.getNum()); |
| | | require.setBomUseAmount(itemNum); |
| | | require.setCreateTime(DateUtils.getNowDate()); |
| | | require.setCreateBy(SecurityUtils.getUsername()); |
| | | require.setDelFlag("0"); |
| | | require.setProductionBase(plan.getProductionBase()); |
| | | /*计算需求数量*/ |
| | | if (level == 0) { |
| | | require.setBomUseAmount(BigDecimal.ONE); |
| | | require.setCompleteDate(plan.getPlanEndDay()); |
| | | require.setDemandDate(plan.getPlanEndDay()); |
| | | } else { |
| | | require.setBomUseAmount(bomLine.getNum().multiply(plan.getProductionQuantity())); |
| | | require.setBomUseAmount(itemNum.multiply(plan.getProductionQuantity())); |
| | | } |
| | | /*查找库存,计算净需求,保存剩余库存,保存库存扣减明细*/ |
| | | BigDecimal remainderStock = BigDecimal.ZERO; |
| | | /*默认净需求为BOM用量*/ |
| | | require.setNetRequirement(require.getBomUseAmount()); |
| | | Optional<ApsMaterialStorageManagement> itemStorage = getItemStorage(plant, itemNumber); |
| | | Optional<ApsMaterialStorageManagement> itemStorage = getItemStorage(plant, itemCode); |
| | | if (itemStorage.isPresent()) { |
| | | ApsMaterialStorageManagement storage = itemStorage.get(); |
| | | /*剩余库存*/ |
| | |
| | | afterStockAmount = remainderStock.subtract(deductionAmount); |
| | | require.setNetRequirement(BigDecimal.ZERO); |
| | | } |
| | | bomStockDetailService.saveStorageAndDetail(storage, plan, bomLine, batchNum, deductionAmount, afterStockAmount,require.getId()); |
| | | /*记录库存剩余数量,记录库存使用记录*/ |
| | | bomStockDetailService.saveStorageAndDetail(storage, plan, bomLineId,itemCode, batchNum, deductionAmount, afterStockAmount,require.getId()); |
| | | } |
| | | } |
| | | |
| | | /*工艺路线总需求*/ |
| | | ApsStandardProcessRouteLine routeHeader = routeLineService.getRouteLineTotalTime(require); |
| | | String routeId = routeHeader.getRouteId(); |
| | |
| | | allRequires.add(require); |
| | | if (require.getNetRequirement().compareTo(BigDecimal.ZERO) > 0) { |
| | | /*当前Bom节点处理完成后,处理下级BOM*/ |
| | | List<ApsBom> bomLineList = bomLineService.selectApsBomLineList(plant, itemNumber); |
| | | long nextLevel=level+1; |
| | | List<ApsBom> bomLineList = bomLineService.selectApsBomLineList(plant, itemCode); |
| | | if (!bomLineList.isEmpty()) { |
| | | bomLineList.forEach(line -> { |
| | | getBomRequires(plant, line, batchNum, require.getStartDate(), plan, allRequires, level + 1); |
| | | getBomRequires(plant, line.getBomLineId(),line.getItemCode() ,line.getNum() , batchNum, require.getStartDate(), plan, allRequires, nextLevel); |
| | | }); |
| | | } |
| | | } |
| | |
| | | <result property="orderCreateTime" column="order_create_time" /> |
| | | <result property="professionalAffiliation" column="professional_affiliation" /> |
| | | <result property="requireId" column="require_id" /> |
| | | <result property="version" column="version" /> |
| | | </resultMap> |
| | | |
| | | <sql id="selectApsPlatePlanVo"> |
| | |
| | | work_center, department, plan_start_day, plan_end_day, standby_number, standby_name, |
| | | standby_stock, next_process_deparment, is_suspended, is_outsourcing, account, advanced_materials, |
| | | advanced_document_number, advanced_requirement_day, is_plan_complete, is_stock_complete, |
| | | has_turnback, has_risk, std_op, op_status, next_op_name ,unmatched_quantity,professional_affiliation |
| | | , production_base, order_create_time |
| | | has_turnback, has_risk, std_op, op_status, next_op_name ,unmatched_quantity,professional_affiliation, |
| | | require_id, version,production_base, order_create_time |
| | | from aps_plate_plan |
| | | </sql> |
| | | |
| | |
| | | </update> |
| | | |
| | | <select id="selectPlatePlanByPlantMajor" parameterType="ApsPlatePlan" resultMap="ApsPlatePlanResult"> |
| | | select id,document_number,plan_end_day, main_part_number,item_number,plant,professional_affiliation,production_quantity,require_id |
| | | from aps_plate_plan |
| | | select id,document_number,main_part_number,item_number,plant,professional_affiliation,production_quantity,require_id, |
| | | unmatched_quantity,version, production_base |
| | | (case when custom_time is null then plan_end_day else custom_time end ) as plan_end_day |
| | | <where> |
| | | <if test="plant != null "> and plant = #{plant}</if> |
| | | <if test="professionalAffiliation != null "> and professional_affiliation = #{professionalAffiliation}</if> |
| | |
| | | |
| | | <select id="selectUnMatchPlateSubPlan" parameterType="ApsPlatePlan" resultMap="ApsPlatePlanResult"> |
| | | select id,document_number,main_part_number,item_number,plant,professional_affiliation,production_quantity, |
| | | unmatched_quantity |
| | | unmatched_quantity,version |
| | | from aps_plate_plan |
| | | where del_flag='0' and professional_affiliation !='0' and unmatched_quantity > 0 |
| | | <if test="plant != null and plan !='' "> and plant = #{plant}</if> |
| | |
| | | |
| | | <update id="initUnMatchQty" > |
| | | update aps_plate_plan |
| | | set unmatched_quantity=production_quantity, version=0 |
| | | set unmatched_quantity=production_quantity, version=0,require_id=id |
| | | where del_flag='0' and professional_affiliation !='0' |
| | | </update> |
| | | </mapper> |