Blame view

ProjectServiceImpl.java 6.55 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 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 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 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
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;
    }

    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);

        return userRoleVO;
    }

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

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

    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) {
        return projectSalaryHistoryMapper.salaryCount(salaryListSumDTO.getProjectId(), salaryListSumDTO.getMemberId());
    }

    public IPage<SalaryListVO> salaryList(SalaryListSumDTO salaryListSumDTO) {
        Page page = new Page(salaryListSumDTO.getPageNum(), salaryListSumDTO.getPageSize());
        return projectSalaryHistoryMapper.salaryList(page, salaryListSumDTO.getProjectId(), salaryListSumDTO.getMemberId());
    }


}