package com.iailab.module.data.http.service.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.iailab.module.data.common.utils.HttpsRequest; import com.iailab.framework.common.page.PageData; import com.iailab.framework.common.service.impl.BaseServiceImpl; import com.iailab.module.data.http.dao.HttpTokenDao; import com.iailab.module.data.http.entity.HttpTokenEntity; import com.iailab.module.data.http.service.HttpTokenService; import org.apache.commons.lang3.StringUtils; import javax.annotation.Resource; import org.springframework.stereotype.Service; import java.util.Date; import java.util.HashMap; import java.util.Map; @Service public class HttpTokenServiceImpl extends BaseServiceImpl implements HttpTokenService { @Resource private HttpsRequest httpsRequest; @Override public PageData page(Map params) { IPage page = baseDao.selectPage( getPage(params, "client_id", false), getWrapper(params) ); return getPageData(page, HttpTokenEntity.class); } private QueryWrapper getWrapper(Map params){ String clientId = (String)params.get("clientId"); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(clientId), "client_id", clientId); return wrapper; } @Override public HttpTokenEntity getByApiId(String apiId) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(apiId), "api_id", apiId); return baseDao.selectOne(wrapper); } @Override public void updateToken(String clientId) { Map params = new HashMap<>(1); params.put("timeout", "30000"); HttpTokenEntity entity = baseDao.selectOne(new QueryWrapper().eq("client_id", clientId)); Map dataJson = new HashMap<>(2); String url = entity.getLoginUrl(); String userName = entity.getUsername(); String password = entity.getPassword(); String prvsetName = entity.getPrvsetName(); String projectName = entity.getProjectName(); String platform = entity.getPlatform(); dataJson.put("username", userName); dataJson.put("password", password); dataJson.put("prvset_name", prvsetName); dataJson.put("project_name", projectName); dataJson.put("platform", platform); //查询token的请求 String responseStr = httpsRequest.doPostToken(url, params, JSONObject.toJSONString(dataJson), "utf-8"); //插入token和更新时间 entity.setToken(responseStr); entity.setUpdateTime(new Date()); baseDao.update(entity, new QueryWrapper().eq("client_id", clientId)); } @Override public String queryToken(String clientId) { return baseDao.selectOne(new QueryWrapper().eq("client_id", clientId)).getToken(); } }