package com.xy.service;

import com.xy.entity.DeviceFaultInfoAttachments;
import com.xy.mapper.DeviceFaultInfoAttachmentsMapper;
import com.xy.service.DeviceFaultInfoAttachmentsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;

import java.util.List;
import com.xy.utils.R;
import com.xy.utils.PageBean;
import com.xy.dto.DeviceFaultInfoAttachmentsDto;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xy.utils.MybatisPlusQuery;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.validation.annotation.Validated;
import com.xy.utils.Emptys;

import static com.xy.utils.Beans.copy;
import static com.xy.utils.PlusBeans.toIPage;
import static com.xy.utils.PlusBeans.toPageBean;


/**
* <p>
* 设备故障信息附件 服务实现类
* </p>
*
* @author 谭斌
* @since 2024-01-16
*/
@Service
@AllArgsConstructor
@Api(tags = "设备故障信息附件")
public class DeviceFaultInfoAttachmentsServiceImpl extends ServiceImpl<DeviceFaultInfoAttachmentsMapper, DeviceFaultInfoAttachments> implements DeviceFaultInfoAttachmentsService {

    @PostMapping("obj")
    @ApiOperation("对象查询")
    public R<DeviceFaultInfoAttachmentsDto.Vo> obj(@RequestBody DeviceFaultInfoAttachmentsDto.Vo vo) {
        DeviceFaultInfoAttachmentsDto.SelectList selectList = copy(DeviceFaultInfoAttachmentsDto.SelectList.class, vo);
        List<DeviceFaultInfoAttachmentsDto.Vo> list = list(selectList).getData();
        if(Emptys.check(list)) {
            return R.ok(list.get(0));
        }
        return R.ok();
    }

    @PostMapping("list")
    @ApiOperation("集合查询")
    public R<List<DeviceFaultInfoAttachmentsDto.Vo>> list(@RequestBody DeviceFaultInfoAttachmentsDto.SelectList selectList) {
        LambdaQueryWrapper<DeviceFaultInfoAttachments> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, DeviceFaultInfoAttachments.class).build();
        List<DeviceFaultInfoAttachments> list = list(lambdaQueryWrapper);
        return R.ok(copy(DeviceFaultInfoAttachmentsDto.Vo.class, list));
    }

    @PostMapping("page")
    @ApiOperation("分页查询")
    public R<PageBean<DeviceFaultInfoAttachmentsDto.Vo>> page(@RequestBody DeviceFaultInfoAttachmentsDto.Page page) {
        PageBean pageBean = page.getPage();
        LambdaQueryWrapper<DeviceFaultInfoAttachments> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, DeviceFaultInfoAttachments.class).build();
        IPage<DeviceFaultInfoAttachments> iPage = page(toIPage(pageBean), lambdaQueryWrapper);
        return R.ok(toPageBean(DeviceFaultInfoAttachmentsDto.Vo.class, iPage));
    }

    @PostMapping("save")
    @ApiOperation("添加")
    public R save(@RequestBody @Validated DeviceFaultInfoAttachmentsDto.Save save) {
        DeviceFaultInfoAttachments saveInfo = copy(DeviceFaultInfoAttachments.class, save);
        save(saveInfo);
        return R.ok();
    }

    @PostMapping("update")
    @ApiOperation("修改")
    public R update(@RequestBody @Validated DeviceFaultInfoAttachmentsDto.Update update) {
        DeviceFaultInfoAttachments updateInfo = copy(DeviceFaultInfoAttachments.class, update);
        updateById(updateInfo);
        return R.ok();
    }
}