|
@@ -2,21 +2,27 @@ package com.kxs.product.biz.task;
|
|
|
|
|
|
|
|
import cn.hutool.crypto.symmetric.AES;
|
|
import cn.hutool.crypto.symmetric.AES;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.nacos.api.config.annotation.NacosValue;
|
|
|
import com.kxs.common.core.util.R;
|
|
import com.kxs.common.core.util.R;
|
|
|
import com.kxs.product.api.model.KxsMachine;
|
|
import com.kxs.product.api.model.KxsMachine;
|
|
|
import com.kxs.product.api.model.KxsMachineDeduct;
|
|
import com.kxs.product.api.model.KxsMachineDeduct;
|
|
|
|
|
+import com.kxs.product.biz.config.KxsOldConfigProperties;
|
|
|
import com.kxs.product.biz.mapper.KxsMachineDeductMapper;
|
|
import com.kxs.product.biz.mapper.KxsMachineDeductMapper;
|
|
|
import com.kxs.product.biz.mapper.KxsMachineMapper;
|
|
import com.kxs.product.biz.mapper.KxsMachineMapper;
|
|
|
import com.kxs.system.api.feign.RemoteOldService;
|
|
import com.kxs.system.api.feign.RemoteOldService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
|
+import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
@@ -29,13 +35,16 @@ import java.util.List;
|
|
|
* @author 没秃顶的码农
|
|
* @author 没秃顶的码农
|
|
|
* @date 2024-03-13
|
|
* @date 2024-03-13
|
|
|
*/
|
|
*/
|
|
|
-@Configuration
|
|
|
|
|
|
|
+@Component
|
|
|
@EnableAsync
|
|
@EnableAsync
|
|
|
@EnableScheduling
|
|
@EnableScheduling
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
|
|
+@EnableConfigurationProperties(KxsOldConfigProperties.class)
|
|
|
public class KxsProductTask {
|
|
public class KxsProductTask {
|
|
|
|
|
|
|
|
|
|
+ private final KxsOldConfigProperties kxsOldConfigProperties;
|
|
|
|
|
+
|
|
|
private final KxsMachineMapper kxsMachineMapper;
|
|
private final KxsMachineMapper kxsMachineMapper;
|
|
|
|
|
|
|
|
private final KxsMachineDeductMapper kxsMachineDeductMapper;
|
|
private final KxsMachineDeductMapper kxsMachineDeductMapper;
|
|
@@ -50,47 +59,45 @@ public class KxsProductTask {
|
|
|
|
|
|
|
|
private final AES cryptoOldAes;
|
|
private final AES cryptoOldAes;
|
|
|
|
|
|
|
|
- @Value("${kxs.old.url}")
|
|
|
|
|
- private String url;
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 循环过期机具添加预扣款
|
|
* 循环过期机具添加预扣款
|
|
|
|
|
+ * 一个小时执行一次
|
|
|
*
|
|
*
|
|
|
*/
|
|
*/
|
|
|
-// @Async(value = "getAsyncExecutor")
|
|
|
|
|
-// @Scheduled(cron = "0 0 */1 * * ?")
|
|
|
|
|
-// public void recycleMachineSchedule() {
|
|
|
|
|
-// Boolean lock = false;
|
|
|
|
|
-// try {
|
|
|
|
|
-// //分布式锁
|
|
|
|
|
-// lock = redisTemplate.opsForValue().setIfAbsent(KEY, LOCK);
|
|
|
|
|
-// if (Boolean.TRUE.equals(lock)) {
|
|
|
|
|
-//
|
|
|
|
|
-// LocalDateTime endDay = LocalDate.now().minusDays(30).atStartOfDay();
|
|
|
|
|
-// List<KxsMachine> machines = kxsMachineMapper.selectExpireDeductList(endDay);
|
|
|
|
|
-//
|
|
|
|
|
-// for (KxsMachine machine : machines) {
|
|
|
|
|
-// HashMap<String, Object> param = new HashMap<>();
|
|
|
|
|
-// HashMap<String, Object> data = new HashMap<>();
|
|
|
|
|
-// data.put("PosSn", machine.getPosSn());
|
|
|
|
|
-//// String body = cryptoOldAes.encryptHex(JSON.toJSONString(data));
|
|
|
|
|
-// param.put("value", JSON.toJSONString(data));
|
|
|
|
|
-// R result = remoteOldService.savePosAdvance(param);
|
|
|
|
|
-// if(result.getStatus() == 1){
|
|
|
|
|
-// log.info("查询数据:{}", machines);
|
|
|
|
|
-//
|
|
|
|
|
-// KxsMachineDeduct machineDeduct = new KxsMachineDeduct();
|
|
|
|
|
-// machineDeduct.setPosSn(machine.getPosSn());
|
|
|
|
|
-// machineDeduct.setRemark("已添加预扣款");
|
|
|
|
|
-// kxsMachineDeductMapper.insert(machineDeduct);
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// }
|
|
|
|
|
-// } finally {
|
|
|
|
|
-// if (Boolean.TRUE.equals(lock)) {
|
|
|
|
|
-// redisTemplate.delete(KEY);
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ @Async(value = "getAsyncExecutor")
|
|
|
|
|
+ @Scheduled(fixedDelay = 1000 * 60 * 60 )
|
|
|
|
|
+ @RefreshScope
|
|
|
|
|
+ public void recycleMachineSchedule() {
|
|
|
|
|
+ Boolean lock = false;
|
|
|
|
|
+ try {
|
|
|
|
|
+ //分布式锁
|
|
|
|
|
+ lock = redisTemplate.opsForValue().setIfAbsent(KEY, LOCK);
|
|
|
|
|
+ if (Boolean.TRUE.equals(lock) && kxsOldConfigProperties.getRecycleEnable()) {
|
|
|
|
|
+
|
|
|
|
|
+ LocalDateTime endDay = LocalDate.now().minusDays(30).atStartOfDay();
|
|
|
|
|
+ List<KxsMachine> machines = kxsMachineMapper.selectExpireDeductList(endDay);
|
|
|
|
|
+
|
|
|
|
|
+ for (KxsMachine machine : machines) {
|
|
|
|
|
+ HashMap<String, Object> param = new HashMap<>();
|
|
|
|
|
+ HashMap<String, Object> data = new HashMap<>();
|
|
|
|
|
+ data.put("PosSn", machine.getPosSn());
|
|
|
|
|
+// String body = cryptoOldAes.encryptHex(JSON.toJSONString(data));
|
|
|
|
|
+ param.put("value", JSON.toJSONString(data));
|
|
|
|
|
+ R result = remoteOldService.savePosAdvance(param);
|
|
|
|
|
+ if(result.getStatus() == 1){
|
|
|
|
|
+ log.info("查询数据:{}", machines);
|
|
|
|
|
+
|
|
|
|
|
+ KxsMachineDeduct machineDeduct = new KxsMachineDeduct();
|
|
|
|
|
+ machineDeduct.setPosSn(machine.getPosSn());
|
|
|
|
|
+ machineDeduct.setRemark("已添加预扣款");
|
|
|
|
|
+ kxsMachineDeductMapper.insert(machineDeduct);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ if (Boolean.TRUE.equals(lock)) {
|
|
|
|
|
+ redisTemplate.delete(KEY);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|