qiangxuan 5 months ago
parent
commit
f2c4cc77c5

+ 7 - 30
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/controller/BilletHotsendChangeShiftController.java

@@ -1,9 +1,9 @@
 package org.jeecg.modules.billet.billetHotsendChangeShift.controller;
 
+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.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;
@@ -27,7 +27,6 @@ import org.springframework.web.servlet.ModelAndView;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Arrays;
-import java.util.Date;
 import java.util.List;
 
 /**
@@ -86,8 +85,6 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 	@RequiresPermissions("billetHotsendChangeShift:billet_hotsend_change_shift:add")
 	@PostMapping(value = "/add")
 	public Result<String> add(@RequestBody BilletHotsendChangeShift billetHotsendChangeShiftVo) {
-
-
 		LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapperCS = new LambdaQueryWrapper<>();
 		queryWrapperCS.eq(BilletHotsendChangeShift::getCcmNo, billetHotsendChangeShiftVo.getCcmNo())
 				.between(BilletHotsendChangeShift::getCreateTime, DateUtils.getStartOfDay(), DateUtils.getEndOfDay());
@@ -100,33 +97,13 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 				return Result.error("当天不能重复交班");
 			}
 		}
-		//更新班组班别缓存
-		String keyShiftGroup = String.format("class:shift:group:%s", billetHotsendChangeShiftVo.getCcmNo());
-		String keyShift = String.format("class:shift:%s", billetHotsendChangeShiftVo.getCcmNo());
-		redisTemplate.opsForValue().set(keyShiftGroup, billetHotsendChangeShiftVo.getShiftGroup());
-		redisTemplate.opsForValue().set(keyShift, billetHotsendChangeShiftVo.getShift());
-		// 生成新的交班记录 初始化并保存入库
-		BilletHotsendChangeShift billetHotsendChangeShift1 = new BilletHotsendChangeShift();
-		billetHotsendChangeShift1.setId(String.valueOf(IdWorker.getId()));
-		billetHotsendChangeShift1.setCcmNo(billetHotsendChangeShiftVo.getCcmNo());
-		billetHotsendChangeShift1.setShift(billetHotsendChangeShiftVo.getShift());
-		billetHotsendChangeShift1.setShiftGroup(billetHotsendChangeShiftVo.getShiftGroup());
-		billetHotsendChangeShift1.setHotfeignAmount(0);// 当前热装支数
-		billetHotsendChangeShift1.setProductAmount(0);//当前生产支数
-		billetHotsendChangeShift1.setHotsendAmount(0);// 当前热送支数
-		billetHotsendChangeShift1.setStackAmount(0);//当前起垛支数
-		billetHotsendChangeShift1.setOutCarNum(0);//车次
-		billetHotsendChangeShift1.setShiftSum(0);//当班总数
-		billetHotsendChangeShift1.setShiftProduct(0d); // 当班总重
-		billetHotsendChangeShift1.setWasteAmount(0);// 当前废品支数
-		billetHotsendChangeShift1.setCreateTime(new Date());
-		billetHotsendChangeShiftService.save(billetHotsendChangeShift1);
-
-		operateLogService.add(billetHotsendChangeShift1,null, BilletHotsendChangeShift.class);
-
-		return Result.OK("交班成功!");
+		JSONObject jsonObject = billetHotsendChangeShiftService.billetHotsendChangeShiftHandle(billetHotsendChangeShiftVo);
+		if (jsonObject.containsKey("fail")){
+			return Result.OK((String) jsonObject.get("fail"));
+		}
+		return Result.OK((String) jsonObject.get("success"));
 	}
-	
+
 	/**
 	 *  编辑
 	 *

+ 2 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/service/IBilletHotsendChangeShiftService.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.billet.billetHotsendChangeShift.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.modules.billet.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
 
@@ -11,4 +12,5 @@ import org.jeecg.modules.billet.billetHotsendChangeShift.entity.BilletHotsendCha
  */
 public interface IBilletHotsendChangeShiftService extends IService<BilletHotsendChangeShift> {
 
+    JSONObject billetHotsendChangeShiftHandle(BilletHotsendChangeShift billetHotsendChangeShiftVo);
 }

+ 101 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/service/impl/BilletHotsendChangeShiftServiceImpl.java

@@ -1,11 +1,24 @@
 package org.jeecg.modules.billet.billetHotsendChangeShift.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+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.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
 import org.jeecg.modules.billet.billetHotsendChangeShift.mapper.BilletHotsendChangeShiftMapper;
 import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
+import org.jeecg.modules.billet.operateLog.service.IOperateLogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
 /**
  * @Description: 钢坯交班记录
  * @Author: jeecg-boot
@@ -15,4 +28,92 @@ import org.springframework.stereotype.Service;
 @Service
 public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotsendChangeShiftMapper, BilletHotsendChangeShift> implements IBilletHotsendChangeShiftService {
 
+    @Autowired
+    private IBilletBasicInfoService billetBasicInfoService;
+
+    @Autowired
+    public RedisTemplate redisTemplate;
+
+    @Autowired
+    private IOperateLogService operateLogService;
+
+
+    @Override
+    public JSONObject billetHotsendChangeShiftHandle(BilletHotsendChangeShift billetHotsendChangeShiftVo) {
+
+        JSONObject result = new JSONObject();
+        //先更新班组班别缓存
+        String keyShiftGroup = String.format("class:shift:group:%s", billetHotsendChangeShiftVo.getCcmNo());
+        String keyShift = String.format("class:shift:%s", billetHotsendChangeShiftVo.getCcmNo());
+        redisTemplate.opsForValue().set(keyShiftGroup, billetHotsendChangeShiftVo.getShiftGroup());
+        redisTemplate.opsForValue().set(keyShift, billetHotsendChangeShiftVo.getShift());
+        // 获取当前班组班别
+        List<BilletHotsendChangeShift> billetHotsendChangeShiftList = baseMapper.selectList(new LambdaQueryWrapper<BilletHotsendChangeShift>()
+                .eq(BilletHotsendChangeShift::getCcmNo, billetHotsendChangeShiftVo.getCcmNo())
+                .orderByDesc(BilletHotsendChangeShift::getCreateTime));
+        if (oConvertUtils.listIsNotEmpty(billetHotsendChangeShiftList)){
+            BilletHotsendChangeShift billetHotsendChangeShift = billetHotsendChangeShiftList.stream().findFirst().orElse(null);
+            // 获取当前最新炉号
+            BilletBasicInfo billetBasicInfo = billetBasicInfoService.list(new LambdaQueryWrapper<BilletBasicInfo>().orderByDesc(BilletBasicInfo::getCreateTime)).stream().findFirst().orElse(null);
+            if (oConvertUtils.isNotEmpty(billetBasicInfo)){
+                // 根据当前炉号、铸机号、班组、班别查询总生产的钢坯数
+                LambdaQueryWrapper<BilletBasicInfo> queryWrapper = new LambdaQueryWrapper<BilletBasicInfo>()
+                        .eq(BilletBasicInfo::getCcmNo, Integer.valueOf(billetHotsendChangeShiftVo.getCcmNo()))
+                        .eq(BilletBasicInfo::getHeatNo, billetBasicInfo.getHeatNo())
+                        .eq(BilletBasicInfo::getShift, billetHotsendChangeShift.getShift())
+                        .eq(BilletBasicInfo::getShiftGroup, billetHotsendChangeShift.getShiftGroup())
+                        .orderByDesc(BilletBasicInfo::getCreateTime);
+                List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(queryWrapper);
+                if (oConvertUtils.listIsNotEmpty(billetBasicInfoList)){
+                    List<BilletBasicInfo> updateBilletBasicInfo = extractRemainderData(billetBasicInfoList);
+                    updateBilletBasicInfo.forEach(x ->{
+                        x.setShift(billetHotsendChangeShiftVo.getShift());
+                        x.setShiftGroup(billetHotsendChangeShiftVo.getShiftGroup());
+                        x.setUpdateTime(new Date());
+                    });
+                    billetBasicInfoService.saveOrUpdateBatch(updateBilletBasicInfo);
+                }
+            }
+        }
+
+        // 生成新的交班记录 初始化并保存入库
+        BilletHotsendChangeShift billetHotsendChangeShift1 = new BilletHotsendChangeShift();
+        billetHotsendChangeShift1.setId(String.valueOf(IdWorker.getId()));
+        billetHotsendChangeShift1.setCcmNo(billetHotsendChangeShiftVo.getCcmNo());
+        billetHotsendChangeShift1.setShift(billetHotsendChangeShiftVo.getShift());
+        billetHotsendChangeShift1.setShiftGroup(billetHotsendChangeShiftVo.getShiftGroup());
+        billetHotsendChangeShift1.setHotfeignAmount(0);// 当前热装支数
+        billetHotsendChangeShift1.setProductAmount(0);//当前生产支数
+        billetHotsendChangeShift1.setHotsendAmount(0);// 当前热送支数
+        billetHotsendChangeShift1.setStackAmount(0);//当前起垛支数
+        billetHotsendChangeShift1.setOutCarNum(0);//车次
+        billetHotsendChangeShift1.setShiftSum(0);//当班总数
+        billetHotsendChangeShift1.setShiftProduct(0d); // 当班总重
+        billetHotsendChangeShift1.setWasteAmount(0);// 当前废品支数
+        billetHotsendChangeShift1.setCreateTime(new Date());
+        baseMapper.insert(billetHotsendChangeShift1);
+        operateLogService.add(billetHotsendChangeShift1,null, BilletHotsendChangeShift.class);
+
+        result.put("success", "交班操作成功!");
+        return result;
+    }
+
+    /**
+     * 计算余数并提取相应元素
+     * @param billetBasicInfoList
+     * @return
+     */
+    private List<BilletBasicInfo> extractRemainderData(List<BilletBasicInfo> billetBasicInfoList) {
+        List<BilletBasicInfo> remainderList = new ArrayList<>();
+        if (oConvertUtils.listIsNotEmpty(billetBasicInfoList)) {
+            int size = billetBasicInfoList.size();
+            int remainder = size % 4;
+            if (remainder > 0) {
+                for (int i = size - remainder; i < size; i++) {
+                    remainderList.add(billetBasicInfoList.get(i));
+                }
+            }
+        }
+        return remainderList;
+    }
 }