package com.xy.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.yitter.idgen.YitIdHelper; import com.xy.dto.DevicePartDto; import com.xy.entity.DevicePart; import com.xy.mapper.DevicePartMapper; import com.xy.utils.Emptys; import com.xy.utils.MybatisPlusQuery; import com.xy.utils.R; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import java.time.LocalDateTime; import java.util.List; import static com.xy.utils.Beans.copy; /** *

* 设备配件表 服务实现类 *

* * @author lijin * @since 2024-02-02 */ @Service @AllArgsConstructor @Api(tags = "设备配件表") public class DevicePartServiceImpl extends ServiceImpl implements DevicePartService { @ApiOperation("集合查询") @PostMapping("list") public R> list(@RequestBody DevicePartDto.SelectList selectList) { LambdaQueryWrapper lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, DevicePart.class).build(); List list = list(lambdaQueryWrapper); return R.ok(copy(DevicePartDto.Vo.class, list)); } @ApiOperation("添加或修改") @PostMapping("saveOrUpdate") public R saveOrUpdate(@RequestBody List saveOrUpdates) { LocalDateTime now = LocalDateTime.now(); //循环处理 saveOrUpdates.forEach(saveOrUpdate -> { DevicePart devicePart = getOne(new LambdaQueryWrapper() .eq(DevicePart::getDeviceId, saveOrUpdate.getDeviceId()) .eq(DevicePart::getCode, saveOrUpdate.getCode()) ); //删除 if (saveOrUpdate.getIsRemove() && devicePart != null) { removeById(devicePart.getId()); return; } //新增 if (devicePart == null) { DevicePart info = copy(DevicePart.class, saveOrUpdate) .setId(YitIdHelper.nextId()) .setUpdateTime(now) .setCreateTime(now); save(info); return; } //修改 if (Emptys.check(saveOrUpdate.getValue())) { updateById(devicePart.setValue(saveOrUpdate.getValue())); } }); return R.ok(); } }