|
@@ -1,7 +1,11 @@
|
|
|
package org.jeecg.modules.billet.billetHotsendAbandons.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+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.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -11,17 +15,33 @@ import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletBasicInfo;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetActual.service.IBilletBasicInfoService;
|
|
|
+import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsend;
|
|
|
+import org.jeecg.modules.billet.billetHotsend.service.IBilletHotsendBaseService;
|
|
|
import org.jeecg.modules.billet.billetHotsendAbandons.entity.BilletHotsendAbandons;
|
|
|
import org.jeecg.modules.billet.billetHotsendAbandons.service.IBilletHotsendAbandonsService;
|
|
|
+import org.jeecg.modules.billet.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
|
|
|
+import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
|
|
|
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.entity.StackingAndLoadingVehicles;
|
|
|
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.service.IStackingAndLoadingVehiclesService;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.BeansException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.util.Arrays;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
- /**
|
|
|
+/**
|
|
|
* @Description: 钢坯热送单炉支数传递单判废记录
|
|
|
* @Author: jeecg-boot
|
|
|
* @Date: 2024-11-19
|
|
@@ -32,9 +52,21 @@ import java.util.Arrays;
|
|
|
@RequestMapping("/billetHotsend/billetHotsendAbandons")
|
|
|
@Slf4j
|
|
|
public class BilletHotsendAbandonsController extends JeecgController<BilletHotsendAbandons, IBilletHotsendAbandonsService> {
|
|
|
+
|
|
|
@Autowired
|
|
|
private IBilletHotsendAbandonsService billetHotsendAbandonsService;
|
|
|
-
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBilletHotsendBaseService billetHotsendBaseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBilletBasicInfoService billetBasicInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IStackingAndLoadingVehiclesService stackingAndLoadingVehiclesService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBilletHotsendChangeShiftService billetHotsendChangeShiftService;
|
|
|
/**
|
|
|
* 分页列表查询
|
|
|
*
|
|
@@ -159,4 +191,123 @@ public class BilletHotsendAbandonsController extends JeecgController<BilletHotse
|
|
|
return super.importExcel(request, response, BilletHotsendAbandons.class);
|
|
|
}
|
|
|
|
|
|
+ @AutoLog(value = "钢坯实绩判废-批量判废")
|
|
|
+ @ApiOperation(value="钢坯实绩判废-批量判废", notes="钢坯实绩判废-批量判废")
|
|
|
+ @DeleteMapping(value = "/abandonsBatch")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Result<String> abandonsBatchHandle(@RequestParam(name="ids",required=true) String ids) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ //根据逗号拼接的ids、BelongTable等于stacking_and_loading_vehicles或者为null 的所有钢坯基础信息
|
|
|
+ LambdaQueryWrapper<BilletBasicInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(BilletBasicInfo::getId, Arrays.asList(ids.split(",")));
|
|
|
+ List<BilletBasicInfo> billetBasicInfos = billetBasicInfoService.list(queryWrapper);
|
|
|
+ if (oConvertUtils.listIsEmpty(billetBasicInfos)){
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新钢坯实绩为叛废记录,belongTable = "billet_hotsend_abandons", bhtcId = "1025"
|
|
|
+ List<BilletBasicInfo> billetBasicInfoLists = new ArrayList<>();
|
|
|
+ for (BilletBasicInfo billetBasicInfo : billetBasicInfos) {
|
|
|
+ billetBasicInfo.setBelongTable("billet_hotsend_abandons");
|
|
|
+ billetBasicInfo.setBhtcId("1025");
|
|
|
+ billetBasicInfoLists.add(billetBasicInfo);
|
|
|
+ }
|
|
|
+ billetBasicInfoService.updateBatchById(billetBasicInfoLists);
|
|
|
+
|
|
|
+ // 对 billetBasicInfos 根据炉号、班组、班别进行分组,
|
|
|
+ Map<String, List<BilletBasicInfo>> groupedMap = billetBasicInfos.stream()
|
|
|
+ .collect(Collectors.groupingBy(info -> info.getHeatNo() + "-" + info.getShiftGroup() + "-" + info.getShift()));
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<BilletBasicInfo>> entry : groupedMap.entrySet()) {
|
|
|
+ List<BilletBasicInfo> group = entry.getValue();
|
|
|
+ if (oConvertUtils.listIsNotEmpty(group)) {
|
|
|
+
|
|
|
+ // 计算 group 中 billetWeight 总重量,保留 4 位小数
|
|
|
+ double totalWeight = group.stream()
|
|
|
+ .mapToDouble(BilletBasicInfo::getBilletWeight)
|
|
|
+ .sum();
|
|
|
+ BigDecimal totalWeightBigDecimal = new BigDecimal(totalWeight).setScale(4, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ BilletBasicInfo firstInfo = group.get(0);
|
|
|
+ String heatNo = firstInfo.getHeatNo();
|
|
|
+ String shiftGroup = firstInfo.getShiftGroup();
|
|
|
+ String shift = firstInfo.getShift();
|
|
|
+ String ccmNo = String.valueOf(firstInfo.getCcmNo());
|
|
|
+ // 根据炉号、班组、班别、铸机号 查询该钢坯热送传递单,返回一个对象
|
|
|
+ LambdaQueryWrapper<BilletHotsend> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(BilletHotsend::getHeatNo, heatNo)
|
|
|
+ .eq(BilletHotsend::getShiftGroup, shiftGroup)
|
|
|
+ .eq(BilletHotsend::getShift, shift)
|
|
|
+ .eq(BilletHotsend::getCcmNo, ccmNo);
|
|
|
+ BilletHotsend billetHotsend = billetHotsendBaseService.getOne(lambdaQueryWrapper, false);
|
|
|
+ if (billetHotsend == null){
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return Result.error("钢坯炉次传递单查询失败,叛废失败!");
|
|
|
+ }
|
|
|
+ // 更新BilletHotsend中的wasteNum字段,并更新BilletHotsend对象
|
|
|
+ billetHotsend.setWasteNum(billetHotsend.getWasteNum() + group.size());
|
|
|
+ billetHotsend.setWasteBlankOutput(billetHotsend.getWasteBlankOutput() + totalWeightBigDecimal.doubleValue());
|
|
|
+ billetHotsendBaseService.updateById(billetHotsend);
|
|
|
+
|
|
|
+ // 更新交班记录
|
|
|
+ LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapperBilletHotsendChangeShift = new LambdaQueryWrapper<BilletHotsendChangeShift>()
|
|
|
+ .eq(BilletHotsendChangeShift::getCcmNo, ccmNo)
|
|
|
+ .eq(BilletHotsendChangeShift::getShift, shift)
|
|
|
+ .eq(BilletHotsendChangeShift::getShiftGroup, shiftGroup)
|
|
|
+ .isNull(BilletHotsendChangeShift::getChangeShiftTime)
|
|
|
+ .orderByDesc(BilletHotsendChangeShift::getCreateTime).last("limit 1");
|
|
|
+ BilletHotsendChangeShift billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(queryWrapperBilletHotsendChangeShift, false);
|
|
|
+ if (billetHotsendChangeShift == null){
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return Result.error("交班记录查询失败,叛废失败!");
|
|
|
+ }
|
|
|
+ // 减掉总重量
|
|
|
+ billetHotsendChangeShift.setShiftProduct(Math.max(billetHotsendChangeShift.getShiftProduct() - totalWeightBigDecimal.doubleValue(), 0));
|
|
|
+ billetHotsendChangeShift.setShiftSum(Math.max(billetHotsendChangeShift.getShiftSum() - group.size(), 0));
|
|
|
+ billetHotsendChangeShift.setWasteAmount(billetHotsendChangeShift.getWasteAmount() + group.size());
|
|
|
+ billetHotsendChangeShiftService.updateById(billetHotsendChangeShift);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据billetBasicInfos遍历 保存叛废记录
|
|
|
+ List<BilletHotsendAbandons> billetHotsendAbandonsList = new ArrayList<>();
|
|
|
+ for (BilletBasicInfo billetBasicInfo : billetBasicInfos) {
|
|
|
+ BilletHotsendAbandons billetHotsendAbandons = new BilletHotsendAbandons();
|
|
|
+ BeanUtils.copyProperties(billetBasicInfo, billetHotsendAbandons);
|
|
|
+ billetHotsendAbandons.setId(String.valueOf(IdWorker.getId()));
|
|
|
+ billetHotsendAbandons.setCcmNo(String.valueOf(billetBasicInfo.getCcmNo()));
|
|
|
+ billetHotsendAbandons.setSize(String.valueOf(billetBasicInfo.getLength()));
|
|
|
+ billetHotsendAbandonsList.add(billetHotsendAbandons);
|
|
|
+ }
|
|
|
+ billetHotsendAbandonsService.saveBatch(billetHotsendAbandonsList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("{}{}", "批量判废异常:", e.getMessage());
|
|
|
+ }
|
|
|
+ return Result.OK("批量判废成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化堆垛公共容器
|
|
|
+ * @param stackingAndLoadingVehiclesList
|
|
|
+ */
|
|
|
+ private void batchUpdateStackingAndLoadingVehicles(List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList) {
|
|
|
+
|
|
|
+ List<String> ids = stackingAndLoadingVehiclesList.stream().map(StackingAndLoadingVehicles::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 创建更新包装器
|
|
|
+ LambdaUpdateWrapper<StackingAndLoadingVehicles> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.in(StackingAndLoadingVehicles::getId, ids)
|
|
|
+ .set(StackingAndLoadingVehicles::getBilletNos, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getSpec, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getSteel, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getSize, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getShift, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getHeatNo, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getCreateDate, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getShiftGroup, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getUpdateTime, new Date());
|
|
|
+ // 执行批量更新
|
|
|
+ stackingAndLoadingVehiclesService.update(null, updateWrapper);
|
|
|
+ }
|
|
|
}
|