package com.cyl.manager.staff.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyl.h5.pojo.request.StaffServiceRecordRequest;
import com.cyl.h5.pojo.vo.StaffServiceRecordVO;
import com.cyl.manager.staff.domain.StaffServiceRecord;
import com.cyl.manager.staff.mapper.StaffServiceRecordMapper;
import com.cyl.manager.staff.service.IStaffServiceRecordService;
import com.ruoyi.common.utils.bean.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 人员工服务记录Service接口
 *
 * @author ruoyi
 * @date 2023-12-26
 */
@Service
@Slf4j
public class StaffServiceRecordServiceImpl extends ServiceImpl<StaffServiceRecordMapper, StaffServiceRecord> implements IStaffServiceRecordService {

    @Override
    public boolean saveOrUpdateServiceRecord(StaffServiceRecordRequest request) {
        StaffServiceRecord staffServiceRecord = new StaffServiceRecord();
        BeanUtils.copyProperties(request, staffServiceRecord);
        return this.saveOrUpdate(staffServiceRecord);
    }

    @Override
    public List<StaffServiceRecordVO> getServiceRecords(Long staffId) {
        List<StaffServiceRecordVO> result = new ArrayList<>();
        List<StaffServiceRecord> staffServiceRecords = this.list(new LambdaQueryWrapper<StaffServiceRecord>().eq(StaffServiceRecord::getStaffId, staffId));
        if (!CollectionUtils.isEmpty(staffServiceRecords)) {
            staffServiceRecords.stream().forEach(o -> {
                StaffServiceRecordVO staffServiceRecordVO = new StaffServiceRecordVO();
                BeanUtils.copyProperties(o, staffServiceRecordVO);
                result.add(staffServiceRecordVO);
            });

        }
        return result;
    }

    @Override
    public StaffServiceRecordVO getServiceRecord(Long staffId) {
        StaffServiceRecord staffServiceRecord = this.getOne(new LambdaQueryWrapper<StaffServiceRecord>().eq(StaffServiceRecord::getStaffId,staffId));
        StaffServiceRecordVO staffServiceRecordVO = new StaffServiceRecordVO();
        BeanUtils.copyProperties(staffServiceRecord,staffServiceRecordVO);
        return staffServiceRecordVO;
    }

}
