package com.mortals.xhx.module.staff.service.impl;
import com.mortals.xhx.module.attendance.model.AttendanceGroupStaffEntity;
import com.mortals.xhx.module.attendance.model.AttendanceGroupStaffQuery;
import com.mortals.xhx.module.attendance.service.AttendanceGroupStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.staff.dao.StaffLeaveDao;
import com.mortals.xhx.module.staff.model.StaffLeaveEntity;
import com.mortals.xhx.module.staff.service.StaffLeaveService;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
* StaffLeaveService
* 员工离职信息 service实现
*
* @author zxfei
* @date 2023-04-07
*/
@Service("staffLeaveService")
public class StaffLeaveServiceImpl extends AbstractCRUDServiceImpl<StaffLeaveDao, StaffLeaveEntity, Long> implements StaffLeaveService {

  @Autowired
   private AttendanceGroupStaffService groupStaffService;


    @Override
    protected void saveAfter(StaffLeaveEntity entity, Context context) throws AppException {
        super.saveAfter(entity, context);


        AttendanceGroupStaffQuery attendanceGroupStaffQuery = new AttendanceGroupStaffQuery();

        attendanceGroupStaffQuery.setStaffId(entity.getStaffId());
        List<AttendanceGroupStaffEntity> attendanceGroupStaffEntities = groupStaffService.find(attendanceGroupStaffQuery, context);
        if(!ObjectUtils.isEmpty(attendanceGroupStaffEntities)){
            Long[] delIds = attendanceGroupStaffEntities.stream().map(attendanceGroupStaffEntity -> attendanceGroupStaffEntity.getId()).toArray(Long[]::new);
            if(!ObjectUtils.isEmpty(delIds)){
                groupStaffService.remove(delIds, context);
            }
        }
        //删除对应考勤组人员
    }
}