AdministerServiceImpl.java 5.8 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.ChangeServiceDTO;
import com.subsidy.mapper.LaborGroupDictMapper;
import com.subsidy.mapper.LaborServiceDictMapper;
import com.subsidy.mapper.ServiceDictMapper;
import com.subsidy.model.AdministerDO;
import com.subsidy.mapper.AdministerMapper;
import com.subsidy.model.LaborServiceDictDO;
import com.subsidy.model.ServiceDictDO;
import com.subsidy.service.AdministerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 管理平台用户 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2024-07-18
 */
@Service
public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, AdministerDO> implements AdministerService {

    @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());
        }
    }


}