package com.tmerclub.cloud.user.feign;

import com.tmerclub.cloud.api.user.dto.UserExtensionDTO;
import com.tmerclub.cloud.api.user.feign.UserExtensionFeignClient;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.user.model.UserExtension;
import com.tmerclub.cloud.user.service.UserExtensionService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author gaozijie
 * @date 2023-05-23
 */
@DubboService
public class UserExtensionFeignController implements UserExtensionFeignClient {

    @Autowired
    private UserExtensionService userExtensionService;

    @Override
    public void updateExtension(UserExtensionDTO userExtensionDTO) {
        UserExtension userExtension = userExtensionService.getByUserId(userExtensionDTO.getUserId());
        if (userExtension == null) {
            ServerResponseEntity.showFailMsg("用户拓展信息不存在");
            return;
        }
        Integer version = userExtension.getVersion();
        BeanUtils.copyProperties(userExtensionDTO, userExtension);
        userExtension.setVersion(version);
        userExtensionService.update(userExtension);
    }

    @Override
    public void updateBatchStatus(UserExtensionDTO userExtensionDTO, List<Long> userIds) {
        userExtensionService.updateBatchStatus(userExtensionDTO, userIds);
    }
}
