DevicePartServiceImpl.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.xy.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.github.yitter.idgen.YitIdHelper;
  5. import com.xy.dto.DevicePartDto;
  6. import com.xy.entity.DevicePart;
  7. import com.xy.mapper.DevicePartMapper;
  8. import com.xy.utils.Emptys;
  9. import com.xy.utils.MybatisPlusQuery;
  10. import com.xy.utils.R;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiOperation;
  13. import lombok.AllArgsConstructor;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import org.springframework.web.bind.annotation.RequestBody;
  17. import java.time.LocalDateTime;
  18. import java.util.List;
  19. import static com.xy.utils.Beans.copy;
  20. /**
  21. * <p>
  22. * 设备配件表 服务实现类
  23. * </p>
  24. *
  25. * @author lijin
  26. * @since 2024-02-02
  27. */
  28. @Service
  29. @AllArgsConstructor
  30. @Api(tags = "设备配件表")
  31. public class DevicePartServiceImpl extends ServiceImpl<DevicePartMapper, DevicePart> implements DevicePartService {
  32. @ApiOperation("集合查询")
  33. @PostMapping("list")
  34. public R<List<DevicePartDto.Vo>> list(@RequestBody DevicePartDto.SelectList selectList) {
  35. LambdaQueryWrapper<DevicePart> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, DevicePart.class).build();
  36. List<DevicePart> list = list(lambdaQueryWrapper);
  37. return R.ok(copy(DevicePartDto.Vo.class, list));
  38. }
  39. @ApiOperation("添加或修改")
  40. @PostMapping("saveOrUpdate")
  41. public R saveOrUpdate(@RequestBody List<DevicePartDto.SaveOrUpdate> saveOrUpdates) {
  42. LocalDateTime now = LocalDateTime.now();
  43. //循环处理
  44. saveOrUpdates.forEach(saveOrUpdate -> {
  45. DevicePart devicePart = getOne(new LambdaQueryWrapper<DevicePart>()
  46. .eq(DevicePart::getDeviceId, saveOrUpdate.getDeviceId())
  47. .eq(DevicePart::getCode, saveOrUpdate.getCode())
  48. );
  49. //删除
  50. if (saveOrUpdate.getIsRemove() && devicePart != null) {
  51. removeById(devicePart.getId());
  52. return;
  53. }
  54. //新增
  55. if (devicePart == null) {
  56. DevicePart info = copy(DevicePart.class, saveOrUpdate)
  57. .setId(YitIdHelper.nextId())
  58. .setUpdateTime(now)
  59. .setCreateTime(now);
  60. save(info);
  61. return;
  62. }
  63. //修改
  64. if (Emptys.check(saveOrUpdate.getValue())) {
  65. updateById(devicePart.setValue(saveOrUpdate.getValue()));
  66. }
  67. });
  68. return R.ok();
  69. }
  70. }