package com.dcsoft.system.service.impl;

import com.dcsoft.common.core.utils.DateUtils;
import com.dcsoft.common.datascope.annotation.DataScope;
import com.dcsoft.system.domain.HkPeopleRecord;
import com.dcsoft.system.mapper.HkPeopleRecordMapper;
import com.dcsoft.system.service.IHkPeopleRecordService;
import com.dcsoft.system.uniubi.domain.HkBackRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 海康打卡记录Service业务层处理
 *
 * @author nichun
 * @date 2023-09-27
 */
@Service
public class HkPeopleRecordServiceImpl implements IHkPeopleRecordService
{
    @Autowired
    private HkPeopleRecordMapper hkPeopleRecordMapper;

    /**
     * 查询海康打卡记录
     *
     * @param id 海康打卡记录主键
     * @return 海康打卡记录
     */
    @Override
    public HkPeopleRecord selectHkPeopleRecordById(Long id)
    {
        return hkPeopleRecordMapper.selectHkPeopleRecordById(id);
    }

    /**
     * 查询海康打卡记录列表
     *
     * @param hkPeopleRecord 海康打卡记录
     * @return 海康打卡记录
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<HkPeopleRecord> selectHkPeopleRecordList(HkPeopleRecord hkPeopleRecord)
    {
        return hkPeopleRecordMapper.selectHkPeopleRecordList(hkPeopleRecord);
    }

    /**
     * 新增海康打卡记录
     *
     * @param hkPeopleRecord 海康打卡记录
     * @return 结果
     */
    @Override
    public int insertHkPeopleRecord(HkPeopleRecord hkPeopleRecord)
    {
        hkPeopleRecord.setCreateTime(DateUtils.getNowDate());
        return hkPeopleRecordMapper.insertHkPeopleRecord(hkPeopleRecord);
    }

    /**
     * 修改海康打卡记录
     *
     * @param hkPeopleRecord 海康打卡记录
     * @return 结果
     */
    @Override
    public int updateHkPeopleRecord(HkPeopleRecord hkPeopleRecord)
    {
        hkPeopleRecord.setUpdateTime(DateUtils.getNowDate());
        return hkPeopleRecordMapper.updateHkPeopleRecord(hkPeopleRecord);
    }

    /**
     * 批量删除海康打卡记录
     *
     * @param ids 需要删除的海康打卡记录主键
     * @return 结果
     */
    @Override
    public int deleteHkPeopleRecordByIds(Long[] ids)
    {
        return hkPeopleRecordMapper.deleteHkPeopleRecordByIds(ids);
    }

    /**
     * 删除海康打卡记录信息
     *
     * @param id 海康打卡记录主键
     * @return 结果
     */
    @Override
    public int deleteHkPeopleRecordById(Long id)
    {
        return hkPeopleRecordMapper.deleteHkPeopleRecordById(id);
    }

    @Override
    public List<HkPeopleRecord> selectHkPeopleRecordByEventId(HkPeopleRecord hkPeopleRecord) {
        return hkPeopleRecordMapper.selectHkPeopleRecordByEventId(hkPeopleRecord);
    }

    @Override
    public int insertHkPeopleBackRecord(HkBackRecord hkBackRecord) {
        HkPeopleRecord hkPeopleRecord=new HkPeopleRecord();
        hkPeopleRecord.setEventId(hkBackRecord.getSerialNo()+"");
        hkPeopleRecord.setCardNo(hkBackRecord.getCardNo());
        hkPeopleRecord.setEmployeeNo(hkBackRecord.getEmployeeNoString());
        hkPeopleRecord.setDateTime(hkBackRecord.getDateTime());
        hkPeopleRecord.setEventType("AccessControllerEvent");
        hkPeopleRecord.setEventCode("10101");
        hkPeopleRecord.setRemark(hkBackRecord.getRemark());
        hkPeopleRecord.setDeviceSerial(hkBackRecord.getSerialNumber());
        return hkPeopleRecordMapper.insertHkPeopleRecord(hkPeopleRecord);
    }


}
