Blame view

AdministerServiceImpl.java 3.74 KB
涂亚平 committed
1 2 3 4 5
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;
涂亚平 committed
6 7
import com.subsidy.common.constant.Platform;
import com.subsidy.common.constant.SmsCode;
涂亚平 committed
8
import com.subsidy.common.exception.HttpException;
涂亚平 committed
9 10 11 12
import com.subsidy.dto.administer.AdministerPageDTO;
import com.subsidy.dto.administer.LoginDTO;
import com.subsidy.mapper.PermissionsMapper;
import com.subsidy.mapper.SmsVerifyCodeMapper;
涂亚平 committed
13 14
import com.subsidy.model.AdministerDO;
import com.subsidy.mapper.AdministerMapper;
涂亚平 committed
15
import com.subsidy.model.SmsVerifyCodeDO;
涂亚平 committed
16 17
import com.subsidy.service.AdministerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
涂亚平 committed
18
import com.subsidy.service.PermissionsService;
涂亚平 committed
19
import com.subsidy.util.JwtUtil;
涂亚平 committed
20 21
import com.subsidy.vo.administer.AdministerVO;
import com.subsidy.vo.administer.PermissionVO;
涂亚平 committed
22 23 24 25 26 27 28 29 30
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
涂亚平 committed
31
 * 中心管理账户表 服务实现类
涂亚平 committed
32 33 34
 * </p>
 *
 * @author Tuyp
涂亚平 committed
35
 * @since 2025-01-08
涂亚平 committed
36 37 38 39 40
 */
@Service
public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, AdministerDO> implements AdministerService {

    @Autowired
涂亚平 committed
41
    private SmsVerifyCodeMapper smsVerifyCodeMapper;
涂亚平 committed
42

涂亚平 committed
43 44 45 46 47 48 49 50 51
    @Autowired
    private PermissionsMapper permissionsMapper;

    @Override
    public AdministerVO login(LoginDTO loginDTO) {
        AdministerVO administerVO = new AdministerVO();
        SmsVerifyCodeDO smsCodeDO = smsVerifyCodeMapper.getOneByTelePhone(loginDTO.getTelephone(), SmsCode.login, SmsCode.center);
        if (smsCodeDO == null) {
            throw new HttpException(10025);
涂亚平 committed
52 53
        }

涂亚平 committed
54 55 56
        if (!smsCodeDO.getVerifyCode().equals(loginDTO.getCode())) {
            throw new HttpException(10021);
        }
涂亚平 committed
57

涂亚平 committed
58
        smsVerifyCodeMapper.deleteById(smsCodeDO.getId());
涂亚平 committed
59 60 61

        AdministerDO administerDO = this.baseMapper.selectOne(new QueryWrapper<AdministerDO>()
                .lambda()
涂亚平 committed
62
                .eq(AdministerDO::getTelephone, loginDTO.getTelephone()));
涂亚平 committed
63
        if (administerDO == null) {
涂亚平 committed
64
            throw new HttpException(10060);
涂亚平 committed
65 66
        }

涂亚平 committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
        BeanUtils.copyProperties(administerDO, administerVO);
        String token = JwtUtil.generateToken(administerDO.getId(), Platform.center);
        administerVO.setToken(token);

        List<PermissionVO> list = permissionsMapper.getPermissionById(administerDO.getId());
        List<PermissionVO> treeList = new ArrayList();
        list.forEach(permissions -> {
            if (permissions.getParentId() == null) {
                treeList.add(permissions);
            }

            list.forEach(p -> {
                if (p.getParentId() != null) {
                    if (p.getParentId().equals(permissions.getId())) {
                        if (permissions.getChildNodeList() == null) {
                            permissions.setChildNodeList(new ArrayList<>());
涂亚平 committed
83
                        }
涂亚平 committed
84
                        permissions.getChildNodeList().add(p);
涂亚平 committed
85
                    }
涂亚平 committed
86
                }
涂亚平 committed
87
            });
涂亚平 committed
88 89 90 91
        });
        administerVO.setPermission(treeList);
        return administerVO;
    }
涂亚平 committed
92

涂亚平 committed
93 94 95 96 97 98 99
    @Override
    public IPage getAdministerPage(AdministerPageDTO administerPageDTO) {
        Page page = new Page(administerPageDTO.getPageNum(), administerPageDTO.getPageSize());
        return this.baseMapper.selectPage(page, new QueryWrapper<AdministerDO>()
                .lambda()
                .eq(AdministerDO::getRole, administerPageDTO.getListItem())
                .like(AdministerDO::getUsername, administerPageDTO.getUsername()));
涂亚平 committed
100 101 102
    }

}