package cn.newfeifan.mall.module.distri.service.socialstatuschangelog;

import cn.newfeifan.mall.module.distri.dal.dataobject.socialstatuschangelog.SocialStatusChangeLogDO;
import cn.newfeifan.mall.module.distri.dal.mysql.socialstatuschangelog.SocialStatusChangeLogMapper;
import cn.newfeifan.mall.module.distri.enums.SocialStatusEnum;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

import static cn.newfeifan.mall.module.distri.constant.DistriConstants.IS_EFFECTIVE;

/**
 * 会员身价变化日志 Service 实现类
 *
 * @author 非繁人
 */
@Service
@Validated
public class SocialStatusChangeLogServiceImpl implements SocialStatusChangeLogService {

    @Resource
    private SocialStatusChangeLogMapper socialStatusChangeLogMapper;

    @Override
    public Long createSocialStatusChangeLog(Long userId, Long socialValue, Long objectId, SocialStatusEnum socialStatusEnum) {
        // 插入
        SocialStatusChangeLogDO socialStatusChangeLog = SocialStatusChangeLogDO.builder()
                .socialStatusChangeCategoryId(Long.valueOf(socialStatusEnum.getStatus()))
                .description(socialStatusEnum.getName())
                .variationValue(socialValue)
                .objectId(objectId)
                .effective(IS_EFFECTIVE)
                .userId(userId).build();
        socialStatusChangeLogMapper.insert(socialStatusChangeLog);
        // 返回
        return socialStatusChangeLog.getId();
    }

}
