ProjectServiceImpl.java 7.82 KB
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 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;
    }

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

        if (null != verifyCodeDTO.getOpenId()){
            memberDO.setOpenId(verifyCodeDTO.getOpenId());
            memberMapper.updateById(memberDO);
        }

        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.getProjectMappingId(), salaryListSumDTO.getMemberId());
    }

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

    public void updateUserInfo(MemberDO memberDO) {

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

    }

}