1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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;
- /**
- * <p>
- * 设备配件表 服务实现类
- * </p>
- *
- * @author lijin
- * @since 2024-02-02
- */
- @Service
- @AllArgsConstructor
- @Api(tags = "设备配件表")
- public class DevicePartServiceImpl extends ServiceImpl<DevicePartMapper, DevicePart> implements DevicePartService {
- @ApiOperation("集合查询")
- @PostMapping("list")
- public R<List<DevicePartDto.Vo>> list(@RequestBody DevicePartDto.SelectList selectList) {
- LambdaQueryWrapper<DevicePart> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, DevicePart.class).build();
- List<DevicePart> list = list(lambdaQueryWrapper);
- return R.ok(copy(DevicePartDto.Vo.class, list));
- }
- @ApiOperation("添加或修改")
- @PostMapping("saveOrUpdate")
- public R saveOrUpdate(@RequestBody List<DevicePartDto.SaveOrUpdate> saveOrUpdates) {
- LocalDateTime now = LocalDateTime.now();
- //循环处理
- saveOrUpdates.forEach(saveOrUpdate -> {
- DevicePart devicePart = getOne(new LambdaQueryWrapper<DevicePart>()
- .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();
- }
- }
|