package com.xy.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xy.dto.DeviceDoorRecordDto;
import com.xy.entity.DeviceDoorRecord;
import com.xy.mapper.DeviceDoorRecordMapper;
import com.xy.utils.Emptys;
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.util.List;

import static com.xy.utils.Beans.copy;


/**
 * <p>
 * 设备门锁记录表 服务实现类
 * </p>
 *
 * @author lijin
 * @since 2024-07-30
 */
@Service
@AllArgsConstructor
@Api(tags = "设备门锁记录表")
public class DeviceDoorRecordServiceImpl extends ServiceImpl<DeviceDoorRecordMapper, DeviceDoorRecord> implements DeviceDoorRecordService {

    @PostMapping("list")
    @ApiOperation("集合查询")
    public R<List<DeviceDoorRecordDto.Vo>> list(@RequestBody DeviceDoorRecordDto.SelectList selectList) {
        LambdaQueryWrapper<DeviceDoorRecord> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceDoorRecord>()
                .eq(DeviceDoorRecord::getDeviceId, selectList.getDeviceId())
                .eq(DeviceDoorRecord::getDoor, Emptys.check(selectList.getDoor()) ? selectList.getDoor() : 0)
                .eq(Emptys.check(selectList.getStatus()), DeviceDoorRecord::getStatus, selectList.getStatus())
                .ge(Emptys.check(selectList.getBeginTime()), DeviceDoorRecord::getCreateTime, selectList.getBeginTime())
                .le(Emptys.check(selectList.getEndTime()), DeviceDoorRecord::getCreateTime, selectList.getEndTime())
                .orderByAsc(DeviceDoorRecord::getCreateTime);
        List<DeviceDoorRecord> deviceDoorRecords = list(lambdaQueryWrapper);
        List<DeviceDoorRecordDto.Vo> vos = copy(DeviceDoorRecordDto.Vo.class, deviceDoorRecords);
        return R.ok(vos);
    }

}