feat:优化设备台账新增接口,修复关联关键件、备件回显问题
parent
a5698d1449
commit
cae6e64c65
@ -0,0 +1,67 @@
|
||||
package cn.iocoder.yudao.module.mes.controller.admin.deviceledger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerComponentRelDO;
|
||||
import cn.iocoder.yudao.module.mes.service.deviceledger.DeviceLedgerComponentRelService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 设备台账关键件关系")
|
||||
@RestController
|
||||
@RequestMapping("/mes/device-ledger-component-rel")
|
||||
@Validated
|
||||
public class DeviceLedgerComponentRelController {
|
||||
|
||||
@Resource
|
||||
private DeviceLedgerComponentRelService deviceLedgerComponentRelService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建设备台账关键件关系")
|
||||
@PreAuthorize("@ss.hasPermission('mes:device-ledger:update')")
|
||||
public CommonResult<Long> create(@Valid @RequestBody DeviceLedgerComponentRelDO createReqVO) {
|
||||
return success(deviceLedgerComponentRelService.create(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新设备台账关键件关系")
|
||||
@PreAuthorize("@ss.hasPermission('mes:device-ledger:update')")
|
||||
public CommonResult<Boolean> update(@Valid @RequestBody DeviceLedgerComponentRelDO updateReqVO) {
|
||||
deviceLedgerComponentRelService.update(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除设备台账关键件关系")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('mes:device-ledger:update')")
|
||||
public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
|
||||
deviceLedgerComponentRelService.delete(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得设备台账关键件关系")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('mes:device-ledger:query')")
|
||||
public CommonResult<DeviceLedgerComponentRelDO> get(@RequestParam("id") Long id) {
|
||||
return success(deviceLedgerComponentRelService.get(id));
|
||||
}
|
||||
|
||||
@GetMapping("/list-by-device-ledger-id")
|
||||
@Operation(summary = "根据设备台账ID获得关键件关系列表")
|
||||
@Parameter(name = "deviceLedgerId", description = "设备台账ID", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('mes:device-ledger:query')")
|
||||
public CommonResult<List<DeviceLedgerComponentRelDO>> listByDeviceLedgerId(@RequestParam("deviceLedgerId") Long deviceLedgerId) {
|
||||
return success(deviceLedgerComponentRelService.getListByDeviceLedgerId(deviceLedgerId));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package cn.iocoder.yudao.module.mes.controller.admin.deviceledger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerSpareRelDO;
|
||||
import cn.iocoder.yudao.module.mes.service.deviceledger.DeviceLedgerSpareRelService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 设备台账备件关系")
|
||||
@RestController
|
||||
@RequestMapping("/mes/device-ledger-spare-rel")
|
||||
@Validated
|
||||
public class DeviceLedgerSpareRelController {
|
||||
|
||||
@Resource
|
||||
private DeviceLedgerSpareRelService deviceLedgerSpareRelService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建设备台账备件关系")
|
||||
@PreAuthorize("@ss.hasPermission('mes:device-ledger:update')")
|
||||
public CommonResult<Long> create(@Valid @RequestBody DeviceLedgerSpareRelDO createReqVO) {
|
||||
return success(deviceLedgerSpareRelService.create(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新设备台账备件关系")
|
||||
@PreAuthorize("@ss.hasPermission('mes:device-ledger:update')")
|
||||
public CommonResult<Boolean> update(@Valid @RequestBody DeviceLedgerSpareRelDO updateReqVO) {
|
||||
deviceLedgerSpareRelService.update(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除设备台账备件关系")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('mes:device-ledger:update')")
|
||||
public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
|
||||
deviceLedgerSpareRelService.delete(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得设备台账备件关系")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('mes:device-ledger:query')")
|
||||
public CommonResult<DeviceLedgerSpareRelDO> get(@RequestParam("id") Long id) {
|
||||
return success(deviceLedgerSpareRelService.get(id));
|
||||
}
|
||||
|
||||
@GetMapping("/list-by-device-ledger-id")
|
||||
@Operation(summary = "根据设备台账ID获得备件关系列表")
|
||||
@Parameter(name = "deviceLedgerId", description = "设备台账ID", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('mes:device-ledger:query')")
|
||||
public CommonResult<List<DeviceLedgerSpareRelDO>> listByDeviceLedgerId(@RequestParam("deviceLedgerId") Long deviceLedgerId) {
|
||||
return success(deviceLedgerSpareRelService.getListByDeviceLedgerId(deviceLedgerId));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@TableName("mes_device_ledger_component_rel")
|
||||
@KeySequence("mes_device_ledger_component_rel_seq")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DeviceLedgerComponentRelDO extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
private Long deviceLedgerId;
|
||||
|
||||
private Long componentId;
|
||||
|
||||
private String componentNameSnapshot;
|
||||
|
||||
private Integer sort;
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@TableName("mes_device_ledger_spare_rel")
|
||||
@KeySequence("mes_device_ledger_spare_rel_seq")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DeviceLedgerSpareRelDO extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
private Long deviceLedgerId;
|
||||
|
||||
private Long productId;
|
||||
|
||||
private String productNameSnapshot;
|
||||
|
||||
private Integer sort;
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.mes.dal.mysql.deviceledger;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerComponentRelDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DeviceLedgerComponentRelMapper extends BaseMapperX<DeviceLedgerComponentRelDO> {
|
||||
|
||||
default List<DeviceLedgerComponentRelDO> selectListByDeviceLedgerId(Long deviceLedgerId) {
|
||||
return selectList(DeviceLedgerComponentRelDO::getDeviceLedgerId, deviceLedgerId);
|
||||
}
|
||||
|
||||
default List<DeviceLedgerComponentRelDO> selectListByDeviceLedgerIds(Collection<Long> deviceLedgerIds) {
|
||||
if (deviceLedgerIds == null || deviceLedgerIds.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return selectList(DeviceLedgerComponentRelDO::getDeviceLedgerId, deviceLedgerIds);
|
||||
}
|
||||
|
||||
default int deleteByDeviceLedgerId(Long deviceLedgerId) {
|
||||
return delete(DeviceLedgerComponentRelDO::getDeviceLedgerId, deviceLedgerId);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.mes.dal.mysql.deviceledger;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerSpareRelDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DeviceLedgerSpareRelMapper extends BaseMapperX<DeviceLedgerSpareRelDO> {
|
||||
|
||||
default List<DeviceLedgerSpareRelDO> selectListByDeviceLedgerId(Long deviceLedgerId) {
|
||||
return selectList(DeviceLedgerSpareRelDO::getDeviceLedgerId, deviceLedgerId);
|
||||
}
|
||||
|
||||
default List<DeviceLedgerSpareRelDO> selectListByDeviceLedgerIds(Collection<Long> deviceLedgerIds) {
|
||||
if (deviceLedgerIds == null || deviceLedgerIds.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return selectList(DeviceLedgerSpareRelDO::getDeviceLedgerId, deviceLedgerIds);
|
||||
}
|
||||
|
||||
default int deleteByDeviceLedgerId(Long deviceLedgerId) {
|
||||
return delete(DeviceLedgerSpareRelDO::getDeviceLedgerId, deviceLedgerId);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.yudao.module.mes.service.deviceledger;
|
||||
|
||||
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerComponentRelDO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface DeviceLedgerComponentRelService {
|
||||
|
||||
Long create(DeviceLedgerComponentRelDO createObj);
|
||||
|
||||
void update(DeviceLedgerComponentRelDO updateObj);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
DeviceLedgerComponentRelDO get(Long id);
|
||||
|
||||
void replaceByDeviceLedgerId(Long deviceLedgerId, String componentIdsText);
|
||||
|
||||
List<DeviceLedgerComponentRelDO> getListByDeviceLedgerId(Long deviceLedgerId);
|
||||
|
||||
Map<Long, List<DeviceLedgerComponentRelDO>> getMapByDeviceLedgerIds(Collection<Long> deviceLedgerIds);
|
||||
|
||||
void deleteByDeviceLedgerId(Long deviceLedgerId);
|
||||
}
|
||||
@ -0,0 +1,115 @@
|
||||
package cn.iocoder.yudao.module.mes.service.deviceledger;
|
||||
|
||||
import cn.iocoder.yudao.module.mes.dal.dataobject.criticalcomponent.CriticalComponentDO;
|
||||
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerComponentRelDO;
|
||||
import cn.iocoder.yudao.module.mes.dal.mysql.criticalcomponent.CriticalComponentMapper;
|
||||
import cn.iocoder.yudao.module.mes.dal.mysql.deviceledger.DeviceLedgerComponentRelMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class DeviceLedgerComponentRelServiceImpl implements DeviceLedgerComponentRelService {
|
||||
|
||||
@Resource
|
||||
private DeviceLedgerComponentRelMapper componentRelMapper;
|
||||
|
||||
@Resource
|
||||
private CriticalComponentMapper criticalComponentMapper;
|
||||
|
||||
@Override
|
||||
public Long create(DeviceLedgerComponentRelDO createObj) {
|
||||
componentRelMapper.insert(createObj);
|
||||
return createObj.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(DeviceLedgerComponentRelDO updateObj) {
|
||||
componentRelMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
componentRelMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceLedgerComponentRelDO get(Long id) {
|
||||
return componentRelMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceByDeviceLedgerId(Long deviceLedgerId, String componentIdsText) {
|
||||
List<Long> componentIds = parseIds(componentIdsText);
|
||||
List<DeviceLedgerComponentRelDO> oldRelList = componentRelMapper.selectListByDeviceLedgerId(deviceLedgerId);
|
||||
Map<Long, String> oldSnapshotMap = oldRelList.stream()
|
||||
.filter(item -> item.getComponentId() != null)
|
||||
.collect(Collectors.toMap(DeviceLedgerComponentRelDO::getComponentId,
|
||||
DeviceLedgerComponentRelDO::getComponentNameSnapshot, (a, b) -> a));
|
||||
|
||||
componentRelMapper.deleteByDeviceLedgerId(deviceLedgerId);
|
||||
if (componentIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Map<Long, CriticalComponentDO> componentMap = criticalComponentMapper.selectBatchIds(componentIds).stream()
|
||||
.collect(Collectors.toMap(CriticalComponentDO::getId, Function.identity(), (a, b) -> a));
|
||||
List<DeviceLedgerComponentRelDO> list = new ArrayList<>();
|
||||
for (int i = 0; i < componentIds.size(); i++) {
|
||||
Long componentId = componentIds.get(i);
|
||||
CriticalComponentDO componentDO = componentMap.get(componentId);
|
||||
String snapshotName = componentDO != null && StringUtils.isNotBlank(componentDO.getName())
|
||||
? componentDO.getName()
|
||||
: oldSnapshotMap.getOrDefault(componentId, "");
|
||||
list.add(DeviceLedgerComponentRelDO.builder()
|
||||
.deviceLedgerId(deviceLedgerId)
|
||||
.componentId(componentId)
|
||||
.componentNameSnapshot(snapshotName)
|
||||
.sort(i + 1)
|
||||
.build());
|
||||
}
|
||||
componentRelMapper.insertBatch(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceLedgerComponentRelDO> getListByDeviceLedgerId(Long deviceLedgerId) {
|
||||
return componentRelMapper.selectListByDeviceLedgerId(deviceLedgerId).stream()
|
||||
.sorted(Comparator.comparing(item -> Optional.ofNullable(item.getSort()).orElse(Integer.MAX_VALUE)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, List<DeviceLedgerComponentRelDO>> getMapByDeviceLedgerIds(Collection<Long> deviceLedgerIds) {
|
||||
return componentRelMapper.selectListByDeviceLedgerIds(deviceLedgerIds).stream()
|
||||
.sorted(Comparator.comparing(item -> Optional.ofNullable(item.getSort()).orElse(Integer.MAX_VALUE)))
|
||||
.collect(Collectors.groupingBy(DeviceLedgerComponentRelDO::getDeviceLedgerId,
|
||||
LinkedHashMap::new, Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByDeviceLedgerId(Long deviceLedgerId) {
|
||||
componentRelMapper.deleteByDeviceLedgerId(deviceLedgerId);
|
||||
}
|
||||
|
||||
private List<Long> parseIds(String idsText) {
|
||||
if (StringUtils.isBlank(idsText)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.stream(idsText.split(","))
|
||||
.map(String::trim)
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.map(Long::valueOf)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.yudao.module.mes.service.deviceledger;
|
||||
|
||||
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerSpareRelDO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface DeviceLedgerSpareRelService {
|
||||
|
||||
Long create(DeviceLedgerSpareRelDO createObj);
|
||||
|
||||
void update(DeviceLedgerSpareRelDO updateObj);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
DeviceLedgerSpareRelDO get(Long id);
|
||||
|
||||
void replaceByDeviceLedgerId(Long deviceLedgerId, String productIdsText);
|
||||
|
||||
List<DeviceLedgerSpareRelDO> getListByDeviceLedgerId(Long deviceLedgerId);
|
||||
|
||||
Map<Long, List<DeviceLedgerSpareRelDO>> getMapByDeviceLedgerIds(Collection<Long> deviceLedgerIds);
|
||||
|
||||
void deleteByDeviceLedgerId(Long deviceLedgerId);
|
||||
}
|
||||
@ -0,0 +1,115 @@
|
||||
package cn.iocoder.yudao.module.mes.service.deviceledger;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductMapper;
|
||||
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerSpareRelDO;
|
||||
import cn.iocoder.yudao.module.mes.dal.mysql.deviceledger.DeviceLedgerSpareRelMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class DeviceLedgerSpareRelServiceImpl implements DeviceLedgerSpareRelService {
|
||||
|
||||
@Resource
|
||||
private DeviceLedgerSpareRelMapper spareRelMapper;
|
||||
|
||||
@Resource
|
||||
private ErpProductMapper productMapper;
|
||||
|
||||
@Override
|
||||
public Long create(DeviceLedgerSpareRelDO createObj) {
|
||||
spareRelMapper.insert(createObj);
|
||||
return createObj.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(DeviceLedgerSpareRelDO updateObj) {
|
||||
spareRelMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
spareRelMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceLedgerSpareRelDO get(Long id) {
|
||||
return spareRelMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceByDeviceLedgerId(Long deviceLedgerId, String productIdsText) {
|
||||
List<Long> productIds = parseIds(productIdsText);
|
||||
List<DeviceLedgerSpareRelDO> oldRelList = spareRelMapper.selectListByDeviceLedgerId(deviceLedgerId);
|
||||
Map<Long, String> oldSnapshotMap = oldRelList.stream()
|
||||
.filter(item -> item.getProductId() != null)
|
||||
.collect(Collectors.toMap(DeviceLedgerSpareRelDO::getProductId,
|
||||
DeviceLedgerSpareRelDO::getProductNameSnapshot, (a, b) -> a));
|
||||
|
||||
spareRelMapper.deleteByDeviceLedgerId(deviceLedgerId);
|
||||
if (productIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Map<Long, ErpProductDO> productMap = productMapper.selectBatchIds(productIds).stream()
|
||||
.collect(Collectors.toMap(ErpProductDO::getId, Function.identity(), (a, b) -> a));
|
||||
List<DeviceLedgerSpareRelDO> list = new ArrayList<>();
|
||||
for (int i = 0; i < productIds.size(); i++) {
|
||||
Long productId = productIds.get(i);
|
||||
ErpProductDO productDO = productMap.get(productId);
|
||||
String snapshotName = productDO != null && StringUtils.isNotBlank(productDO.getName())
|
||||
? productDO.getName()
|
||||
: oldSnapshotMap.getOrDefault(productId, "");
|
||||
list.add(DeviceLedgerSpareRelDO.builder()
|
||||
.deviceLedgerId(deviceLedgerId)
|
||||
.productId(productId)
|
||||
.productNameSnapshot(snapshotName)
|
||||
.sort(i + 1)
|
||||
.build());
|
||||
}
|
||||
spareRelMapper.insertBatch(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceLedgerSpareRelDO> getListByDeviceLedgerId(Long deviceLedgerId) {
|
||||
return spareRelMapper.selectListByDeviceLedgerId(deviceLedgerId).stream()
|
||||
.sorted(Comparator.comparing(item -> Optional.ofNullable(item.getSort()).orElse(Integer.MAX_VALUE)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, List<DeviceLedgerSpareRelDO>> getMapByDeviceLedgerIds(Collection<Long> deviceLedgerIds) {
|
||||
return spareRelMapper.selectListByDeviceLedgerIds(deviceLedgerIds).stream()
|
||||
.sorted(Comparator.comparing(item -> Optional.ofNullable(item.getSort()).orElse(Integer.MAX_VALUE)))
|
||||
.collect(Collectors.groupingBy(DeviceLedgerSpareRelDO::getDeviceLedgerId,
|
||||
LinkedHashMap::new, Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByDeviceLedgerId(Long deviceLedgerId) {
|
||||
spareRelMapper.deleteByDeviceLedgerId(deviceLedgerId);
|
||||
}
|
||||
|
||||
private List<Long> parseIds(String idsText) {
|
||||
if (StringUtils.isBlank(idsText)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.stream(idsText.split(","))
|
||||
.map(String::trim)
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.map(Long::valueOf)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue