package com.iailab.module.data.channel.http.service.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.iailab.framework.common.pojo.PageResult; import com.iailab.module.data.channel.http.dao.HttpTokenDao; import com.iailab.module.data.channel.http.entity.HttpTokenEntity; import com.iailab.module.data.channel.http.service.HttpTokenService; import com.iailab.module.data.channel.http.vo.HttpTokenPageReqVO; import com.iailab.module.data.common.utils.HttpsRequest; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class HttpTokenServiceImpl extends ServiceImpl implements HttpTokenService { @Resource private HttpsRequest httpsRequest; @Resource private HttpTokenDao httpTokenDao; @Override public PageResult queryPage(HttpTokenPageReqVO reqVO) { return httpTokenDao.selectPage(reqVO); } @Override public HttpTokenEntity info(String id) { return httpTokenDao.selectById(id); } @Override public void add(HttpTokenEntity httpTokenEntity) { httpTokenDao.insert(httpTokenEntity); } @Override public void update(HttpTokenEntity httpTokenEntity) { httpTokenDao.updateById(httpTokenEntity); } @Override public void delete(String id) { httpTokenDao.deleteById(id); } @Override public List list() { return httpTokenDao.selectList(new QueryWrapper<>()); } @Override public HttpTokenEntity getByApiId(String apiId) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(apiId), "api_id", apiId); return httpTokenDao.selectOne(wrapper); } @Override public void updateToken(String clientId) { Map params = new HashMap<>(1); params.put("timeout", "30000"); HttpTokenEntity entity = httpTokenDao.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()); httpTokenDao.update(entity, new QueryWrapper().eq("client_id", clientId)); } @Override public String queryToken(String clientId) { return httpTokenDao.selectOne(new QueryWrapper().eq("client_id", clientId)).getToken(); } }