diff --git a/ant-design-vue-jeecg/src/views/hanger/HangerManage.vue b/ant-design-vue-jeecg/src/views/hanger/HangerManage.vue index 8c3952d2..1331b845 100644 --- a/ant-design-vue-jeecg/src/views/hanger/HangerManage.vue +++ b/ant-design-vue-jeecg/src/views/hanger/HangerManage.vue @@ -33,7 +33,7 @@ import '@/assets/less/TableExpand.less' import {mixinDevice} from '@/utils/mixin' import {JeecgListMixin} from '@/mixins/JeecgListMixin' -import {getAction, postAction} from "@api/manage"; +import {getAction, postAction, putAction} from "@api/manage"; import {filterObj, pushIfNotExist, randomNumber, randomUUID} from "@/utils/util"; import {JVXETypes} from '@/components/jeecg/JVxeTable' @@ -130,7 +130,7 @@ export default { url: { list: "/org.jeecg.modules.hanger/zyHang/getPointById", getStationList: "/jeecg-boot/org.jeecg.modules.hanger/zyHang/getStationList", - syncHangRecord: "/org.jeecg.modules.productplan/zyPlanProcess/syncHangRecord", + syncHangRecord: "/org.jeecg.modules.hanger/hangRecord/syncHangRecord", addBatch: "/org.jeecg.modules.hanger/zyHangPoint/addBatch", }, loadRouteType: false, @@ -195,7 +195,7 @@ export default { //同步生产记录到吊挂运行记录表 syncHangRecord() { this.loading = true; - getAction(this.url.syncHangRecord, {"code": this.code}).then((res) => { + putAction(this.url.syncHangRecord, {"hangCode": this.code}).then((res) => { if (res.success) { this.$message.success("操作成功"); } else { diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/controller/HangRecordController.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/controller/HangRecordController.java index 6dff3325..3b7ddada 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/controller/HangRecordController.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/controller/HangRecordController.java @@ -11,6 +11,7 @@ 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.modules.hanger.entity.HangRecord; +import org.jeecg.modules.hanger.entity.ZyHangPoint; import org.jeecg.modules.hanger.service.IHangRecordService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -56,6 +57,18 @@ public class HangRecordController extends JeecgController syncHangRecord(@RequestBody HangRecord hangRecord) { + hangRecordService.syncHangRecord(hangRecord); + return Result.OK(); + } + /** * 添加 * diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/controller/ZyHangPointController.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/controller/ZyHangPointController.java index 71b9df59..ca6c66dd 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/controller/ZyHangPointController.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/controller/ZyHangPointController.java @@ -65,14 +65,6 @@ public class ZyHangPointController extends JeecgController syncHangRecord(ZyHangPoint zyHangPoint) { - zyHangPointService.syncHangRecord(zyHangPoint); - return Result.OK(); - } - - @ApiOperation(value = "吊挂工位表-工站、工位绑定批量添加", notes = "吊挂工位表-工站、工位绑定批量添加") @PostMapping(value = "/addBatch") public Result addBatch(@RequestBody List pointList) { diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/IHangRecordService.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/IHangRecordService.java index 7599dca0..da40da0e 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/IHangRecordService.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/IHangRecordService.java @@ -11,5 +11,5 @@ import org.jeecg.modules.hanger.entity.HangRecord; * @Version: V1.0 */ public interface IHangRecordService extends IService { - + void syncHangRecord(HangRecord hangRecord); } diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/IZyHangPointService.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/IZyHangPointService.java index 6b591a85..e865e726 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/IZyHangPointService.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/IZyHangPointService.java @@ -17,6 +17,4 @@ public interface IZyHangPointService extends IService { String getLastPointCode(); void addBatch(List pointList); - - void syncHangRecord(ZyHangPoint zyHangPoint); } diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/impl/HangRecordServiceImpl.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/impl/HangRecordServiceImpl.java index 9c222347..96ecd0e9 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/impl/HangRecordServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/impl/HangRecordServiceImpl.java @@ -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 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().eq(ZyHang::getCode, hangRecord.getHangCode())); + Optional.ofNullable(one).orElseThrow(() -> new JeecgBootException("吊挂不存在!")); + + List pointList = iZyHangPointService.list(new LambdaQueryWrapper().eq(ZyHangPoint::getCode, hangRecord.getHangCode())); + //没有配置工站时,不同步运行记录 + if (ObjectUtils.isEmpty(pointList)) return; + + //查询每一工站是否已有同步过的工站运行记录数据, + // 有同步过则根据生产记录表创建时间为条件增量同步, + // 未同步过则全量同步 + pointList.forEach(e -> { + List saveList; + List pointRecordList = this.list(new LambdaQueryWrapper() + .eq(HangRecord::getHangCode, hangRecord.getHangCode()) + .eq(HangRecord::getPoint, e.getPoint()) + .orderByDesc(HangRecord::getCreateTime) + ); + if (!ObjectUtils.isEmpty(pointRecordList)) {//该工站已同步过,增量同步 + Date createTime = pointRecordList.get(0).getCreateTime(); + List productRecords = iProductRecordService.list(new LambdaQueryWrapper() + .eq(ProductRecord::getStationId, e.getStationId()) + .gt(ProductRecord::getCreateTime, createTime) + ); + saveList = this.convertHangRecord(one.getCode(), e.getPoint(), productRecords); + } else {//该工站未同步过 + List productRecords = iProductRecordService.list(new LambdaQueryWrapper() + .eq(ProductRecord::getStationId, e.getStationId()) + ); + saveList = this.convertHangRecord(one.getCode(), e.getPoint(), productRecords); + } + this.saveBatch(saveList); + }); + } + + private List convertHangRecord(final String hangCode, final String point, List productRecords) { + List 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; + } } diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/impl/ZyHangPointServiceImpl.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/impl/ZyHangPointServiceImpl.java index 10d3d79f..a6efbe98 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/impl/ZyHangPointServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/hanger/service/impl/ZyHangPointServiceImpl.java @@ -4,12 +4,9 @@ package org.jeecg.modules.hanger.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.lang3.StringUtils; -import org.jeecg.common.exception.JeecgBootException; -import org.jeecg.modules.hanger.entity.ZyHang; import org.jeecg.modules.hanger.entity.ZyHangPoint; import org.jeecg.modules.hanger.mapper.ZyHangPointMapper; import org.jeecg.modules.hanger.service.IZyHangPointService; -import org.jeecg.modules.hanger.service.IZyHangService; import org.jeecg.modules.team.entity.Station; import org.jeecg.modules.team.service.IStationService; import org.springframework.beans.factory.annotation.Autowired; @@ -32,9 +29,6 @@ public class ZyHangPointServiceImpl extends ServiceImpl pointList = this.list(new LambdaQueryWrapper().orderByDesc(ZyHangPoint::getPoint)); @@ -63,11 +57,4 @@ public class ZyHangPointServiceImpl extends ServiceImpl().eq(ZyHang::getCode, zyHangPoint.getCode())); - Optional.ofNullable(zyHang).orElseThrow(() -> new JeecgBootException(zyHangPoint.getCode() + "不存在")); - //TODO - } }