Blame view

ProjectServiceImpl.java 7.82 KB
涂亚平 committed
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
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.administer.VerifyCodeDTO;
import com.subsidy.dto.labor.SalaryListSumDTO;
import com.subsidy.dto.labor.UpdateTelephoneDTO;
import com.subsidy.mapper.*;
import com.subsidy.model.MemberDO;
import com.subsidy.model.ProjectDO;
import com.subsidy.model.SmsVerifyCodeDO;
import com.subsidy.service.ProjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.*;
import com.subsidy.vo.administer.UserRoleVO;
import com.subsidy.vo.labor.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 项目表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2024-07-18
 */
@Service
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, ProjectDO> implements ProjectService {

    @Autowired
    private MemberMapper memberMapper;

    @Autowired
    private SMSUtils smsUtils;

    @Autowired
    private SmsVerifyCodeMapper smsVerifyCodeMapper;

    @Autowired
    private ProjectMemberMappingMapper projectMemberMappingMapper;

    @Autowired
    private ProjectSalaryHistoryMapper projectSalaryHistoryMapper;

    public String sendSms(MemberDO memberDO) {

        int count = memberMapper.selectCount(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone, memberDO.getTelephone())
                .eq(MemberDO::getMemberType, 3));

        if (count == 0) {
            throw new HttpException(10011);
        }

        String code = RandomUtil.getRandomCode(6);
        smsUtils.send(memberDO.getTelephone(), code);

        smsVerifyCodeMapper.delete(new QueryWrapper<SmsVerifyCodeDO>()
                .lambda()
                .eq(SmsVerifyCodeDO::getTelephone, memberDO.getTelephone()));

        SmsVerifyCodeDO smsCodeDO = new SmsVerifyCodeDO();
        smsCodeDO.setVerifyCode(code);
        smsCodeDO.setTelephone(memberDO.getTelephone());
        smsVerifyCodeMapper.insert(smsCodeDO);
        return ConstantUtils.SUCCESS_SEND_OUT;
    }

涂亚平 committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

    public String sendNewSms(MemberDO memberDO) {

        int count = memberMapper.selectCount(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone, memberDO.getTelephone())
                .eq(MemberDO::getMemberType, 3));

        if (count > 0) {
            throw new HttpException(10027);
        }

        String code = RandomUtil.getRandomCode(6);
        smsUtils.send(memberDO.getTelephone(), code);

        smsVerifyCodeMapper.delete(new QueryWrapper<SmsVerifyCodeDO>()
                .lambda()
                .eq(SmsVerifyCodeDO::getTelephone, memberDO.getTelephone()));

        SmsVerifyCodeDO smsCodeDO = new SmsVerifyCodeDO();
        smsCodeDO.setVerifyCode(code);
        smsCodeDO.setTelephone(memberDO.getTelephone());
        smsVerifyCodeMapper.insert(smsCodeDO);
        return ConstantUtils.SUCCESS_SEND_OUT;
    }

涂亚平 committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    public UserRoleVO login(VerifyCodeDTO verifyCodeDTO) {
        UserRoleVO userRoleVO = new UserRoleVO();

        MemberDO memberDO = memberMapper.selectOne(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone, verifyCodeDTO.getTelephone())
                .eq(MemberDO::getMemberType, 3));
        if (null == memberDO) {
            throw new HttpException(10011);
        }

        SmsVerifyCodeDO smsCodeDO = smsVerifyCodeMapper.selectOne(new QueryWrapper<SmsVerifyCodeDO>()
                .lambda()
                .eq(SmsVerifyCodeDO::getTelephone, verifyCodeDTO.getTelephone())
                .eq(SmsVerifyCodeDO::getVerifyCode, verifyCodeDTO.getVerifyCode())
                .gt(SmsVerifyCodeDO::getCreateDate, LocalDateTime.now().minusMinutes(30L)));

        if (null == smsCodeDO || !verifyCodeDTO.getVerifyCode().equals(smsCodeDO.getVerifyCode())) {
            throw new HttpException(70010);
        }

        String token = JwtUtil.generateToken(memberDO.getId(), ConstantUtils.MOBILE_TERMINATE);
        Localstorage.setUser(memberDO);
        userRoleVO.setToken(token);
        BeanUtils.copyProperties(memberDO, userRoleVO);

涂亚平 committed
129 130 131 132 133
        if (null != verifyCodeDTO.getOpenId()){
            memberDO.setOpenId(verifyCodeDTO.getOpenId());
            memberMapper.updateById(memberDO);
        }

涂亚平 committed
134 135 136 137 138 139 140 141 142 143 144
        return userRoleVO;
    }

    public CurrentProjectVO currentProject(MemberDO memberDO) {
        return projectMemberMappingMapper.currentProject(memberDO.getId());
    }

    public List<HistoryProjectsVO> historyProjects(MemberDO memberDO) {
        return projectMemberMappingMapper.historyProjects(memberDO.getId());
    }

涂亚平 committed
145 146


涂亚平 committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
    public String verify(VerifyCodeDTO verifyCodeDTO) {

        SmsVerifyCodeDO smsCodeDO = smsVerifyCodeMapper.selectOne(new QueryWrapper<SmsVerifyCodeDO>()
                .lambda()
                .eq(SmsVerifyCodeDO::getTelephone, verifyCodeDTO.getTelephone())
                .eq(SmsVerifyCodeDO::getVerifyCode, verifyCodeDTO.getVerifyCode())
                .gt(SmsVerifyCodeDO::getCreateDate, LocalDateTime.now().minusMinutes(30L)));

        if (null == smsCodeDO || !verifyCodeDTO.getVerifyCode().equals(smsCodeDO.getVerifyCode())) {
            throw new HttpException(70010);
        }

        return ConstantUtils.SUCCESS_VERIFY;
    }

    public String updateTelephone(UpdateTelephoneDTO updateTelephoneDTO) {

        SmsVerifyCodeDO smsCodeDO = smsVerifyCodeMapper.selectOne(new QueryWrapper<SmsVerifyCodeDO>()
                .lambda()
                .eq(SmsVerifyCodeDO::getTelephone, updateTelephoneDTO.getTelephone())
                .eq(SmsVerifyCodeDO::getVerifyCode, updateTelephoneDTO.getVerifyCode())
                .gt(SmsVerifyCodeDO::getCreateDate, LocalDateTime.now().minusMinutes(30L)));

        if (null == smsCodeDO || !updateTelephoneDTO.getVerifyCode().equals(smsCodeDO.getVerifyCode())) {
            throw new HttpException(70010);
        }

        MemberDO memberDO = memberMapper.selectById(updateTelephoneDTO.getId());
        memberDO.setTelephone(updateTelephoneDTO.getTelephone());
        memberMapper.updateById(memberDO);

        return ConstantUtils.SUCCESS_UPDATE;
    }

    public IdCardInfoVO idCardInfo(MemberDO memberDO) {
        IdCardInfoVO idCardInfoVO = new IdCardInfoVO();
        MemberDO memberDO1 = memberMapper.selectById(memberDO.getId());
        idCardInfoVO.setIdCard(memberDO1.getIdCard());
        idCardInfoVO.setUserName(memberDO1.getUserName());
        return idCardInfoVO;
    }

    public BankInfoVO bankInfo(MemberDO memberDO) {
        BankInfoVO bankInfoVO = new BankInfoVO();
        MemberDO memberDO1 = memberMapper.selectById(memberDO.getId());
        bankInfoVO.setPayrollAccount(memberDO1.getPayrollAccount());
        bankInfoVO.setUserName(memberDO1.getUserName());
        bankInfoVO.setBank(memberDO1.getBank());
        return bankInfoVO;
    }

    public SalaryListSumVO salaryListSum(SalaryListSumDTO salaryListSumDTO) {
涂亚平 committed
199
        return projectSalaryHistoryMapper.salaryCount(salaryListSumDTO.getProjectMappingId(), salaryListSumDTO.getMemberId());
涂亚平 committed
200 201 202 203
    }

    public IPage<SalaryListVO> salaryList(SalaryListSumDTO salaryListSumDTO) {
        Page page = new Page(salaryListSumDTO.getPageNum(), salaryListSumDTO.getPageSize());
涂亚平 committed
204
        return projectSalaryHistoryMapper.salaryList(page, salaryListSumDTO.getProjectMappingId(), salaryListSumDTO.getMemberId());
涂亚平 committed
205 206
    }

涂亚平 committed
207 208 209 210 211 212 213
    public void updateUserInfo(MemberDO memberDO) {

        MemberDO memberDO1 = memberMapper.selectById(memberDO.getId());
        BeanUtils.copyProperties(memberDO,memberDO1);
        memberMapper.updateById(memberDO);

    }
涂亚平 committed
214 215

}