package com.zcloud.basic.info.gatewayimpl;

import com.alibaba.cola.dto.Response;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zcloud.basic.info.domain.enums.UserEmploymentFlagEnum;
import com.zcloud.basic.info.domain.gateway.UserGateway;
import com.zcloud.basic.info.domain.model.UserE;
import com.zcloud.basic.info.persistence.dataobject.UserDO;
import com.zcloud.basic.info.persistence.repository.UserRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Arrays;
import java.util.Map;

/**
* web-infrastructure
* @Author zhangyue
* @Date 2025-11-04 14:07:35
*/
@Service
@AllArgsConstructor
public class UserGatewayImpl implements UserGateway {
    private final UserRepository userRepository;

    @Override
    public Boolean add(UserE userE) {
        UserDO d = new UserDO();
        BeanUtils.copyProperties(userE, d);
        userRepository.saveUser(d);
        userE.setId(d.getId());
        return true;
    }

    @Override
    public Boolean register(UserE userE) {
        UserDO d = new UserDO();
        BeanUtils.copyProperties(userE, d);
        userRepository.saveRegisterUser(d);
        userE.setId(d.getId());
        return true;
    }

    @Override
    public boolean addXgf(UserE userE) {
        UserDO d = new UserDO();
        // 新增用户默认在职
        userE.setEmploymentFlag(UserEmploymentFlagEnum.ON.getCode());
        BeanUtils.copyProperties(userE, d);
        userE.resetPassword();
        userRepository.saveUserXgf(d);
        userE.setId(d.getId());
        return true;
    }

    @Override
    public Boolean update(UserE userE) {
        UserDO d = new UserDO();
        BeanUtils.copyProperties(userE, d);
        userRepository.updateById(d);
        return true;
    }

    @Override
    public void deletedUserById(Long id) {
        userRepository.deleteUserById(id);
    }

    @Override
    public Boolean deletedUserByIds(Long[] ids) {
        return userRepository.removeByIds(Arrays.asList(ids));
    }

    @Override
    public Response countUser(Map<String,Object> params) {
        return userRepository.countUser(params);
    }

    @Override
    public Response updatePassword(UserE userE) {
        UserDO userDO = new UserDO();
        BeanUtils.copyProperties(userE, userDO);
        return userRepository.updatePassword(userDO);
    }
}

