package com.zhgd.xmgl.modules.basicdata.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhgd.xmgl.async.AsyncAttendance;
import com.zhgd.xmgl.modules.basicdata.entity.AttendanceDev;
import com.zhgd.xmgl.modules.basicdata.entity.SystemDictData;
import com.zhgd.xmgl.modules.basicdata.mapper.AttendanceDevMapper;
import com.zhgd.xmgl.modules.basicdata.service.IAttendanceDevService;
import com.zhgd.xmgl.modules.basicdata.service.ISystemDictDataService;
import com.zhgd.xmgl.util.ParamEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: 考勤设备
 * @author： pengj
 * @date：   2023-03-14
 * @version： V1.0
 */
@Service
public class AttendanceDevServiceImpl extends ServiceImpl<AttendanceDevMapper, AttendanceDev> implements IAttendanceDevService {

    @Autowired
    private ISystemDictDataService systemDictDataService;

    @Autowired
    private AsyncAttendance asyncAttendance;

    @Override
    public boolean saveInfo(AttendanceDev attendanceDev) {
        // 添加考勤设备
        boolean flag = this.save(attendanceDev);
        if (flag) {
            // 推送新增的考勤设备信息
            SystemDictData data = systemDictDataService.getOne(Wrappers.<SystemDictData>lambdaQuery()
                    .eq(SystemDictData::getDictType, ParamEnum.SysDictType.ATTEND_DEV_ADD_API.getValue())
                    .eq(SystemDictData::getDictLabel, attendanceDev.getProduceId()));
            asyncAttendance.syncAttendanceDev(data.getRemark(), attendanceDev);
        }
        return flag;
    }

    @Override
    public boolean updateInfo(AttendanceDev attendanceDev) {
        // 修改考勤设备
        boolean flag = this.updateById(attendanceDev);
        if (flag) {
            // 推送修改的考勤设备信息

        }
        return flag;
    }

    @Override
    public boolean delInfo(AttendanceDev attendanceDev) {
        // 删除考勤设备
        boolean flag = this.removeById(attendanceDev.getId());
        if (flag) {
            // 推送删除的考勤设备信息
            SystemDictData data = systemDictDataService.getOne(Wrappers.<SystemDictData>lambdaQuery()
                    .eq(SystemDictData::getDictType, ParamEnum.SysDictType.ATTEND_DEV_DEL_API.getValue())
                    .eq(SystemDictData::getDictLabel, attendanceDev.getProduceId()));
            asyncAttendance.syncAttendanceDev(data.getRemark(), attendanceDev);
        }
        return flag;
    }
}
