添加token校验

main
吴顺杰 8 months ago
parent a4e200c09e
commit 6deba7d989

@ -5,12 +5,41 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.mudu.entity.*;
import com.mudu.entity.ACheckQuatzEntity;
import com.mudu.entity.ACheckQuatzZichaEntity;
import com.mudu.entity.ASafeQyjcxx;
import com.mudu.entity.ASafeRwfj;
import com.mudu.entity.ASafeRwzq;
import com.mudu.entity.ASafeTfg;
import com.mudu.entity.ASafeTfgsh;
import com.mudu.entity.ASafeXcrw;
import com.mudu.entity.ASafeXcrwjcx;
import com.mudu.entity.ASafeXcrwjcxzgxx;
import com.mudu.entity.ASafeXcrwwz;
import com.mudu.entity.ASafeYhzgxx;
import com.mudu.entity.ASafeZcrw;
import com.mudu.entity.ASafeZcrwjl;
import com.mudu.entity.ASafeZcrwwz;
import com.mudu.entity.SzsASafeZcyhxx;
import com.mudu.entity.dto.request.ACheckQuatzRequest;
import com.mudu.entity.dto.request.ACheckQuatzZichaRequest;
import com.mudu.entity.dto.response.ACheckXcTpResponse;
import com.mudu.entity.dto.response.RwzqUuidResponse;
import com.mudu.service.*;
import com.mudu.service.ASafeQyjcxxService;
import com.mudu.service.ASafeRwfjService;
import com.mudu.service.ASafeRwzqService;
import com.mudu.service.ASafeTfgService;
import com.mudu.service.ASafeTfgshService;
import com.mudu.service.ASafeXcrwService;
import com.mudu.service.ASafeXcrwjcxService;
import com.mudu.service.ASafeXcrwjcxzgxxService;
import com.mudu.service.ASafeXcrwwzService;
import com.mudu.service.ASafeYhzgxxService;
import com.mudu.service.ASafeZcrwService;
import com.mudu.service.ASafeZcrwjlService;
import com.mudu.service.ASafeZcrwwzService;
import com.mudu.service.SzsASafeZcyhxxService;
import com.mudu.service.impl.LoginService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
@ -88,9 +117,13 @@ public class AcheckTaskQuartz {
@Resource
private ASafeTfgshService aSafeTfgshService;
@Resource
private ASafeRwzqService aSafeRwzqService;
@Resource
private LoginService loginService;
@Value("${improveUrl}")
private String url;
@ -115,17 +148,28 @@ public class AcheckTaskQuartz {
@Value("${tfgUrl}")
private String tfgUrl;
/**
* token
*/
private String token;
private void getToken() {
token = "Bearer " + loginService.getToken();
}
/**
*
*
* @Param qymc
*/
@Scheduled(cron = "0 0 4 * * ? ")
// @Scheduled(cron = "0 0 4 * * ? ")
// @Scheduled(cron = "0 0/5 * * * ?")
// @PostMapping("/insert")
// @ApiOperation(value = "新增创建时间为昨天且处于审批通过的工单数据")
public void selectAll() throws ParseException {
// 获取token
getToken();
// todo 查询巡查任务主表2月是否有记录就不推
Integer xcrwNum = aSafeXcrwService.xcrwNum();
if (xcrwNum > 0) {
@ -134,7 +178,10 @@ public class AcheckTaskQuartz {
//巡查任务周期id
RwzqUuidResponse rwzqUuidResponse = aSafeRwzqService.getXcUuid();
String rwzqUuid = rwzqUuidResponse.getXxbh();
String responseList = HttpRequest.post(imUrl).contentType("application/x-www-form-urlencoded;charset=UTF-8").execute().body();
String responseList = HttpRequest.post(imUrl)
.contentType("application/x-www-form-urlencoded;charset=UTF-8")
.header("Authorization", token)
.execute().body();
JSONObject jsonResponseList = JSON.parseObject(responseList);
String dataList = jsonResponseList.getString("data");
if (StrUtil.isEmpty(dataList)) {
@ -152,7 +199,11 @@ public class AcheckTaskQuartz {
JSONObject xcjsonObject = new JSONObject();
xcjsonObject.put("qybh", aSafeQyjcxx.getXxbh());
xcjsonObject.put("zqbh", rwzqUuid);
String xcresponse = HttpRequest.post(xczqUrl).contentType("application/x-www-form-urlencoded;charset=UTF-8").body(xcjsonObject.toJSONString()).execute().body();
String xcresponse = HttpRequest.post(xczqUrl)
.contentType("application/x-www-form-urlencoded;charset=UTF-8")
.header("Authorization", token)
.body(xcjsonObject.toJSONString())
.execute().body();
JSONObject xcjsonResponse = JSON.parseObject(xcresponse);
if (xcjsonResponse.getString("msg") == null) {
continue;
@ -162,7 +213,11 @@ public class AcheckTaskQuartz {
//根据工单获取数据
JSONObject jsonObject = new JSONObject();
jsonObject.put("improvingNo", a.getImprovingNo());
String response = HttpRequest.post(url).contentType("application/x-www-form-urlencoded;charset=UTF-8").body(jsonObject.toJSONString()).execute().body();
String response = HttpRequest.post(url)
.contentType("application/x-www-form-urlencoded;charset=UTF-8")
.header("Authorization", token)
.body(jsonObject.toJSONString())
.execute().body();
JSONObject jsonResponse = JSON.parseObject(response);
// 提取数据
String data = jsonResponse.getString("data");
@ -603,7 +658,10 @@ public class AcheckTaskQuartz {
//自己查任务周期id
RwzqUuidResponse rwzqUuidResponse = aSafeRwzqService.getZcUuid();
String rwzqUuid = rwzqUuidResponse.getXxbh();
String responseList = HttpRequest.post(zcXxUrl).contentType("application/x-www-form-urlencoded;charset=UTF-8").execute().body();
String responseList = HttpRequest.post(zcXxUrl)
.contentType("application/x-www-form-urlencoded;charset=UTF-8")
.header("Authorization", token)
.execute().body();
JSONObject jsonResponseList = JSON.parseObject(responseList);
String dataList = jsonResponseList.getString("data");
if (StrUtil.isEmpty(dataList)) {
@ -617,7 +675,11 @@ public class AcheckTaskQuartz {
JSONObject zcjsonObject = new JSONObject();
zcjsonObject.put("qybh", a.getEnterpriseID());
zcjsonObject.put("zqbh", rwzqUuid);
String zcresponse = HttpRequest.post(zczqUrl).contentType("application/x-www-form-urlencoded;charset=UTF-8").body(zcjsonObject.toJSONString()).execute().body();
String zcresponse = HttpRequest.post(zczqUrl)
.contentType("application/x-www-form-urlencoded;charset=UTF-8")
.header("Authorization", token)
.body(zcjsonObject.toJSONString())
.execute().body();
JSONObject zcjsonResponse = JSON.parseObject(zcresponse);
if (zcjsonResponse.getString("msg") == null) {
continue;
@ -643,7 +705,11 @@ public class AcheckTaskQuartz {
//根据工单获取数据
JSONObject jsonObject = new JSONObject();
jsonObject.put("imageRelationID", b.getImgId());
String response = HttpRequest.post(zcUrl).contentType("application/x-www-form-urlencoded;charset=UTF-8").body(jsonObject.toJSONString()).execute().body();
String response = HttpRequest.post(zcUrl)
.contentType("application/x-www-form-urlencoded;charset=UTF-8")
.header("Authorization", token)
.body(jsonObject.toJSONString())
.execute().body();
JSONObject jsonResponse = JSON.parseObject(response);
// 提取数据
String data = jsonResponse.getString("data");
@ -974,7 +1040,10 @@ public class AcheckTaskQuartz {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currentTimeString = dateFormat.format(currentDate);
//停复工表推送
String responseList = HttpRequest.get(tfgUrl).header("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8").execute().body();
String responseList = HttpRequest.get(tfgUrl)
.contentType("application/x-www-form-urlencoded;charset=UTF-8")
.header("Authorization", token)
.execute().body();
JSONObject jsonResponseList = JSON.parseObject(responseList);
String dataList = jsonResponseList.getString("rows");
if (StrUtil.isEmpty(dataList)) {

@ -14,16 +14,12 @@ import com.mudu.entity.dto.request.ASafeQyzypglRequest;
import com.mudu.entity.dto.response.XcTpResponse;
import com.mudu.service.ASafeBqbhpxService;
import com.mudu.service.ASafeQyzypglService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mudu.service.impl.LoginService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.ArrayList;
@ -49,6 +45,9 @@ public class BqbhTszyQuartz {
@Resource
private ASafeQyzypglService safeQyzypglService;
@Resource
private LoginService loginService;
@Value("${bqbhUrl}")
private String bqbhUrl;
@ -58,6 +57,10 @@ public class BqbhTszyQuartz {
@Value("${api}")
private String api;
/**
* token
*/
private String token;
/**
*
@ -67,7 +70,10 @@ public class BqbhTszyQuartz {
@Scheduled(cron = "0 0 1 * * ? ")
// @Scheduled(cron = "0 0/5 * * * ?")
public void saveBqbh() {
String res = HttpRequest.get(bqbhUrl).contentType("application/x-www-form-urlencoded;charset=UTF-8").execute().body();
String res = HttpRequest.get(bqbhUrl)
.contentType("application/x-www-form-urlencoded;charset=UTF-8")
.header("Authorization", token)
.execute().body();
JSONObject resObj = JSON.parseObject(res);
String dataList = resObj.getString("data");
if (StrUtil.isEmpty(dataList)) {
@ -103,7 +109,10 @@ public class BqbhTszyQuartz {
@Scheduled(cron = "0 0 1 * * ? ")
// @Scheduled(cron = "0 0/5 * * * ?")
public void saveTszy() {
String res = HttpRequest.get(tszyUrl).contentType("application/x-www-form-urlencoded;charset=UTF-8").execute().body();
String res = HttpRequest.get(tszyUrl)
.contentType("application/x-www-form-urlencoded;charset=UTF-8")
.header("Authorization", token)
.execute().body();
JSONObject resObj = JSON.parseObject(res);
String dataList = resObj.getString("data");
if (StrUtil.isEmpty(dataList)) {

@ -0,0 +1,17 @@
package com.mudu.service.impl;
/**
*
*
* @author wu
* @since 2024/7/4 4:22
*/
public interface LoginService {
/**
* token
*
* @return token
*/
String getToken();
}

@ -0,0 +1,38 @@
package com.mudu.service.impl;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
*
*
* @author wu
* @since 2024/7/4 4:23
*/
@Service("LoginService")
public class LoginServiceImpl implements LoginService {
@Value("${getToken}")
private String getTokenUrl;
/**
* token
*
* @return token
*/
@Override
public String getToken() {
Map<String, Object> map = new HashMap<>();
map.put("username", "admin");
map.put("password", "Mudu@123.");
String body = JSONUtil.toJsonStr(map);
String responseList = HttpRequest.post(getTokenUrl).body(body)
.execute().body();
return (String) JSONUtil.parseObj(responseList).get("token");
}
}

@ -4,7 +4,7 @@ spring:
datasource:
url: jdbc:mysql://localhost:3306/mudu?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: adminadmin
password: 123456
#公司本地
# url: jdbc:mysql://localhost:3307/mudu?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: root

@ -3,5 +3,5 @@ server:
spring:
profiles:
active: prod
#获取token
getToken: http://221.229.220.83:9028/loginnocaptcha
Loading…
Cancel
Save