Blame view

AdministerServiceImpl.java 5.8 KB
涂亚平 committed
1 2
package com.subsidy.service.impl;

涂亚平 committed
3 4 5 6 7 8 9 10
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.ChangeServiceDTO;
import com.subsidy.mapper.LaborGroupDictMapper;
import com.subsidy.mapper.LaborServiceDictMapper;
import com.subsidy.mapper.ServiceDictMapper;
涂亚平 committed
11 12
import com.subsidy.model.AdministerDO;
import com.subsidy.mapper.AdministerMapper;
涂亚平 committed
13 14
import com.subsidy.model.LaborServiceDictDO;
import com.subsidy.model.ServiceDictDO;
涂亚平 committed
15 16
import com.subsidy.service.AdministerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
涂亚平 committed
17 18 19 20 21 22 23 24 25 26 27 28
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.JwtUtil;
import com.subsidy.util.Localstorage;
import com.subsidy.util.SecretUtils;
import com.subsidy.vo.administer.AdministerPermissionVO;
import com.subsidy.vo.administer.AuthVO;
import com.subsidy.vo.administer.PermissionsVO;
import com.subsidy.vo.labor.LoginVO;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.CloseableHttpClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
涂亚平 committed
29 30
import org.springframework.stereotype.Service;

涂亚平 committed
31 32 33
import java.util.ArrayList;
import java.util.List;

涂亚平 committed
34 35 36 37 38 39 40 41 42 43 44
/**
 * <p>
 * 管理平台用户 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2024-07-18
 */
@Service
public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, AdministerDO> implements AdministerService {

涂亚平 committed
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
    @Autowired
    private LaborServiceDictMapper laborServiceDictMapper;

    public LoginVO login(AdministerDO administerDO) {

        LoginVO loginVO = new LoginVO();

        List<Integer> integers = new ArrayList<>();
        integers.add(0);
        integers.add(6);
        integers.add(7);

        AdministerDO administerDO1 = this.baseMapper.selectOne(new QueryWrapper<AdministerDO>()
                .lambda()
                .eq(AdministerDO::getAccountName, administerDO.getAccountName())
                .in(AdministerDO::getRole, integers));

        if (null == administerDO1) {
            throw new HttpException(10012);
        }

        if ("0".equals(administerDO1.getStatus())) {
            throw new HttpException(10013);
        }

        if (administerDO1.getPassword().equals(administerDO.getPassword())) {
            String token = JwtUtil.generateToken(administerDO1.getId(), ConstantUtils.ADMINISTER_TERMINATE);
            loginVO.setToken(token);
            return loginVO;
        }else {
            throw new HttpException(10029);
        }
    }


    public AdministerPermissionVO getPermissions() {

        AdministerPermissionVO administerPermissionVO = new AdministerPermissionVO();
        AdministerDO administerDO = (AdministerDO) Localstorage.getUser();
        if (administerDO == null) {
            throw new HttpException(10012);
        }
        BeanUtils.copyProperties(administerDO, administerPermissionVO);

        List<PermissionsVO> list = this.baseMapper.getPermissions(administerDO.getId());
        List<PermissionsVO> treeList = new ArrayList();
        if (list != null) {
            list.forEach(permission -> {
                if (permission.getParentId() == null) {
                    treeList.add(permission);
                }

                list.forEach(p -> {
                    if (null != p.getParentId() && p.getParentId().equals(permission.getId())) {
                        if (permission.getChildren() == null) {
                            permission.setChildren(new ArrayList<>());
                        }
                        permission.getChildren().add(p);
                    }
                });
            });
        }
        administerPermissionVO.setPermissions(treeList);
        administerPermissionVO.setTelephone(administerDO.getTelephone());
        administerPermissionVO.setAccountName(administerDO.getAccountName());

        return administerPermissionVO;
    }

    public AuthVO auth(AdministerDO administerDO){

        CloseableHttpClient client = null;
        CloseableHttpResponse response = null;
        String resValue = "";

//        long timestamp = System.currentTimeMillis();
//        String nonce = SecretUtils.getNonce(5);
//        String appId = subsidyConfig.getAppId();
//
//        String appKey = subsidyConfig.getSecurityKey();
//        String accountName = administerDO.getAccountName();

        //鉴权逻辑 对不对
        String preAuthen = "appId=qxywz5nnWMI7ABCS"
                +"&id="+administerDO.getId()
                +"&accountName="+administerDO.getAccountName()
                + "&appSecret=626737T1-65K0-5xC2-0Y0V-2Aq9QUAJ";


        String signature = SecretUtils.getMD5String(preAuthen);
        try {
            AuthVO qxyVO = new AuthVO();
            qxyVO.setToken(signature);
            return qxyVO;
//            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new AuthVO();
    }

    public IPage<LaborServiceDictDO> changeService(ChangeServiceDTO changeServiceDTO) {
        Page pager = new Page(changeServiceDTO.getPageNum(), changeServiceDTO.getPageSize());
        AdministerDO administerDO = this.baseMapper.selectById(changeServiceDTO.getId());
        if (6 == administerDO.getRole()){
            return laborServiceDictMapper.selectPage(pager,new QueryWrapper<LaborServiceDictDO>()
                    .lambda()
                    .eq(LaborServiceDictDO::getId,administerDO.getLaborId()));
        }else if (0== administerDO.getRole()){
            return laborServiceDictMapper.selectPage(pager,null);
        }
        else {
            return this.baseMapper.administerLabors(pager,changeServiceDTO.getId(),changeServiceDTO.getLaborServiceName());
        }
    }


涂亚平 committed
162
}