Commit c880dc07223ea5def3ec36e1257f64bcc30928fd
1 parent
5ab2f5ee
fix: 新增日志,新增请求token任务
Showing
9 changed files
with
110 additions
and
20 deletions
ruoyi-admin/src/main/java/com/ruoyi/in/service/impl/SignInServiceImpl.java
| ... | ... | @@ -164,6 +164,7 @@ public class SignInServiceImpl implements ISignInService { |
| 164 | 164 | SignInResponseVo vo = new SignInResponseVo(); |
| 165 | 165 | vo.setAddress(equipment.getAddress()); |
| 166 | 166 | vo.setDeviceId(signIn.getDeviceId()); |
| 167 | + System.out.println("返回数据:" + vo.toString()); | |
| 167 | 168 | return SIGN_IN_SUCCESS.equals(signIn.getStatus()) ? AjaxResult.success(SIGN_IN_SUCCESS_STRING,vo) : AjaxResult.error(SIGN_IN_ERROR + signIn.getRemark(),vo); |
| 168 | 169 | } |
| 169 | 170 | ... | ... |
ruoyi-admin/src/main/java/com/ruoyi/job/DriverJob.java
| ... | ... | @@ -4,14 +4,17 @@ import com.ruoyi.common.core.redis.RedisCache; |
| 4 | 4 | import com.ruoyi.driver.domain.Driver; |
| 5 | 5 | import com.ruoyi.driver.service.IDriverService; |
| 6 | 6 | import com.ruoyi.pojo.response.ResponseScheduling; |
| 7 | +import com.ruoyi.pojo.response.TokenResponseVo; | |
| 7 | 8 | import com.ruoyi.utils.ConstDateUtil; |
| 8 | 9 | import com.ruoyi.utils.ListUtils; |
| 9 | 10 | import org.springframework.beans.factory.InitializingBean; |
| 10 | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | 12 | import org.springframework.beans.factory.annotation.Value; |
| 12 | 13 | import org.springframework.core.ParameterizedTypeReference; |
| 13 | -import org.springframework.http.HttpMethod; | |
| 14 | +import org.springframework.http.*; | |
| 14 | 15 | import org.springframework.stereotype.Component; |
| 16 | +import org.springframework.util.LinkedMultiValueMap; | |
| 17 | +import org.springframework.util.MultiValueMap; | |
| 15 | 18 | import org.springframework.web.client.RestTemplate; |
| 16 | 19 | |
| 17 | 20 | import javax.annotation.Resource; |
| ... | ... | @@ -42,6 +45,16 @@ public class DriverJob implements InitializingBean { |
| 42 | 45 | @Value("${api.url.getDriverInfo}") |
| 43 | 46 | private String getDriverInfoUrl; |
| 44 | 47 | |
| 48 | + | |
| 49 | + @Value("${api.personnel.token.tokenUrl}") | |
| 50 | + private String tokenUrl; | |
| 51 | + | |
| 52 | + @Value("${api.personnel.token.appKey}") | |
| 53 | + private String appKey; | |
| 54 | + | |
| 55 | + @Value("${api.personnel.token.appSecret}") | |
| 56 | + private String appSecret; | |
| 57 | + | |
| 45 | 58 | @Value("${api.url.getSchedulingInfo}") |
| 46 | 59 | private String getSchedulingInfoUrl; |
| 47 | 60 | |
| ... | ... | @@ -51,6 +64,9 @@ public class DriverJob implements InitializingBean { |
| 51 | 64 | @Value("${api.config.nonce}") |
| 52 | 65 | private String nonce; |
| 53 | 66 | |
| 67 | + private static String APP_KEY; | |
| 68 | + private static String TOKEN_URL; | |
| 69 | + private static String APP_SECRET; | |
| 54 | 70 | private static IDriverService DRIVER_SERVICE; |
| 55 | 71 | private static RedisCache REDIS_CACHE; |
| 56 | 72 | private static RestTemplate RESTTEMPLATE; |
| ... | ... | @@ -70,7 +86,7 @@ public class DriverJob implements InitializingBean { |
| 70 | 86 | String getDriverInfoUrl = String.format(GET_DRIVER_INFO_URL, params); |
| 71 | 87 | long timestamp = System.currentTimeMillis(); |
| 72 | 88 | // 获取驾驶员信息 |
| 73 | - List<Driver> drivers = getDrivers(getDriverInfoUrl, String.valueOf(timestamp)); | |
| 89 | + List<Driver> drivers = getDrivers(APP_SECRET, String.valueOf(timestamp)); | |
| 74 | 90 | // 格式化请求 |
| 75 | 91 | String getSchedulingInfoUrl = String.format(GET_SCHEDULING_INFO_URL, "99", ConstDateUtil.formatDate("yyyyMMdd"), timestamp, NONCE, PASSWORD, getSHA1(getStringStringMap(String.valueOf(timestamp)))); |
| 76 | 92 | // 获取排班信息并存入redis |
| ... | ... | @@ -89,6 +105,11 @@ public class DriverJob implements InitializingBean { |
| 89 | 105 | } |
| 90 | 106 | |
| 91 | 107 | /** |
| 108 | + * 获取员工数据 | |
| 109 | + */ | |
| 110 | + | |
| 111 | + | |
| 112 | + /** | |
| 92 | 113 | * 导入图片任务 |
| 93 | 114 | */ |
| 94 | 115 | public void importImages(){ |
| ... | ... | @@ -131,25 +152,30 @@ public class DriverJob implements InitializingBean { |
| 131 | 152 | return driverSchedulingMap; |
| 132 | 153 | } |
| 133 | 154 | |
| 134 | - private List<Driver> getDrivers(String format, String timestamp) throws Exception { | |
| 155 | + private List<Driver> getDrivers(String url, String timestamp) throws Exception { | |
| 135 | 156 | Map<String, String> configMap = getStringStringMap(timestamp); |
| 136 | 157 | String sign = getSHA1(configMap); |
| 137 | - String url = format | |
| 138 | - + "?timestamp=" + timestamp | |
| 139 | - + "&nonce=" + NONCE | |
| 140 | - + "&password=" + PASSWORD | |
| 141 | - + "&sign=" + sign; | |
| 142 | 158 | //生成签名 |
| 143 | - List<Driver> drivers = RESTTEMPLATE.exchange( | |
| 144 | - url, | |
| 145 | - HttpMethod.GET, | |
| 146 | - null, | |
| 147 | - new ParameterizedTypeReference<List<Driver>>() { | |
| 148 | - }).getBody().stream().map(item ->{ | |
| 149 | - item.setJobCode(item.getJobCode().split("-")[1]); | |
| 150 | - return item; | |
| 151 | - }).collect(Collectors.toList()); | |
| 152 | - return drivers; | |
| 159 | + TokenResponseVo tokenVo = getToken(url); | |
| 160 | +// redisCache.setCacheObject(); | |
| 161 | +// getPersonInfo(tokenVo); | |
| 162 | +// return drivers; | |
| 163 | + return null; | |
| 164 | + } | |
| 165 | + | |
| 166 | + private TokenResponseVo getToken(String url) { | |
| 167 | + MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); | |
| 168 | + params.add("appSecret", APP_SECRET); | |
| 169 | + params.add("appKey", APP_KEY); | |
| 170 | + // 设置请求头 | |
| 171 | + HttpHeaders headers = new HttpHeaders(); | |
| 172 | + headers.setContentType(MediaType.APPLICATION_JSON); | |
| 173 | + // 创建HttpEntity对象 | |
| 174 | + HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(params, headers); | |
| 175 | + | |
| 176 | + // 发送POST请求 | |
| 177 | + ResponseEntity<TokenResponseVo> responseEntity = restTemplate.postForEntity(url, requestEntity, TokenResponseVo.class); | |
| 178 | + return responseEntity.getBody(); | |
| 153 | 179 | } |
| 154 | 180 | |
| 155 | 181 | public Map<String, String> getStringStringMap(String timestamp) { |
| ... | ... | @@ -229,5 +255,9 @@ public class DriverJob implements InitializingBean { |
| 229 | 255 | DRIVER_SERVICE = driverService; |
| 230 | 256 | REDIS_CACHE = redisCache; |
| 231 | 257 | GET_SCHEDULING_INFO_URL = getSchedulingInfoUrl; |
| 258 | + | |
| 259 | + TOKEN_URL = tokenUrl; | |
| 260 | + APP_KEY = appKey; | |
| 261 | + APP_SECRET = appSecret; | |
| 232 | 262 | } |
| 233 | 263 | } | ... | ... |
ruoyi-admin/src/main/java/com/ruoyi/pojo/request/TokenRequestVo.java
0 → 100644
ruoyi-admin/src/main/java/com/ruoyi/pojo/response/SignInResponseVo.java
| ... | ... | @@ -10,4 +10,12 @@ import lombok.Data; |
| 10 | 10 | public class SignInResponseVo { |
| 11 | 11 | String address; |
| 12 | 12 | String deviceId; |
| 13 | + | |
| 14 | + @Override | |
| 15 | + public String toString() { | |
| 16 | + return "SignInResponseVo{" + | |
| 17 | + "address='" + address + '\'' + | |
| 18 | + ", deviceId='" + deviceId + '\'' + | |
| 19 | + '}'; | |
| 20 | + } | |
| 13 | 21 | } | ... | ... |
ruoyi-admin/src/main/java/com/ruoyi/pojo/response/TokenResponseVo.java
0 → 100644
| 1 | +package com.ruoyi.pojo.response; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * token接收 | |
| 7 | + * @author 20412 | |
| 8 | + */ | |
| 9 | +@Data | |
| 10 | +public class TokenResponseVo { | |
| 11 | + /** | |
| 12 | + * 生成的accessToken(此Token仅用于获取员工数据及获取临时照片下载地址) | |
| 13 | + */ | |
| 14 | + String accessToken; | |
| 15 | + /** | |
| 16 | + * :accessToken的有效期为7200秒(2小时) | |
| 17 | + */ | |
| 18 | + Long expireIn; | |
| 19 | +} | ... | ... |
ruoyi-admin/src/main/resources/application-druid-dev.yml
| ... | ... | @@ -144,4 +144,7 @@ api: |
| 144 | 144 | nonce: adfsad |
| 145 | 145 | apk: |
| 146 | 146 | path: /apk/dev/ |
| 147 | - | |
| 147 | + personnel: | |
| 148 | + tokenUrl: https://api.dingtalk.com/v1.0/oauth2/accessToken | |
| 149 | + appKey: dingsclwvxui5zilg1xk | |
| 150 | + appSecret: ckV20k3jMKJpUkfXXSGhLk077rQQjsSaAusiSVY-nm4glwweCmb_SMJ62Cpf4YQ5 | |
| 148 | 151 | \ No newline at end of file | ... | ... |
ruoyi-admin/src/main/resources/application-druid-prd.yml
| ... | ... | @@ -104,3 +104,7 @@ api: |
| 104 | 104 | nonce: adfsad |
| 105 | 105 | apk: |
| 106 | 106 | path: /apk/dev/ |
| 107 | + personnel: | |
| 108 | + tokenUrl: https://api.dingtalk.com/v1.0/oauth2/accessToken | |
| 109 | + appKey: dingsclwvxui5zilg1xk | |
| 110 | + appSecret: ckV20k3jMKJpUkfXXSGhLk077rQQjsSaAusiSVY-nm4glwweCmb_SMJ62Cpf4YQ5 | |
| 107 | 111 | \ No newline at end of file | ... | ... |
ruoyi-admin/src/main/resources/application-druid-uat.yml
| ... | ... | @@ -164,3 +164,10 @@ api: |
| 164 | 164 | nonce: adfsad |
| 165 | 165 | apk: |
| 166 | 166 | path: /apk/dev/ |
| 167 | + personnel: | |
| 168 | + token: | |
| 169 | + tokenUrl: https://api.dingtalk.com/v1.0/oauth2/accessToken | |
| 170 | + appKey: dingsclwvxui5zilg1xk | |
| 171 | + appSecret: ckV20k3jMKJpUkfXXSGhLk077rQQjsSaAusiSVY-nm4glwweCmb_SMJ62Cpf4YQ5 | |
| 172 | + personnel: | |
| 173 | + url: https://api.dingtalk.com/v1.0/yida/forms/instances/search | |
| 167 | 174 | \ No newline at end of file | ... | ... |
ruoyi-admin/src/main/resources/application.yml
| ... | ... | @@ -146,4 +146,8 @@ api: |
| 146 | 146 | config: |
| 147 | 147 | password: c4dd3d8cb9a82f6d6a625818618b28ca7bebb464 |
| 148 | 148 | # 随机字符串 |
| 149 | - nonce: adfsad | |
| 150 | 149 | \ No newline at end of file |
| 150 | + nonce: adfsad | |
| 151 | + personnel: | |
| 152 | + tokenUrl: https://api.dingtalk.com/v1.0/oauth2/accessToken | |
| 153 | + appKey: dingsclwvxui5zilg1xk | |
| 154 | + appSecret: ckV20k3jMKJpUkfXXSGhLk077rQQjsSaAusiSVY-nm4glwweCmb_SMJ62Cpf4YQ5 | ... | ... |