package com.mortals.xhx.module.attendance.dao.ibatis;


import com.mortals.framework.exception.AppException;
import com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordQuery;
import com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Repository;
import com.mortals.xhx.module.attendance.dao.AttendanceLeaveRecordDao;
import com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordEntity;
import java.util.Date;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import java.util.List;
/**
* 请假记录信息DaoImpl DAO接口
*
* @author zxfei
* @date 2023-04-07
*/
@Repository("attendanceLeaveRecordDao")
public class AttendanceLeaveRecordDaoImpl extends BaseCRUDDaoMybatis<AttendanceLeaveRecordEntity,Long> implements AttendanceLeaveRecordDao {

    AttendanceLeaveRecordService attendanceLeaveRecordService;

    @Override
    public AttendanceLeaveRecordEntity doUpdateRecord(String processInstanceId,AttendanceLeaveRecordEntity leaveRecordEntity) {
        AttendanceLeaveRecordEntity recordEntity = attendanceLeaveRecordService.selectOne(new AttendanceLeaveRecordQuery().remark(processInstanceId));
        if(ObjectUtils.isEmpty(recordEntity)){
            leaveRecordEntity.setCreateTime(new Date());
            leaveRecordEntity.setCreateUserId(1L);
            attendanceLeaveRecordService.save(leaveRecordEntity);
        }else{
            leaveRecordEntity.setId(recordEntity.getId());

            leaveRecordEntity.setUpdateUserId(1L);
            leaveRecordEntity.setUpdateTime(new Date());

            attendanceLeaveRecordService.update(leaveRecordEntity);
        }

        return leaveRecordEntity;
    }
}
