|
|
|
@ -1,11 +1,30 @@ |
|
|
|
|
package org.jeecg.modules.hanger.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import io.github.classgraph.utils.VersionFinder; |
|
|
|
|
import org.jeecg.common.exception.JeecgBootException; |
|
|
|
|
import org.jeecg.modules.demo.productrecord.entity.ProductRecord; |
|
|
|
|
import org.jeecg.modules.demo.productrecord.service.IProductRecordService; |
|
|
|
|
import org.jeecg.modules.hanger.entity.HangRecord; |
|
|
|
|
import org.jeecg.modules.hanger.entity.ZyHang; |
|
|
|
|
import org.jeecg.modules.hanger.entity.ZyHangPoint; |
|
|
|
|
import org.jeecg.modules.hanger.mapper.HangRecordMapper; |
|
|
|
|
import org.jeecg.modules.hanger.service.IHangRecordService; |
|
|
|
|
import org.jeecg.modules.hanger.service.IZyHangPointService; |
|
|
|
|
import org.jeecg.modules.hanger.service.IZyHangService; |
|
|
|
|
import org.jeecg.modules.team.service.IStationService; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.LinkedList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @Description: 吊挂运行记录表 |
|
|
|
@ -16,4 +35,64 @@ import org.springframework.stereotype.Service; |
|
|
|
|
@Service |
|
|
|
|
public class HangRecordServiceImpl extends ServiceImpl<HangRecordMapper, HangRecord> implements IHangRecordService { |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private IStationService iStationService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private IZyHangService iZyHangService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private IZyHangPointService iZyHangPointService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private IProductRecordService iProductRecordService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(readOnly = false, rollbackFor = Exception.class) |
|
|
|
|
public void syncHangRecord(HangRecord hangRecord) { |
|
|
|
|
ZyHang one = iZyHangService.getOne(new LambdaQueryWrapper<ZyHang>().eq(ZyHang::getCode, hangRecord.getHangCode())); |
|
|
|
|
Optional.ofNullable(one).orElseThrow(() -> new JeecgBootException("吊挂不存在!")); |
|
|
|
|
|
|
|
|
|
List<ZyHangPoint> pointList = iZyHangPointService.list(new LambdaQueryWrapper<ZyHangPoint>().eq(ZyHangPoint::getCode, hangRecord.getHangCode())); |
|
|
|
|
//没有配置工站时,不同步运行记录
|
|
|
|
|
if (ObjectUtils.isEmpty(pointList)) return; |
|
|
|
|
|
|
|
|
|
//查询每一工站是否已有同步过的工站运行记录数据,
|
|
|
|
|
// 有同步过则根据生产记录表创建时间为条件增量同步,
|
|
|
|
|
// 未同步过则全量同步
|
|
|
|
|
pointList.forEach(e -> { |
|
|
|
|
List<HangRecord> saveList; |
|
|
|
|
List<HangRecord> pointRecordList = this.list(new LambdaQueryWrapper<HangRecord>() |
|
|
|
|
.eq(HangRecord::getHangCode, hangRecord.getHangCode()) |
|
|
|
|
.eq(HangRecord::getPoint, e.getPoint()) |
|
|
|
|
.orderByDesc(HangRecord::getCreateTime) |
|
|
|
|
); |
|
|
|
|
if (!ObjectUtils.isEmpty(pointRecordList)) {//该工站已同步过,增量同步
|
|
|
|
|
Date createTime = pointRecordList.get(0).getCreateTime(); |
|
|
|
|
List<ProductRecord> productRecords = iProductRecordService.list(new LambdaQueryWrapper<ProductRecord>() |
|
|
|
|
.eq(ProductRecord::getStationId, e.getStationId()) |
|
|
|
|
.gt(ProductRecord::getCreateTime, createTime) |
|
|
|
|
); |
|
|
|
|
saveList = this.convertHangRecord(one.getCode(), e.getPoint(), productRecords); |
|
|
|
|
} else {//该工站未同步过
|
|
|
|
|
List<ProductRecord> productRecords = iProductRecordService.list(new LambdaQueryWrapper<ProductRecord>() |
|
|
|
|
.eq(ProductRecord::getStationId, e.getStationId()) |
|
|
|
|
); |
|
|
|
|
saveList = this.convertHangRecord(one.getCode(), e.getPoint(), productRecords); |
|
|
|
|
} |
|
|
|
|
this.saveBatch(saveList); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<HangRecord> convertHangRecord(final String hangCode, final String point, List<ProductRecord> productRecords) { |
|
|
|
|
List<HangRecord> saveList = new LinkedList<>(); |
|
|
|
|
Optional.ofNullable(productRecords).orElse(new LinkedList<>()).forEach(obj -> { |
|
|
|
|
HangRecord hangRecord1 = new HangRecord(); |
|
|
|
|
BeanUtils.copyProperties(obj, hangRecord1); |
|
|
|
|
hangRecord1.setHangCode(hangCode); |
|
|
|
|
hangRecord1.setPoint(point); |
|
|
|
|
saveList.add(hangRecord1); |
|
|
|
|
}); |
|
|
|
|
return saveList; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|