소스 검색

装运明细移除功能开发

qiangxuan 1 개월 전
부모
커밋
8fb11b35ec

+ 280 - 1
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/controller/StorageBillController.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -30,17 +32,27 @@ import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsendDetailsVo;
 import org.jeecg.modules.billet.billetHotsend.service.IBilletHotsendBaseService;
 import org.jeecg.modules.billet.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
 import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
+import org.jeecg.modules.billet.billetHotsendConfig.entity.BilletHotsendTypeConfig;
+import org.jeecg.modules.billet.billetHotsendConfig.service.IBilletHotsendTypeConfigService;
 import org.jeecg.modules.billet.operateLog.service.IOperateLogService;
 import org.jeecg.modules.billet.rollClubOne.entity.RollClubOneDetails;
 import org.jeecg.modules.billet.rollClubOne.service.IRollClubOneDetailsService;
+import org.jeecg.modules.billet.rollClubThree.entity.RollClubThree;
 import org.jeecg.modules.billet.rollClubThree.entity.RollClubThreeDetails;
 import org.jeecg.modules.billet.rollClubThree.service.IRollClubThreeDetailsService;
+import org.jeecg.modules.billet.rollClubThree.service.IRollClubThreeService;
+import org.jeecg.modules.billet.rollClubTwo.entity.RollClubTwo;
 import org.jeecg.modules.billet.rollClubTwo.entity.RollClubTwoDetails;
 import org.jeecg.modules.billet.rollClubTwo.service.IRollClubTwoDetailsService;
+import org.jeecg.modules.billet.rollClubTwo.service.IRollClubTwoService;
 import org.jeecg.modules.billet.rollHeight.entity.RollHeightDetails;
 import org.jeecg.modules.billet.rollHeight.service.IRollHeightDetailsService;
+import org.jeecg.modules.billet.rollOutShipp.entity.RollOutShipp;
 import org.jeecg.modules.billet.rollOutShipp.entity.RollOutShippDetails;
 import org.jeecg.modules.billet.rollOutShipp.service.IRollOutShippDetailsService;
+import org.jeecg.modules.billet.rollOutShipp.service.IRollOutShippService;
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.entity.StackingAndLoadingVehicles;
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.service.IStackingAndLoadingVehiclesService;
 import org.jeecg.modules.billet.storageBill.dto.HotChargingQueryDTO;
 import org.jeecg.modules.billet.storageBill.dto.StorageCenterQueryDTO;
 import org.jeecg.modules.billet.storageBill.entity.*;
@@ -52,6 +64,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.servlet.ModelAndView;
 
@@ -116,6 +129,20 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
 	@Autowired
 	private IBilletBasicInfoService billetBasicInfoService;
 
+	@Autowired
+	private IRollClubTwoService rollClubTwoService;
+
+	@Autowired
+	private IRollClubThreeService rollClubThreeService;
+
+	@Autowired
+	private IRollOutShippService rollOutShippService;
+
+	@Autowired
+	private IBilletHotsendTypeConfigService billetHotsendTypeConfigService;
+
+	@Autowired
+	private IStackingAndLoadingVehiclesService stackingAndLoadingVehiclesService;
 	/**
 	 * 分页列表查询
 	 *
@@ -500,7 +527,259 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
 		storageBillService.removeById(storageBill.getId());
 		return Result.OK("删除成功!");
 	}
-	
+
+	/**
+	 *   通过组批号移除
+	 *
+	 * @param storageBillVo
+	 * @return
+	 */
+	@AutoLog(value = "钢坯装运单-通过组批号移除")
+	@ApiOperation(value="钢坯装运单-通过组批号移除", notes="钢坯装运单-通过组批号移除")
+	@DeleteMapping(value = "/deleteByAssemblyNumber")
+	@Transactional(rollbackFor = Exception.class)
+	public Result<String> deleteByAssemblyNumber(@RequestBody StorageBillVo storageBillVo) {
+
+		// 根据id查询钢坯装运单信息
+		StorageBill storageBill = storageBillService.getById(storageBillVo.getId());
+		if (storageBill == null){
+			return Result.error("钢坯装运单信息为空,移除装运明细失败!");
+		}
+		//已发车的钢坯不能移除
+		if (oConvertUtils.isNotEmpty(storageBill.getOutTime())){
+			return Result.error("该钢坯装运单已发车,移除装运明细失败!");
+		}
+		if ("1024".equals(storageBill.getTypeConfigId())){
+			return Result.error("未选择目的地,无法移除装运明细!");
+		}
+
+		try {
+			List<String> billetNos = Arrays.asList(storageBillVo.getBillNos().split(","));
+			//查询并批量更新钢坯基础信息 belongTable
+			LambdaQueryWrapper<BilletBasicInfo> queryWrapperls = new LambdaQueryWrapper<BilletBasicInfo>()
+					.eq(BilletBasicInfo::getCcmNo, Integer.valueOf(storageBillVo.getCcmNo()))
+					.in(BilletBasicInfo::getBilletNo, billetNos);
+			List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(queryWrapperls);
+			if (oConvertUtils.listIsEmpty(billetBasicInfoList)){
+				return Result.error("钢坯基础信息不存在,移除装运明细失败!");
+			}
+
+			String finalHeatNo = billetBasicInfoList.get(0).getHeatNo();
+			Double sumBlankOutput;
+			int sumAmountTotal = billetBasicInfoList.size();
+			if ("棒二".equals(storageBillVo.getDestination())) {
+				List<RollClubTwoDetails> rollClubTwoDetailsList = rollClubTwoDetailsService.list(new LambdaQueryWrapper<RollClubTwoDetails>()
+						.eq(RollClubTwoDetails::getStorageBillId, storageBillVo.getId())
+						.eq(RollClubTwoDetails::getCcmNo, storageBillVo.getCcmNo())
+						.eq(RollClubTwoDetails::getAssemblyNumber, storageBillVo.getAssemblyNumber()));
+				sumBlankOutput = rollClubTwoDetailsList.stream().mapToDouble(RollClubTwoDetails::getBlankOutput).sum();
+				if (oConvertUtils.listIsNotEmpty(rollClubTwoDetailsList)){
+					rollClubTwoDetailsService.removeByIds(rollClubTwoDetailsList.stream().map(RollClubTwoDetails::getId).collect(Collectors.toList()));
+				}
+				LambdaQueryWrapper<RollClubTwo> queryWrapper = new LambdaQueryWrapper<RollClubTwo>()
+						.eq(RollClubTwo::getCcmNo, storageBillVo.getCcmNo())
+						.eq(RollClubTwo::getHeatNo, finalHeatNo)
+						.eq(RollClubTwo::getShiftGroup, storageBillVo.getShiftGroup())
+						.eq(RollClubTwo::getShift, storageBillVo.getShift())
+						.eq(RollClubTwo::getStorageBillId, storageBillVo.getId())
+						.last("limit 1");
+				RollClubTwo rollClubTwo = rollClubTwoService.getOne(queryWrapper);
+				if (oConvertUtils.isNotEmpty(rollClubTwo)){
+					rollClubTwo.setAmountTotal(Math.max(0, rollClubTwo.getAmountTotal() - sumAmountTotal));
+					rollClubTwo.setBlankOutput(Math.max(0, rollClubTwo.getBlankOutput() - sumBlankOutput));
+					rollClubTwoService.updateById(rollClubTwo);
+				}
+			}else if ("棒三".equals(storageBillVo.getDestination())) {
+				List<RollClubThreeDetails> rollClubThreeDetailsList = rollClubThreeDetailsService.list(new LambdaQueryWrapper<RollClubThreeDetails>()
+						.eq(RollClubThreeDetails::getStorageBillId, storageBillVo.getId())
+						.eq(RollClubThreeDetails::getCcmNo, storageBillVo.getCcmNo())
+						.eq(RollClubThreeDetails::getAssemblyNumber, storageBillVo.getAssemblyNumber()));
+				sumBlankOutput = rollClubThreeDetailsList.stream().mapToDouble(RollClubThreeDetails::getBlankOutput).sum();
+				if (oConvertUtils.listIsNotEmpty(rollClubThreeDetailsList)){
+					rollClubThreeDetailsService.removeByIds(rollClubThreeDetailsList.stream().map(RollClubThreeDetails::getId).collect(Collectors.toList()));
+				}
+				LambdaQueryWrapper<RollClubThree> queryWrapper = new LambdaQueryWrapper<RollClubThree>()
+						.eq(RollClubThree::getCcmNo, storageBillVo.getCcmNo())
+						.eq(RollClubThree::getHeatNo, finalHeatNo)
+						.eq(RollClubThree::getShiftGroup, storageBillVo.getShiftGroup())
+						.eq(RollClubThree::getShift, storageBillVo.getShift())
+						.eq(RollClubThree::getStorageBillId, storageBillVo.getId())
+						.last("limit 1");
+				RollClubThree rollClubThree = rollClubThreeService.getOne(queryWrapper);
+				if (oConvertUtils.isNotEmpty(rollClubThree)){
+					rollClubThree.setAmountTotal(Math.max(0, rollClubThree.getAmountTotal() - sumAmountTotal));
+					rollClubThree.setBlankOutput(Math.max(0, rollClubThree.getBlankOutput() - sumBlankOutput));
+					rollClubThreeService.updateById(rollClubThree);
+				}
+			}else if ("上若".equals(storageBillVo.getDestination())) {
+				List<RollOutShippDetails> rollOutShippDetailsList = rollOutShippDetailsService.list(new LambdaQueryWrapper<RollOutShippDetails>()
+						.eq(RollOutShippDetails::getStorageBillId, storageBillVo.getId())
+						.eq(RollOutShippDetails::getCcmNo, storageBillVo.getCcmNo())
+						.eq(RollOutShippDetails::getAssemblyNumber, storageBillVo.getAssemblyNumber()));
+				sumBlankOutput = rollOutShippDetailsList.stream().mapToDouble(RollOutShippDetails::getBlankOutput).sum();
+				if (oConvertUtils.listIsNotEmpty(rollOutShippDetailsList)){
+					rollOutShippDetailsService.removeByIds(rollOutShippDetailsList.stream().map(RollOutShippDetails::getId).collect(Collectors.toList()));
+				}
+				LambdaQueryWrapper<RollOutShipp> queryWrapper = new LambdaQueryWrapper<RollOutShipp>()
+						.eq(RollOutShipp::getCcmNo, storageBillVo.getCcmNo())
+						.eq(RollOutShipp::getHeatNo, finalHeatNo)
+						.eq(RollOutShipp::getShiftGroup, storageBillVo.getShiftGroup())
+						.eq(RollOutShipp::getShift, storageBillVo.getShift())
+						.eq(RollOutShipp::getStorageBillId, storageBillVo.getId())
+						.last("limit 1");
+				RollOutShipp rollOutShipp = rollOutShippService.getOne(queryWrapper);
+				if (oConvertUtils.isNotEmpty(rollOutShipp)){
+					rollOutShipp.setAmountTotal(Math.max(0, rollOutShipp.getAmountTotal() - sumAmountTotal));
+					rollOutShipp.setBlankOutput(Math.max(0, rollOutShipp.getBlankOutput() - sumBlankOutput));
+					rollOutShippService.updateById(rollOutShipp);
+				}
+			}
+			BilletHotsendTypeConfig billetHotsendTypeConfig = new BilletHotsendTypeConfig();
+			if (oConvertUtils.isNotEmpty(storageBillVo.getStackAddr())){
+				LambdaQueryWrapper<BilletHotsendTypeConfig> queryWrapper = new LambdaQueryWrapper<BilletHotsendTypeConfig>()
+						.eq(BilletHotsendTypeConfig::getTypeName, storageBillVo.getStackAddr())
+						.eq(BilletHotsendTypeConfig::getCastMachine, storageBillVo.getCcmNo());
+				billetHotsendTypeConfig = billetHotsendTypeConfigService.getOne(queryWrapper);
+				if (oConvertUtils.isEmpty(billetHotsendTypeConfig)){
+					TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+					return Result.error("钢坯配置信息为空,移除失败!");
+				}
+
+				List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList = new ArrayList<>();
+				StackingAndLoadingVehicles stackingAndLoadingVehiclesInfo = new StackingAndLoadingVehicles();
+				stackingAndLoadingVehiclesInfo.setCcmNo(storageBillVo.getCcmNo());
+				stackingAndLoadingVehiclesInfo.setTypeConfigId(billetHotsendTypeConfig.getId());
+				stackingAndLoadingVehiclesInfo.setStackAddr(billetHotsendTypeConfig.getTypeName());
+				stackingAndLoadingVehiclesInfo.setBilletNos(storageBillVo.getBillNos());
+				stackingAndLoadingVehiclesInfo.setLayer(storageBillVo.getStackStorey());
+				stackingAndLoadingVehiclesInfo.setAddress(storageBillVo.getStackNum());
+				stackingAndLoadingVehiclesList.add(stackingAndLoadingVehiclesInfo);
+
+				StackingAndLoadingVehicles stackingAndLoadingVehiclesPositionInfo = stackingAndLoadingVehiclesService.getOne(new LambdaQueryWrapper<StackingAndLoadingVehicles>()
+						.eq(StackingAndLoadingVehicles::getTypeConfigId, billetHotsendTypeConfig.getId())
+						.eq(StackingAndLoadingVehicles::getLayer, storageBillVo.getStackStorey())
+						.eq(StackingAndLoadingVehicles::getAddress, storageBillVo.getStackNum())
+						.eq(StackingAndLoadingVehicles::getCcmNo, storageBillVo.getCcmNo())
+				);
+				if (oConvertUtils.isNotEmpty(stackingAndLoadingVehiclesPositionInfo) && oConvertUtils.isNotEmpty(stackingAndLoadingVehiclesPositionInfo.getBilletNos())){
+					TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+					return Result.error("该层该位置已存在数据,装运明细移除失败!");
+				}
+
+				// 2 发车后,动态更新容器中的垛位信息 初始化
+				BilletHotsendTypeConfig finalBilletHotsendTypeConfig = billetHotsendTypeConfig;
+				stackingAndLoadingVehiclesList.forEach(x ->{
+					LambdaUpdateWrapper<StackingAndLoadingVehicles> queryWrapperSA = new LambdaUpdateWrapper<>();
+					queryWrapperSA.eq(StackingAndLoadingVehicles::getCcmNo, x.getCcmNo())
+							.eq(StackingAndLoadingVehicles::getLayer, x.getLayer())
+							.eq(StackingAndLoadingVehicles::getAddress, x.getAddress())
+							.eq(StackingAndLoadingVehicles::getTypeConfigId, finalBilletHotsendTypeConfig.getId());
+					StackingAndLoadingVehicles stackingAndLoadingVehicles = createInitializedVehicle();
+					BeanUtils.copyProperties(x, stackingAndLoadingVehicles);
+					BilletBasicInfo billetBasicInfo = billetBasicInfoList.stream().findFirst().orElse(null);
+					stackingAndLoadingVehicles.setShift(billetBasicInfo.getShift());
+					stackingAndLoadingVehicles.setShiftGroup(billetBasicInfo.getShiftGroup());
+					stackingAndLoadingVehicles.setCcmNo(billetBasicInfo.getCcmNo().toString());
+					stackingAndLoadingVehicles.setHeatNo(billetBasicInfo.getHeatNo());
+					stackingAndLoadingVehicles.setSize(billetBasicInfo.getLength().toString());
+					stackingAndLoadingVehicles.setSpec(billetBasicInfo.getSpec());
+					stackingAndLoadingVehicles.setSteel(billetBasicInfo.getGrade());
+					stackingAndLoadingVehicles.setCreateDate(new Date());
+					log.info("{}{}", "装运单移除钢坯,起跺容器中的信息:", JSON.toJSON(stackingAndLoadingVehicles));
+					stackingAndLoadingVehiclesService.update(stackingAndLoadingVehicles, queryWrapperSA);
+				});
+			}
+			LambdaQueryWrapper<BilletHotsend> queryWrapperBH = new LambdaQueryWrapper<BilletHotsend>()
+					.eq(BilletHotsend::getCcmNo, storageBillVo.getCcmNo())
+					.eq(BilletHotsend::getHeatNo, finalHeatNo)
+					.eq(BilletHotsend::getShiftGroup, storageBillVo.getShiftGroup())
+					.eq(BilletHotsend::getShift, storageBillVo.getShift())
+					.last("limit 1");
+			BilletHotsend billetHotsend = billetHotsendBaseService.getOne(queryWrapperBH);
+			if (oConvertUtils.isEmpty(billetHotsend)) {
+				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+				return Result.error("热送传递单不存在,移除失败!");
+			}
+			updateClubNum(billetHotsend, storageBillVo.getDestination(), sumAmountTotal);
+			if (oConvertUtils.isNotEmpty(storageBillVo.getStackAddr())) {
+				billetHotsend.setStackNum(billetHotsend.getStackNum() + sumAmountTotal);
+			}
+			billetHotsendBaseService.updateById(billetHotsend);
+
+			for (BilletBasicInfo billetBasicInfo : billetBasicInfoList) {
+				LambdaUpdateWrapper<BilletBasicInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
+				lambdaUpdateWrapper.eq(BilletBasicInfo::getId, billetBasicInfo.getId());
+				if (oConvertUtils.isNotEmpty(storageBillVo.getStackAddr())) {
+					lambdaUpdateWrapper.set(BilletBasicInfo::getBelongTable, "stacking_and_loading_vehicles");
+					lambdaUpdateWrapper.set(BilletBasicInfo::getBhtcId, billetHotsendTypeConfig.getId());
+				} else {
+					lambdaUpdateWrapper.set(BilletBasicInfo::getBelongTable, null);
+					lambdaUpdateWrapper.set(BilletBasicInfo::getBhtcId, null);
+				}
+				billetBasicInfoService.update(lambdaUpdateWrapper);
+			}
+
+			storageBill.setAmountTotal(Math.max(0, storageBill.getAmountTotal() - sumAmountTotal));
+			String assemblyNumber = storageBill.getAssemblyNumber();
+			String targetNumber = storageBillVo.getAssemblyNumber();
+			String newAssemblyNumber = Arrays.stream(assemblyNumber.split(","))
+					.filter(number -> !number.equals(targetNumber))
+					.collect(Collectors.joining(","));
+			LambdaUpdateWrapper<StorageBill> updateWrapper = new LambdaUpdateWrapper<>();
+			updateWrapper.eq(StorageBill::getId, storageBill.getId());
+			updateWrapper.set(StorageBill::getAmountTotal, storageBill.getAmountTotal());
+
+			if (oConvertUtils.isEmpty(newAssemblyNumber)) {
+				updateWrapper.set(StorageBill::getAssemblyNumber, null);
+			} else {
+				updateWrapper.set(StorageBill::getAssemblyNumber, newAssemblyNumber);
+			}
+			storageBillService.update(updateWrapper);
+		} catch (Exception e) {
+			log.error("装运明细移除发生异常:" + e.getMessage(), e);
+			return Result.error("装运明细移除异常!");
+		}
+		log.info("{}{}", ">>>>>>装运单移除成功的钢坯信息:", JSON.toJSON(storageBillVo));
+		return Result.OK("装运明细移除成功!");
+	}
+
+	/**
+	 * 炉次传递单棒二、棒三、上若总支数计算
+	 * @param billetHotsend
+	 * @param destination
+	 * @param sumAmountTotal
+	 */
+	private void updateClubNum(BilletHotsend billetHotsend, String destination, int sumAmountTotal) {
+		switch (destination) {
+			case "棒二":
+				billetHotsend.setRollclubtwoNum(Math.max(0, billetHotsend.getRollclubtwoNum() - sumAmountTotal));
+				break;
+			case "棒三":
+				billetHotsend.setRollclubthreeNum(Math.max(0, billetHotsend.getRollclubthreeNum() - sumAmountTotal));
+				break;
+			case "上若":
+				billetHotsend.setRolloutshippNum(Math.max(0, billetHotsend.getRolloutshippNum() - sumAmountTotal));
+				break;
+		}
+	}
+
+	/**
+	 * 初始化StackingAndLoadingVehicles对象
+	 * @return
+	 */
+	private StackingAndLoadingVehicles createInitializedVehicle() {
+		StackingAndLoadingVehicles vehicle = new StackingAndLoadingVehicles();
+		vehicle.setBilletNos(null);
+		vehicle.setSpec(null);
+		vehicle.setSteel(null);
+		vehicle.setSize(null);
+		vehicle.setShift(null);
+		vehicle.setHeatNo(null);
+		vehicle.setShiftGroup(null);
+		vehicle.setCreateDate(null);
+		return vehicle;
+	}
+
 	/**
 	 *  批量删除
 	 *

+ 19 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/entity/StorageBillVo.java

@@ -0,0 +1,19 @@
+package org.jeecg.modules.billet.storageBill.entity;
+
+import lombok.Data;
+
+@Data
+public class StorageBillVo {
+    private String id;
+    private String ccmNo;
+    private String heatNo;
+    private String billNos;
+    private String shiftGroup;
+    private String shift;
+    private String assemblyNumber;
+    private String typeConfigId;
+    private String destination;
+    private String stackStorey;
+    private String stackNum;
+    private String stackAddr;
+}