|
@@ -2,16 +2,21 @@ package com.warewms.hailiang.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.warewms.common.core.domain.R;
|
|
|
import com.warewms.common.core.domain.base.page.PageDomain;
|
|
|
import com.warewms.common.core.domain.base.page.TableDataInfo;
|
|
|
import com.warewms.common.core.domain.model.LoginUser;
|
|
|
+import com.warewms.common.core.redis.RedisCache;
|
|
|
import com.warewms.common.exception.ServiceException;
|
|
|
import com.warewms.common.utils.SecurityUtils;
|
|
|
import com.warewms.common.utils.StringUtils;
|
|
|
import com.warewms.hailiang.MES.MesService;
|
|
|
+import com.warewms.hailiang.domain.DeviceLog;
|
|
|
import com.warewms.hailiang.domain.RetroactiveHistory;
|
|
|
import com.warewms.hailiang.domain.RetroactiveNow;
|
|
|
import com.warewms.hailiang.mapper.RetroactiveHistoryMapper;
|
|
@@ -25,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* @author AD
|
|
@@ -45,6 +51,10 @@ public class RetroactiveNowServiceImpl extends ServiceImpl<RetroactiveNowMapper,
|
|
|
@Autowired
|
|
|
private MesService mesService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
@Override
|
|
|
public TableDataInfo<RetroactiveNow> getList(RetroactiveNow retroactiveNow, PageDomain pageDomain, List<String> inStatus) {
|
|
|
Map<String, Object> params = retroactiveNow.getParams();
|
|
@@ -53,43 +63,58 @@ public class RetroactiveNowServiceImpl extends ServiceImpl<RetroactiveNowMapper,
|
|
|
.like(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
|
|
|
.like(StringUtils.isNotEmpty(retroactiveNow.getLotNo()), RetroactiveNow::getLotNo, retroactiveNow.getLotNo())
|
|
|
.in(inStatus.size() > 0, RetroactiveNow::getStatus, inStatus)
|
|
|
+ .orderByDesc(RetroactiveNow::getStatus)
|
|
|
.orderByDesc(RetroactiveNow::getCreateTime)
|
|
|
));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public int insertData(RetroactiveNow retroactiveNow) {
|
|
|
+ if (ObjectUtil.isNotNull(redisCache.getCacheObject("weigh" + retroactiveNow.getBatchNo()))) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
List<RetroactiveNow> retroactiveNows = retroactiveNowMapper.selectList(new LambdaQueryWrapper<RetroactiveNow>()
|
|
|
.eq(RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
|
|
|
);
|
|
|
if (retroactiveNows.size() > 0) {
|
|
|
+ SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_ChengZhong_PLC-1-52.21", "ChengZhongPlc", "数据库中已存在相同批次号,请联系管理员!", "2"));
|
|
|
throw new ServiceException("数据库中已存在相同批次号");
|
|
|
}
|
|
|
retroactiveNowMapper.insert(retroactiveNow);
|
|
|
- return retroactiveHistoryMapper.insert(BeanUtil.copyProperties(retroactiveNow, RetroactiveHistory.class));
|
|
|
+ int insert = retroactiveHistoryMapper.insert(BeanUtil.copyProperties(retroactiveNow, RetroactiveHistory.class));
|
|
|
+ redisCache.setCacheObject("weigh" + retroactiveNow.getBatchNo(), retroactiveNow.getBatchNo(), 30, TimeUnit.SECONDS);
|
|
|
+ return insert;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public RetroactiveNow selectTheOneByParameter(RetroactiveNow retroactiveNow) {
|
|
|
- return retroactiveNowMapper.selectOne(new LambdaQueryWrapper<RetroactiveNow>()
|
|
|
+ List<RetroactiveNow> retroactiveNows = retroactiveNowMapper.selectList(new LambdaQueryWrapper<RetroactiveNow>()
|
|
|
.eq(StringUtils.isNotEmpty(retroactiveNow.getRetroactiveId()), RetroactiveNow::getRetroactiveId, retroactiveNow.getRetroactiveId())
|
|
|
.eq(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
|
|
|
.eq(StringUtils.isNotEmpty(retroactiveNow.getStatus()), RetroactiveNow::getStatus, retroactiveNow.getStatus())
|
|
|
+ .orderByDesc(RetroactiveNow::getStatus)
|
|
|
);
|
|
|
+ if (retroactiveNows.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ return retroactiveNows.get(0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public int updateData(RetroactiveNow retroactiveNow) {
|
|
|
+ //校验
|
|
|
RetroactiveNow baseData = confirmTheDataByIndex(retroactiveNow);
|
|
|
baseData.setStatus(retroactiveNow.getStatus());
|
|
|
baseData.setDeviceId(retroactiveNow.getDeviceId());
|
|
|
baseData.setUpdateBy("system");
|
|
|
+ baseData.setUpdateTime(new Date());
|
|
|
retroactiveNowMapper.updateById(baseData);
|
|
|
RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(baseData, RetroactiveHistory.class);
|
|
|
retroactiveHistory.setCreateTime(baseData.getUpdateTime());
|
|
|
return retroactiveHistoryMapper.insert(retroactiveHistory);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -101,40 +126,122 @@ public class RetroactiveNowServiceImpl extends ServiceImpl<RetroactiveNowMapper,
|
|
|
baseData.setUpdateBy("system");
|
|
|
RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(baseData, RetroactiveHistory.class);
|
|
|
retroactiveHistory.setCreateTime(new Date());
|
|
|
- retroactiveHistoryMapper.insert(retroactiveHistory);
|
|
|
- return retroactiveNowMapper.deleteById(baseData);
|
|
|
+ int delete = retroactiveNowMapper.delete(new LambdaQueryWrapper<RetroactiveNow>().eq(RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo()));
|
|
|
+ if (delete == 1) {
|
|
|
+ retroactiveHistoryMapper.insert(retroactiveHistory);
|
|
|
+
|
|
|
+ }
|
|
|
+ return delete;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public R complement(RetroactiveNow retroactiveNow) {
|
|
|
- RetroactiveNow baseData = confirmTheDataByIndex(retroactiveNow);
|
|
|
- if ("2".equals(baseData.getStatus())){
|
|
|
- mesService.getBatchNoResult(retroactiveNow.getBatchNo(), true);
|
|
|
+ RetroactiveNow baseData = new RetroactiveNow();
|
|
|
+ if (!"5".equals(retroactiveNow.getStatus())) {
|
|
|
+ baseData = confirmTheDataByIndex(retroactiveNow);
|
|
|
+ if ("2".equals(retroactiveNow.getStatus())) {
|
|
|
+ mesService.getBatchNoResult(retroactiveNow.getBatchNo(), 1);
|
|
|
+ }
|
|
|
+ if ("3".equals(retroactiveNow.getStatus())) {
|
|
|
+ mesService.processFeedback(retroactiveNow.getBatchNo(), "1");
|
|
|
+ }
|
|
|
+ if ("4".equals(retroactiveNow.getStatus())) {
|
|
|
+ mesService.processFeedback(retroactiveNow.getBatchNo(), "2");
|
|
|
+ }
|
|
|
+ updateData(retroactiveNow, baseData);
|
|
|
+ } else {
|
|
|
+ String batchNo = mesService.bindLotNo(retroactiveNow.getDeviceId(), retroactiveNow.getLotNo());
|
|
|
+ if (StringUtils.isEmpty(batchNo)) {
|
|
|
+ return R.fail("该大散盘设备不存在产出");
|
|
|
+ }
|
|
|
+ baseData.setBatchNo(batchNo);
|
|
|
+ List<RetroactiveNow> retroactiveNows = retroactiveNowMapper.selectList(new LambdaQueryWrapper<RetroactiveNow>()
|
|
|
+ .eq(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
|
|
|
+ );
|
|
|
+ if (retroactiveNows.isEmpty()) {
|
|
|
+ throw new ServiceException("数据库中不存在该批次号或托盘号," + retroactiveNow.getBatchNo() + "," + retroactiveNow.getLotNo());
|
|
|
+ }
|
|
|
+ RetroactiveNow retroactiveNow1 = retroactiveNows.get(0);
|
|
|
+ if (retroactiveNows.size() == 1) {
|
|
|
+ if (StringUtils.isEmpty(retroactiveNow1.getLotNo())) {
|
|
|
+ updateData(retroactiveNow, retroactiveNow1);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ retroactiveNow1.setNowId(null);
|
|
|
+ retroactiveNow1.setLotNo(retroactiveNow.getLotNo());
|
|
|
+ retroactiveNow1.setSanPanDevice(retroactiveNow.getSanPanDevice());
|
|
|
+ retroactiveNow1.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ retroactiveNow1.setUpdateTime(retroactiveNow.getUpdateTime());
|
|
|
+ retroactiveNowMapper.insert(retroactiveNow1);
|
|
|
+ RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(retroactiveNow1, RetroactiveHistory.class);
|
|
|
+ retroactiveHistory.setCreateTime(baseData.getUpdateTime());
|
|
|
+ retroactiveNow.setRemark("PDA手动补码");
|
|
|
+ retroactiveHistoryMapper.insert(retroactiveHistory);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- if ("3".equals(baseData.getStatus())){
|
|
|
- mesService.processFeedback(retroactiveNow.getBatchNo(),"1");
|
|
|
+
|
|
|
+
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R update(RetroactiveNow retroactiveNow) {
|
|
|
+ RetroactiveNow baseData = retroactiveNowMapper.selectOne(new LambdaQueryWrapper<RetroactiveNow>()
|
|
|
+ .eq(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isNull(baseData)) {
|
|
|
+ throw new ServiceException("数据库中不存在该批次号," + retroactiveNow.getBatchNo());
|
|
|
}
|
|
|
- if ("4".equals(baseData.getStatus())){
|
|
|
- mesService.processFeedback(retroactiveNow.getBatchNo(),"2");
|
|
|
+ baseData.setLotNo(retroactiveNow.getLotNo());
|
|
|
+ retroactiveNowMapper.updateById(baseData);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R delete(RetroactiveHistory retroactiveHistory) {
|
|
|
+ retroactiveHistoryMapper.update(retroactiveHistory,
|
|
|
+ new UpdateWrapper<RetroactiveHistory>()
|
|
|
+ .set("del_remark", retroactiveHistory.getDelRemark())
|
|
|
+ .set("del_flag", "1")
|
|
|
+ .eq("batch_no", retroactiveHistory.getBatchNo()));
|
|
|
+ retroactiveNowMapper.delete(new LambdaQueryWrapper<RetroactiveNow>().eq(RetroactiveNow::getBatchNo, retroactiveHistory.getBatchNo()));
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public int DataTwins(RetroactiveNow retroactiveNow) {
|
|
|
+ if (ObjectUtil.isNull(retroactiveNow.getBatchNo())) {
|
|
|
+ return 0;
|
|
|
}
|
|
|
- LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
- baseData.setStatus(retroactiveNow.getStatus());
|
|
|
- baseData.setDeviceId("PDA");
|
|
|
- baseData.setUpdateBy(loginUser.getUsername());
|
|
|
- baseData.setRemark("PDA手动补码");
|
|
|
- if(Integer.parseInt(retroactiveNow.getStatus())>Integer.parseInt(baseData.getStatus())){
|
|
|
- retroactiveNowMapper.updateById(baseData);
|
|
|
+ List<RetroactiveNow> retroactiveNows = retroactiveNowMapper.selectList(new LambdaQueryWrapper<RetroactiveNow>()
|
|
|
+ .eq(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
|
|
|
+ );
|
|
|
+ if (retroactiveNows.isEmpty()) {
|
|
|
+ throw new ServiceException("数据库中不存在该批次号或托盘号," + retroactiveNow.getBatchNo() + "," + retroactiveNow.getLotNo());
|
|
|
}
|
|
|
- baseData.setCreateBy(loginUser.getUsername());
|
|
|
- if (ObjectUtil.isNull(retroactiveNow.getCreateTime())){
|
|
|
- throw new ServiceException("工序完成时间为空!");
|
|
|
+ retroactiveNows.get(0).setStatus(retroactiveNow.getStatus());
|
|
|
+ retroactiveNows.get(0).setDeviceId(retroactiveNow.getDeviceId());
|
|
|
+ retroactiveNows.get(0).setUpdateBy("system");
|
|
|
+ retroactiveNows.get(0).setUpdateTime(null);
|
|
|
+ retroactiveNows.get(0).setSanPanDevice(retroactiveNow.getSanPanDevice());
|
|
|
+ if (retroactiveNows.size() == 1 && StringUtils.isEmpty(retroactiveNows.get(0).getLotNo())) {
|
|
|
+ retroactiveNows.get(0).setLotNo(retroactiveNow.getLotNo());
|
|
|
+ retroactiveNowMapper.updateById(retroactiveNows.get(0));
|
|
|
+ } else {
|
|
|
+ retroactiveNows.get(0).setNowId(null);
|
|
|
+ retroactiveNows.get(0).setLotNo(retroactiveNow.getLotNo());
|
|
|
+ retroactiveNowMapper.insert(retroactiveNows.get(0));
|
|
|
}
|
|
|
- baseData.setCreateTime(retroactiveNow.getCreateTime());
|
|
|
- RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(baseData, RetroactiveHistory.class);
|
|
|
- retroactiveHistory.setCreateTime(baseData.getUpdateTime());
|
|
|
+ RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(retroactiveNows.get(0), RetroactiveHistory.class);
|
|
|
+ retroactiveHistory.setCreateTime(new Date());
|
|
|
retroactiveHistoryMapper.insert(retroactiveHistory);
|
|
|
- return R.ok();
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
private RetroactiveNow confirmTheDataByIndex(RetroactiveNow retroactiveNow) {
|
|
@@ -145,11 +252,34 @@ public class RetroactiveNowServiceImpl extends ServiceImpl<RetroactiveNowMapper,
|
|
|
if (ObjectUtil.isNull(baseData)) {
|
|
|
throw new ServiceException("数据库中不存在该批次号或托盘号," + retroactiveNow.getBatchNo() + "," + retroactiveNow.getLotNo());
|
|
|
}
|
|
|
- if (baseData.getStatus().equals(retroactiveNow.getStatus())) {
|
|
|
+ if (baseData.getStatus().equals(retroactiveNow.getStatus()) && !"5".equals(baseData.getStatus())) {
|
|
|
throw new ServiceException("数据库存在该状态相同批次号或托盘号的数据");
|
|
|
}
|
|
|
return baseData;
|
|
|
}
|
|
|
+
|
|
|
+ private void updateData(RetroactiveNow retroactiveNow, RetroactiveNow baseData) {
|
|
|
+ retroactiveNow.setNowId(baseData.getNowId());
|
|
|
+ retroactiveNow.setRetroactiveId(baseData.getRetroactiveId());
|
|
|
+ retroactiveNow.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ if (Integer.parseInt(retroactiveNow.getStatus()) >= Integer.parseInt(baseData.getStatus())) {
|
|
|
+ retroactiveNowMapper.updateById(retroactiveNow);
|
|
|
+ if (ObjectUtil.isNull(retroactiveNow.getUpdateTime())) {
|
|
|
+ throw new ServiceException("工序完成时间为空!");
|
|
|
+ }
|
|
|
+ baseData = retroactiveNowMapper.selectById(baseData.getNowId());
|
|
|
+ baseData.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ baseData.setCreateTime(retroactiveNow.getUpdateTime());
|
|
|
+ RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(baseData, RetroactiveHistory.class);
|
|
|
+ retroactiveHistory.setCreateTime(baseData.getUpdateTime());
|
|
|
+ retroactiveHistoryMapper.insert(retroactiveHistory);
|
|
|
+ } else {
|
|
|
+ RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(retroactiveNow, RetroactiveHistory.class);
|
|
|
+ retroactiveHistory.setCreateTime(baseData.getUpdateTime());
|
|
|
+ retroactiveNow.setRemark("PDA手动补码");
|
|
|
+ retroactiveHistoryMapper.insert(retroactiveHistory);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|