diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java index 2d358a0..a899a00 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java @@ -104,21 +104,11 @@ public class StationController extends BladeController { return R.status(stationService.instanceProject(req)); } - @PostMapping("/updateBatch") + @PostMapping("/updateBatchSort") @ApiOperationSupport(order = 30) - @ApiOperation(value = "批量修改", notes = "传入站点列表") - public R updateBatch(@RequestBody List req) { - for (StationEntity stationEntity : req) { - if (StringUtil.isNotBlank(stationEntity.getCode()) || StringUtil.isNotBlank(stationEntity.getName())) { - List list = stationService.list(new LambdaQueryWrapper() {{ - eq(StationEntity::getCode, stationEntity.getCode()).or().eq(StationEntity::getName, stationEntity.getName()); - }}); - Assert.isTrue(CollectionUtil.isEmpty(list), () -> { - throw new ServiceException(stationEntity.getId() + "下站点名/编码已有对应记录,请找到相应记录做修改处理"); - }); - } - } - return R.status(stationService.updateBatchById(req)); + @ApiOperation(value = "批量修改排序", notes = "传入站点列表") + public R updateBatchSort(@RequestBody List req) { + return R.status(stationService.updateBatchSort(req)); } /** diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java index 924cb11..7106f30 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java @@ -1,5 +1,6 @@ package com.hnac.hzims.operational.station.service; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.hnac.hzims.operational.main.vo.StationCountVo; @@ -127,4 +128,14 @@ public interface IStationService extends BaseService { @Override boolean updateById(StationEntity req); + + @Override + boolean save(StationEntity entity); + + /** + * 批量更新站点排序 + * @param req 站点列表 + * @return 更新是否成功 + */ + boolean updateBatchSort(List req); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java index 78d95f3..6479253 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java @@ -89,8 +89,11 @@ public class StationServiceImpl extends BaseServiceImpl { throw new ServiceException("创建/修改机构失败!"); }); - Optional sort = Optional.ofNullable(this.getStationMaxOrder()); - req.setSort(sort.map(integer -> integer + 1).orElse(1)); + // 区分新增和修改站点信息,若为新增,则排序递增,否则不变 + if (req.getId() == null) { + Optional sort = Optional.ofNullable(this.getStationMaxOrder()); + req.setSort(sort.isPresent() ? sort.get() + 1 : 1); + } boolean updateResult = this.saveOrUpdate(req); Assert.isTrue(updateResult, () -> { throw new ServiceException("创建/修改站点信息失败!");