/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the yifu4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */
package com.yifu.cloud.plus.v1.consumer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.consumer.entity.Consumer;
import com.yifu.cloud.plus.v1.consumer.mapper.ConsumerMapper;
import com.yifu.cloud.plus.v1.consumer.service.ConsumerService;
import com.yifu.cloud.plus.v1.provider.entity.Provider;
import com.yifu.cloud.plus.v1.provider.feign.RemoteProviderService;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.SecurityConstants;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * consumer表
 *
 * @author fxj
 * @date 2022-05-13 23:28:12
 */
@RequiredArgsConstructor
@Service
public class ConsumerServiceImpl extends ServiceImpl<ConsumerMapper, Consumer> implements ConsumerService {

	private final RemoteProviderService remoteProviderService;


	@GlobalTransactional // 分布式seata事务
	@Transactional
	@Override
	public Boolean saveTestSeata(Consumer consumer) {
		Provider provider = new Provider();
		provider.setNicename(consumer.getNicename());
		provider.setUsername(consumer.getUsername());
		provider.setCreateBy(consumer.getCreateBy());
		provider.setCreateTime(consumer.getCreateTime());
		provider.setUpdateBy(consumer.getUpdateBy());
		provider.setUpdateTime(consumer.getUpdateTime());
		remoteProviderService.testSeata(provider, SecurityConstants.FROM_IN);
		baseMapper.insert(consumer);
		return true;
	}
}
