UserVipManager.java 3.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
package cn.wisenergy.service.common;

import cn.wisenergy.common.utils.Md5Util;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.StaffUserVipMapper;
import cn.wisenergy.mapper.UsersMapper;
import cn.wisenergy.model.app.StaffUserVip;
import cn.wisenergy.model.app.User;
import cn.wisenergy.model.dto.UserCommitDto;
import cn.wisenergy.model.vo.UserInfoVo;
import cn.wisenergy.model.vo.UserVipCommitVo;
import cn.wisenergy.service.app.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Component
@Slf4j
public class UserVipManager {
    @Autowired
    private UserService userService;

    @Autowired
    private VolunteerManager volunteerManager;

    @Autowired
    private StaffUserVipMapper staffUserVipMapper;

    @Autowired
    private UsersMapper usersMapper;

    //初始密码
    private static final String PASSWORD = "123456";



    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public R<Boolean> CommitUserVip(UserVipCommitVo userVipCommitVo){

        //3、给密码加密 初始密码:123456
        String secret = Md5Util.digestMD5(PASSWORD);
        R<UserInfoVo> userInfoVoR = volunteerManager.saveUserAndLimit(userVipCommitVo.getPhone(), secret, userVipCommitVo.getSource());
        if (null == userInfoVoR.getData()) {
            return R.error("信息添加失败1");
        }

        User user = checkPhone(userVipCommitVo.getPhone());
        //调用用户提交信息接口
        UserCommitDto userCommitDto = new UserCommitDto();
        BeanUtils.copyProperties(userVipCommitVo,userCommitDto);
        userCommitDto.setUserId(user.getId());
        R<UserInfoVo> userInfoVo = userService.commitUserVipInfo(userCommitDto);

        if (null==userInfoVo.getData()) {
            return R.ok(1,false);
        }

        return R.ok(0,true);
    }

    public R<Boolean> addPhone1(Integer staffId,Integer userId){

        StaffUserVip staffUserVip = new StaffUserVip();
        staffUserVip.setStaffId(staffId);
        staffUserVip.setUserVipId(userId);
        staffUserVip.setIsDelete(0);
        int add = staffUserVipMapper.add(staffUserVip);

        //判断数据是否添加成功
        if (add==0) {
            usersMapper.delById(userId);
            return R.error("信息添加失败");
        }

        return R.ok(0,true);
    }

    public User checkPhone(String phone) {

        //根据电话号码查询用户
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone", phone);
        queryWrapper.eq("is_delete", 0);
        User user = usersMapper.selectOne(queryWrapper);
        if (null != user) {
            return user;
        }
        return null;
    }
}