From 6deba7d989333982aed3342a71aedfeff8b4cb56 Mon Sep 17 00:00:00 2001 From: wu Date: Fri, 5 Jul 2024 15:39:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0token=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mudu/quartz/AcheckTaskQuartz.java | 89 ++++++++++++++++--- .../java/com/mudu/quartz/BqbhTszyQuartz.java | 23 +++-- .../com/mudu/service/impl/LoginService.java | 17 ++++ .../mudu/service/impl/LoginServiceImpl.java | 38 ++++++++ src/main/resources/application-dev.yml | 2 +- src/main/resources/application.yml | 4 +- 6 files changed, 153 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/mudu/service/impl/LoginService.java create mode 100644 src/main/java/com/mudu/service/impl/LoginServiceImpl.java diff --git a/src/main/java/com/mudu/quartz/AcheckTaskQuartz.java b/src/main/java/com/mudu/quartz/AcheckTaskQuartz.java index 7cec138..30004b5 100644 --- a/src/main/java/com/mudu/quartz/AcheckTaskQuartz.java +++ b/src/main/java/com/mudu/quartz/AcheckTaskQuartz.java @@ -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)) { diff --git a/src/main/java/com/mudu/quartz/BqbhTszyQuartz.java b/src/main/java/com/mudu/quartz/BqbhTszyQuartz.java index d662648..27924df 100644 --- a/src/main/java/com/mudu/quartz/BqbhTszyQuartz.java +++ b/src/main/java/com/mudu/quartz/BqbhTszyQuartz.java @@ -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)) { diff --git a/src/main/java/com/mudu/service/impl/LoginService.java b/src/main/java/com/mudu/service/impl/LoginService.java new file mode 100644 index 0000000..bb87170 --- /dev/null +++ b/src/main/java/com/mudu/service/impl/LoginService.java @@ -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(); +} diff --git a/src/main/java/com/mudu/service/impl/LoginServiceImpl.java b/src/main/java/com/mudu/service/impl/LoginServiceImpl.java new file mode 100644 index 0000000..fb5b8cc --- /dev/null +++ b/src/main/java/com/mudu/service/impl/LoginServiceImpl.java @@ -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 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"); + } +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index ff753e2..c9d2295 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -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 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7013f18..8b6e6f2 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,5 +3,5 @@ server: spring: profiles: active: prod - - +#获取token +getToken: http://221.229.220.83:9028/loginnocaptcha \ No newline at end of file