Browse Source

推送数据到钢坯数据处理接口以及修改送样卡表同步更新一下质检表

lingpeng.li 3 days ago
parent
commit
1b38b3ffcf

+ 88 - 3
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/controller/BilletOriginalProductRecordController.java

@@ -36,9 +36,7 @@ import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsend;
 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.billetOriginalProductRecord.dto.BilletOriginalProductRecordEditDTO;
-import org.jeecg.modules.billet.billetOriginalProductRecord.dto.LengthCountQueryDTO;
-import org.jeecg.modules.billet.billetOriginalProductRecord.dto.QualityInspectionQueryDTO;
+import org.jeecg.modules.billet.billetOriginalProductRecord.dto.*;
 import org.jeecg.modules.billet.billetOriginalProductRecord.entity.BilletOriginalProductRecord;
 import org.jeecg.modules.billet.billetOriginalProductRecord.entity.BilletOriginalProductRecordDl;
 import org.jeecg.modules.billet.billetOriginalProductRecord.entity.BilletOriginalProductRecordYyf;
@@ -1238,6 +1236,93 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
 	}
 
 
+	/**
+	 *  编辑出坯量以及推送钢坯处理数据
+	 *
+	 * @param editDTO
+	 * @return
+	 */
+	@AutoLog(value = "编辑出坯量以及推送钢坯处理数据")
+	@ApiOperation(value = "编辑出坯量以及推送钢坯处理数据", notes = "编辑出坯量以及推送钢坯处理数据")
+	@PutMapping(value = "/editBlankOutput")
+	public Result<String> editBlankOutput(@RequestBody BlankOutputEditDTO editDTO) {
+
+		// 1. 基本参数校验
+		if (editDTO.getHeatNo() == null || editDTO.getHeatNo().trim().isEmpty()) {
+			return Result.error("炉号不能为空");
+		}
+
+		if (editDTO.getBlankOutput() == null) {
+			return Result.error("出坯量不能为空");
+		}
+
+		// 2. 获取铸机号并设置默认值
+		String ccmNo = (editDTO.getCcmNo() == null || editDTO.getCcmNo().trim().isEmpty()) ? "5" : editDTO.getCcmNo();
+
+		String classShift = String.format("class:shift:%s", ccmNo);
+		String classShiftGroup = String.format("class:shift:group:%s", ccmNo);
+
+		String shift = oConvertUtils.getString(redisTemplate.opsForValue().get(classShift));
+		String shiftGroup = oConvertUtils.getString(redisTemplate.opsForValue().get(classShiftGroup));
+
+		// 3. 查询记录
+		LambdaQueryWrapper<BilletOriginalProductRecord> recordLambdaQueryWrapper = new LambdaQueryWrapper<>();
+		recordLambdaQueryWrapper.eq(BilletOriginalProductRecord::getCcmNo, ccmNo)
+				.eq(BilletOriginalProductRecord::getHeatNo, editDTO.getHeatNo())
+				.eq(BilletOriginalProductRecord::getShift, shift)
+				.eq(BilletOriginalProductRecord::getShiftGroup, shiftGroup)
+				.orderByDesc(BilletOriginalProductRecord::getCreateTime)
+				.last("LIMIT 1");
+
+		BilletOriginalProductRecord one = billetOriginalProductRecordService.getOne(recordLambdaQueryWrapper);
+
+		if (one == null) {
+			return Result.error("未找到匹配的原始记录,请确认炉号、班次和班组信息");
+		}
+
+		// 4. 更新出坯量
+		UpdateWrapper<BilletOriginalProductRecord> updateWrapper = new UpdateWrapper<>();
+		updateWrapper.eq("id", one.getId());
+		updateWrapper.set("blank_output", editDTO.getBlankOutput());
+
+		billetOriginalProductRecordService.update(updateWrapper);
+
+		// 5. 推送处理数据
+		HandleBilletPushDTO pushDTO = new HandleBilletPushDTO();
+		pushDTO.setCcNo(ccmNo);
+		pushDTO.setHeatNo(editDTO.getHeatNo());
+		pushDTO.setBilletWt(editDTO.getBlankOutput());
+
+		billetOriginalProductRecordService.handleBilletPush(pushDTO);
+
+		return Result.OK("修改成功!");
+	}
+
+
+	@AutoLog("根据id更新创建时间")
+	@ApiOperation("根据id更新创建时间")
+	@PutMapping("/updateCreateTime")
+	public Result<String> updateCreateTime(@RequestBody CreateTimeUpdateDTO dto) {
+		if (dto.getId() == null) {
+			return Result.error("ID不能为空");
+		}
+		if (dto.getCreateTime() == null) {
+			return Result.error("createTime 不能为空");
+		}
+
+		UpdateWrapper<BilletOriginalProductRecord> updateWrapper = new UpdateWrapper<>();
+		updateWrapper.eq("id", dto.getId());
+		updateWrapper.set("create_time", dto.getCreateTime());
+
+		boolean success = billetOriginalProductRecordService.update(updateWrapper);
+		if (success) {
+			return Result.OK("更新时间成功!");
+		} else {
+			return Result.error("更新时间失败,请确认ID是否正确");
+		}
+	}
+
+
 	/**
 	 * 获取当前班次下所有炉次浇筑数据
 	 * @param ccmNo

+ 24 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/dto/BlankOutputEditDTO.java

@@ -0,0 +1,24 @@
+package org.jeecg.modules.billet.billetOriginalProductRecord.dto;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class BlankOutputEditDTO {
+
+    /**
+     * 铸机号
+     */
+    private String ccmNo;
+
+    /**
+     * 炉号
+     */
+    private String heatNo;
+
+    /**
+     * 出坯量
+     */
+    private BigDecimal blankOutput;
+}

+ 19 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/dto/CreateTimeUpdateDTO.java

@@ -0,0 +1,19 @@
+package org.jeecg.modules.billet.billetOriginalProductRecord.dto;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class CreateTimeUpdateDTO {
+
+    /**
+     * BilletOriginalProductRecord 主键ID
+     */
+    private String id;
+
+    /**
+     * 新的创建时间
+     */
+    private Date createTime;
+}

+ 25 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/dto/HandleBilletPushDTO.java

@@ -0,0 +1,25 @@
+package org.jeecg.modules.billet.billetOriginalProductRecord.dto;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class HandleBilletPushDTO {
+
+    /**
+     * 铸机号
+     */
+    private String ccNo;
+
+    /**
+     * 炉号
+     */
+    private String heatNo;
+
+    /**
+     * 出坯量
+     */
+    private BigDecimal billetWt;
+
+}

+ 6 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/entity/BilletOriginalProductRecord.java

@@ -226,4 +226,10 @@ public class BilletOriginalProductRecord implements Serializable {
     @ExcelIgnore
     @TableField(exist = false)
     private Integer isHot;
+
+    /**
+     * 出坯量
+     */
+    @ApiModelProperty(value = "出坯量")
+    private BigDecimal blankOutput;
 }

+ 9 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/service/IBilletOriginalProductRecordService.java

@@ -2,8 +2,10 @@ package org.jeecg.modules.billet.billetOriginalProductRecord.service;
 
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.billet.billetOriginalProductRecord.dto.HandleBilletPushDTO;
 import org.jeecg.modules.billet.billetOriginalProductRecord.dto.QualityInspectionQueryDTO;
 import org.jeecg.modules.billet.billetOriginalProductRecord.entity.BilletOriginalProductRecord;
+import org.jeecg.modules.billet.storageBill.entity.StorageBill;
 
 import java.util.Map;
 
@@ -27,4 +29,11 @@ public interface IBilletOriginalProductRecordService extends IService<BilletOrig
      * @param changeShiftId 换班记录ID,可为空
      */
     void delayAndInitStatistics(String ccmNo, String changeShiftId);
+
+    /**
+     * 推送钢坯出坯量数据
+     *
+     * @param pushDTO 出坯量数据
+     */
+    void handleBilletPush(HandleBilletPushDTO pushDTO);
 }

+ 71 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/service/impl/BilletOriginalProductRecordServiceImpl.java

@@ -6,13 +6,17 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.actualControl.billetActual.billetActual.vo.BilletPushResponse;
+import org.jeecg.modules.actualControl.billetActual.billetActual.vo.ShippingOrderVO;
 import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsend;
 import org.jeecg.modules.billet.billetHotsend.mapper.BilletHotsendBaseMapper;
 import org.jeecg.modules.billet.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
 import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
+import org.jeecg.modules.billet.billetOriginalProductRecord.dto.HandleBilletPushDTO;
 import org.jeecg.modules.billet.billetOriginalProductRecord.dto.QualityInspectionQueryDTO;
 import org.jeecg.modules.billet.billetOriginalProductRecord.entity.BilletOriginalProductRecord;
 import org.jeecg.modules.billet.billetOriginalProductRecord.mapper.BilletOriginalProductRecordMapper;
@@ -25,8 +29,10 @@ import org.jeecg.modules.billet.sampleCardDeliveryRecord.entity.SampleCardDelive
 import org.jeecg.modules.billet.sampleCardDeliveryRecord.mapper.SampleCardDeliveryRecordMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.http.ResponseEntity;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -43,6 +49,7 @@ import java.util.stream.Collectors;
  * @Date:   2025-06-23
  * @Version: V1.0
  */
+@Slf4j
 @Service
 public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOriginalProductRecordMapper, BilletOriginalProductRecord> implements IBilletOriginalProductRecordService {
 
@@ -62,6 +69,9 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
     @Autowired
     private SampleCardDeliveryRecordMapper sampleCardDeliveryRecordMapper;
 
+    @Autowired
+    private RestTemplate restTemplate;
+
     @Override
     public Map<String, Object> getQualityInspectionMenu(QualityInspectionQueryDTO queryDTO) {
         if (queryDTO == null || StringUtils.isBlank(queryDTO.getCcmNo())) {
@@ -348,6 +358,17 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
 
     @Override
     public void initMonthlyStatisticsIfMissing(String ccmNo,String changeShiftId) {
+
+        // 参数校验
+        if (ccmNo == null || ccmNo.trim().isEmpty()) {
+            log.warn("initMonthlyStatisticsIfMissing 失败:ccmNo 不能为空");
+            return;
+        }
+        if (changeShiftId == null || changeShiftId.trim().isEmpty()) {
+            log.warn("initMonthlyStatisticsIfMissing 失败:changeShiftId 不能为空");
+            return;
+        }
+
         Date monthStart = DateUtils.getMonthStart(new Date());
         Date searchStart = new Date(monthStart.getTime() - 10 * 60 * 1000); // 向前推10分钟
         Date now = new Date();
@@ -493,6 +514,56 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
         initMonthlyStatisticsIfMissing(ccmNo, changeShiftId);
     }
 
+    @Override
+    @Async("asyncExecutor") // 使用定义好的异步线程池
+    public void handleBilletPush(HandleBilletPushDTO pushDTO) {
+
+        // 远程调用
+        BilletPushResponse response = sendRequestAndLog(pushDTO);
+        if (response != null) {
+            // 远程调用成功后,保存或更新推送日志
+            log.info("远程推送装运单接收接口成功!");
+        } else {
+            log.error("远程调用装运单接收接口失败!");
+            throw new RuntimeException("远程调用装运单接收接口失败!");
+        }
+
+    }
+
+
+    private BilletPushResponse sendRequestAndLog(HandleBilletPushDTO request) {
+        final int maxRetries = 3;
+        final long baseDelayMillis = 3000;
+
+        int attempt = 0;
+        while (attempt < maxRetries) {
+            try {
+                String url = "http://192.168.12.201:8850/scheduling/api/billet-quantities/handleBillet";
+                ResponseEntity<BilletPushResponse> response = restTemplate.postForEntity(url, request, BilletPushResponse.class);
+
+                BilletPushResponse body = response.getBody();
+//                log.info("推送成功,响应信息: {}", body);
+
+                return body;
+            } catch (Exception e) {
+                attempt++;
+                log.error("推送失败,重试第 {} 次,错误信息:{}", attempt, e.getMessage());
+
+                if (attempt >= maxRetries) {
+                    return null;
+                }
+
+                try {
+                    Thread.sleep(baseDelayMillis * attempt);
+                } catch (InterruptedException ie) {
+                    Thread.currentThread().interrupt();
+                    return null;
+                }
+            }
+        }
+        return null;
+    }
+
     public QualityInspectionStatisticsVO getStatisticsByShift(BilletHotsendChangeShift shiftRecord, List<BilletHotsendChangeShift> allShiftsOfTheDay,Map<LocalDate, List<BilletHotsendChangeShift>> shiftByDate) {
         Date classStartTime = shiftRecord.getCreateTime();
         Date classEndTime = Optional.ofNullable(shiftRecord.getChangeShiftTime()).orElse(new Date());

+ 28 - 4
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/sampleCardDeliveryRecord/controller/SampleCardDeliveryRecordController.java

@@ -10,6 +10,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.time.DateFormatUtils;
+import org.apache.commons.lang.time.DateUtils;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
@@ -21,6 +22,7 @@ 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.billetOriginalProductRecord.entity.BilletOriginalProductRecord;
+import org.jeecg.modules.billet.billetOriginalProductRecord.service.IBilletOriginalProductRecordService;
 import org.jeecg.modules.billet.sampleCardDeliveryRecord.entity.SampleCardDeliveryRecord;
 import org.jeecg.modules.billet.sampleCardDeliveryRecord.entity.SampleCardDeliveryRecordDetail;
 import org.jeecg.modules.billet.sampleCardDeliveryRecord.service.ISampleCardDeliveryRecordService;
@@ -31,10 +33,7 @@ import org.springframework.web.servlet.ModelAndView;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 /**
  * @Description: 送样卡记录
@@ -55,6 +54,8 @@ public class SampleCardDeliveryRecordController extends JeecgController<SampleCa
     private IBilletHotsendChangeShiftService billetHotsendChangeShiftService;
     @Autowired
     private IBilletHotsendBaseService billetHotsendService;
+    @Autowired
+    private IBilletOriginalProductRecordService billetOriginalProductRecordService;
 
     /**
      * 分页列表查询
@@ -253,6 +254,29 @@ public class SampleCardDeliveryRecordController extends JeecgController<SampleCa
     @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
     public Result<String> edit(@RequestBody SampleCardDeliveryRecord sampleCardDeliveryRecord) {
         sampleCardDeliveryRecordService.updateById(sampleCardDeliveryRecord);
+
+        // 构建当天起止时间
+        Date createDate = sampleCardDeliveryRecord.getCreateTime();
+        Date startOfDay = DateUtils.truncate(createDate, Calendar.DAY_OF_MONTH); // 当天00:00:00
+        Date endOfDay = DateUtils.addMilliseconds(DateUtils.ceiling(createDate, Calendar.DAY_OF_MONTH), -1); // 当天23:59:59.999
+
+        // 根据ccmNo、shift、shiftGroup查询最新的交班记录
+        LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(BilletHotsendChangeShift::getCcmNo, sampleCardDeliveryRecord.getCcmNo())
+                .eq(BilletHotsendChangeShift::getShift, sampleCardDeliveryRecord.getShift())
+                .eq(BilletHotsendChangeShift::getShiftGroup, sampleCardDeliveryRecord.getShiftGroup())
+                .ge(BilletHotsendChangeShift::getCreateTime, startOfDay)
+                .le(BilletHotsendChangeShift::getCreateTime, endOfDay)
+                .orderByDesc(BilletHotsendChangeShift::getCreateTime)
+                .last("limit 1");
+        BilletHotsendChangeShift changeShift = billetHotsendChangeShiftService.getOne(queryWrapper);
+
+
+        // 延迟统计(修改 SampleCardDeliveryRecord 后)
+        billetOriginalProductRecordService.delayAndInitStatistics(
+                changeShift.getCcmNo(),
+                changeShift.getId()
+        );
         return Result.OK("编辑成功!");
     }