UserOperationServiceImpl.java 3 KB
package com.topdraw.business.process.service.impl;


import com.topdraw.business.module.member.domain.Member;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.user.iptv.domain.UserTv;
import com.topdraw.business.module.user.iptv.service.UserTvService;
import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
import com.topdraw.business.module.user.weixin.domain.UserWeixin;
import com.topdraw.business.module.user.weixin.service.UserWeixinService;
import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
import com.topdraw.business.process.service.UserOperationService;
import com.topdraw.business.process.service.dto.MemberAndUserTvDTO;
import com.topdraw.business.process.service.dto.MemberAndWeixinUserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class UserOperationServiceImpl implements UserOperationService {

    @Autowired
    private MemberService memberService;
    @Autowired
    private UserTvService userTvService;
    @Autowired
    private UserWeixinService userWeixinService;

    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
    public void asyncMemberAndUserWeixin4Iptv(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {
        this.saveMember(memberAndWeixinUserDTO.getMemberDTO());
        this.saveWeixin(memberAndWeixinUserDTO.getUserWeixinDTO());
    }

    private void saveMember(MemberDTO memberDTO){
        Member member = new Member();
        BeanUtils.copyProperties(memberDTO, member);
        this.memberService.create(member);
    }

    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
    public void asyncMemberAndUserTv4Iptv(MemberAndUserTvDTO memberAndUserTvDTO) {
        this.saveMember(memberAndUserTvDTO.getMemberDTO());
        this.saveUserTv(memberAndUserTvDTO.getUserTvDTO());
    }

    public void asyncWeixin(UserWeixinDTO weixinDTO) {
        this.saveWeixin(weixinDTO);
    }

    private void saveWeixin(UserWeixinDTO weixinDTO){
        UserWeixin userWeixin = new UserWeixin();
        BeanUtils.copyProperties(weixinDTO, userWeixin);
        this.userWeixinService.create(userWeixin);
    }

    public void asyncUserTv(UserTvDTO userTvDTO) {
        this.saveUserTv(userTvDTO);
    }

    private void saveUserTv(UserTvDTO userTvDTO){
        UserTv userTv = new UserTv();
        BeanUtils.copyProperties(userTvDTO, userTv);
        this.userTvService.create(userTv);
    }

    public void asyncMember(MemberDTO memberDTO) {
        this.saveMember(memberDTO);
    }
}