package com.zcloud.basic.info.persistence.repository.impl;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jjb.saas.framework.repository.common.PageHelper;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
import com.zcloud.basic.info.domain.model.UserEmploymentLogE;
import com.zcloud.basic.info.persistence.dataobject.UserEmploymentLogDO;
import com.zcloud.basic.info.persistence.mapper.UserEmploymentLogMapper;
import com.zcloud.basic.info.persistence.repository.UserEmploymentLogRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * web-infrastructure
 *
 * @Author zhangyue
 * @Date 2025-11-06 19:15:37
 */
@Service
@RequiredArgsConstructor
public class UserEmploymentLogRepositoryImpl extends BaseRepositoryImpl<UserEmploymentLogMapper, UserEmploymentLogDO> implements UserEmploymentLogRepository {
    private final UserEmploymentLogMapper userEmploymentLogMapper;

    @Override
    public PageResponse<UserEmploymentLogDO> listPage(Map<String, Object> params) {
        IPage<UserEmploymentLogDO> iPage = new Query<UserEmploymentLogDO>().getPage(params);
        QueryWrapper<UserEmploymentLogDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        queryWrapper.orderByDesc("create_time");
        IPage<UserEmploymentLogDO> result = userEmploymentLogMapper.selectPage(iPage, queryWrapper);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public List<UserEmploymentLogDO> listAll(Map<String, Object> params) {
        QueryWrapper<UserEmploymentLogDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        queryWrapper.orderByDesc("create_time");
        queryWrapper.eq("delete_enum","FALSE");
        return userEmploymentLogMapper.selectList(queryWrapper);
    }

    @Override
    public void addCorpUserEmploymentLog(UserEmploymentLogE userEmploymentLogE) {
        UserEmploymentLogDO d = new UserEmploymentLogDO();
        BeanUtils.copyProperties(userEmploymentLogE, d);
        save(d);
    }
}

