diff --git a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/aspect/JobAnnotationAspect.java b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/aspect/JobAnnotationAspect.java new file mode 100644 index 000000000..aacf226c4 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/aspect/JobAnnotationAspect.java @@ -0,0 +1,93 @@ +package com.logpm.factorydata.olo.aspect; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; +import lombok.AllArgsConstructor; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springblade.common.cache.CacheNames; +import org.springblade.common.constant.LauncherConstant; +import org.springblade.core.redis.cache.BladeRedis; +import org.springblade.core.redis.lock.LockType; +import org.springblade.core.redis.lock.RedisLockClient; +import org.springblade.core.tool.utils.ThreadLocalUtil; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpHeaders; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.TimeUnit; + +@Aspect +@Component +@AllArgsConstructor +public class JobAnnotationAspect { + private final BladeRedis bladeRedis; + private final Environment environment; + private final RedisLockClient redisLockClient; + + @Around("@annotation(com.xxl.job.core.handler.annotation.XxlJob)") + public Object xxlJobAnnotationMethods(ProceedingJoinPoint joinPoint) throws Throwable { + + + JSONObject jsonObject = mockLogin(); + MockHttpServletRequest mockRequest = new MockHttpServletRequest(); + mockRequest.addHeader("Blade-Auth", "bearer "+jsonObject.get("access_token")); + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(mockRequest)); + + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.add("Blade-Auth","bearer "+jsonObject.get("access_token") ); + httpHeaders.add( "Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); + ThreadLocalUtil.put("bladeContext", httpHeaders); + + DynamicDataSourceContextHolder.push(jsonObject.getString("tenant_id")); + // 执行原方法 + Object result = joinPoint.proceed(); + // 在方法执行后,从数据源上下文中移除租户ID + DynamicDataSourceContextHolder.poll(); + + return result; + + + } + + private JSONObject mockLogin() throws InterruptedException { + + String account ="shujutongbu"; + JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); + if(Objects.isNull(data)){ + boolean flag = redisLockClient.tryLock("local_server_user", LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS); + if(flag){ + data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); + if(Objects.isNull(data)){ + String url = "http://"+ LauncherConstant.loginAddr(Objects.requireNonNull(environment.getActiveProfiles()[0]))+"/blade-auth/oauth/token"; + HttpRequest urlRequest = HttpRequest.post(url); + urlRequest.header("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); + urlRequest.header("Tenant-Id", "627683"); + + Map params = new HashMap<>(); + params.put("grant_type", "local_server"); + params.put("scope", "all"); + params.put("username", account); + params.put("tenantId", "627683"); + HttpResponse execute = urlRequest.form(params).execute(); + String body = execute.body(); + data = JSONObject.parseObject(body); + bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,3200L); + redisLockClient.unLock("local_server_user", LockType.FAIR); + } + } + } + return data; + } + + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/config/XxlJobConfig.java b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/config/XxlJobConfig.java new file mode 100644 index 000000000..dfff9fc2a --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/config/XxlJobConfig.java @@ -0,0 +1,74 @@ +package com.logpm.factorydata.olo.config; + +import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * xxl-job config + * + * @author xuxueli 2017-04-28 + */ +@Configuration(proxyBeanMethods = false) +public class XxlJobConfig { + private final Logger logger = LoggerFactory.getLogger(XxlJobConfig.class); + + @Value("${xxl.job.admin.addresses}") + private String adminAddresses; + + @Value("${xxl.job.executor.appname}") + private String appName; + + @Value("${xxl.job.executor.ip}") + private String ip; + + @Value("${xxl.job.executor.port}") + private int port; + + @Value("${xxl.job.accessToken}") + private String accessToken; + + @Value("${xxl.job.executor.logpath}") + private String logPath; + + @Value("${xxl.job.executor.logretentiondays}") + private int logRetentionDays; + + + @Bean + public XxlJobSpringExecutor xxlJobExecutor() { + logger.info(">>>>>>>>>>> xxl-job config init."); + XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); + xxlJobSpringExecutor.setAdminAddresses(adminAddresses); + xxlJobSpringExecutor.setAppName(appName); + xxlJobSpringExecutor.setIp(ip); + xxlJobSpringExecutor.setPort(port); + xxlJobSpringExecutor.setAccessToken(accessToken); + xxlJobSpringExecutor.setLogPath(logPath); + xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays); + + return xxlJobSpringExecutor; + } + + /** + * 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP; + * + * 1、引入依赖: + * + * org.springframework.cloud + * spring-cloud-commons + * ${version} + * + * + * 2、配置文件,或者容器启动变量 + * spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.' + * + * 3、获取IP + * String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); + */ + + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/job/PushDataJob.java b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/job/PushDataJob.java new file mode 100644 index 000000000..fe1d4e43b --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/job/PushDataJob.java @@ -0,0 +1,36 @@ +package com.logpm.factorydata.olo.job; + +import com.logpm.factorydata.olo.service.DeliveryNoteService; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @author zhaoqiaobo + * @create 2024-04-02 + */ +@AllArgsConstructor +@Component +@Slf4j +public class PushDataJob { + + private final DeliveryNoteService deliveryNoteService; + + /** + * 定时扫描我乐手动维护的数据,推送给我乐 + * + * @param param + * @return + * @throws Exception + */ + @XxlJob("pushNodeData") + public ReturnT pushDataJob(String param) throws Exception { + + deliveryNoteService.customPushNodeData(); + + return ReturnT.SUCCESS; + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mapper/DeliveryNoteMapper.java b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mapper/DeliveryNoteMapper.java index 219905d9b..5940a281a 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mapper/DeliveryNoteMapper.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mapper/DeliveryNoteMapper.java @@ -1,5 +1,6 @@ package com.logpm.factorydata.olo.mapper; +import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.logpm.factorydata.olo.entity.DeliveryNoteEntity; import org.apache.ibatis.annotations.Mapper; @@ -13,4 +14,6 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface DeliveryNoteMapper extends BaseMapper { + JSONObject customPushNodeData(); + } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mapper/FactoryNodeOrderMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mapper/FactoryNodeOrderMapper.xml index e19d0437f..605ab4d16 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mapper/FactoryNodeOrderMapper.xml +++ b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mapper/FactoryNodeOrderMapper.xml @@ -2,4 +2,19 @@ + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/service/DeliveryNoteService.java b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/service/DeliveryNoteService.java index 20f2177cc..cc0382041 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/service/DeliveryNoteService.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/service/DeliveryNoteService.java @@ -17,4 +17,13 @@ public interface DeliveryNoteService extends BaseService { String order(List vo); void buildAdvance(List entities); + + /** + * 我乐自定义数据推送 + + * @return void + * @author zqb 2024/5/29 + **/ + void customPushNodeData(); + } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/service/impl/DeliveryNoteServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/service/impl/DeliveryNoteServiceImpl.java index a79715f20..80657b4fc 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/service/impl/DeliveryNoteServiceImpl.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/service/impl/DeliveryNoteServiceImpl.java @@ -7,6 +7,8 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.logpm.factorydata.base.feign.IFactoryDataBaseClient; @@ -17,9 +19,11 @@ import com.logpm.factorydata.feign.IFactoryDataClient; import com.logpm.factorydata.olo.entity.DeliveryNoteEntity; import com.logpm.factorydata.olo.entity.FactoryOrderLogEntity; import com.logpm.factorydata.olo.mapper.DeliveryNoteMapper; +import com.logpm.factorydata.olo.pros.OldProperties; import com.logpm.factorydata.olo.service.DeliveryNoteService; import com.logpm.factorydata.olo.service.FactoryOrderLogService; import com.logpm.factorydata.olo.vo.DeliveryNoteVO; +import com.logpm.factorydata.vo.PushData; import com.logpm.factorydata.vo.SendMsg; import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; import com.logpm.trunkline.entity.TrunklineAdvanceEntity; @@ -70,6 +74,8 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl vo) { @@ -228,6 +234,36 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl pushDatas = StrUtil.split(sns, ","); + js.set("siteLevel", 3); + js.set("receiveOrSend", 1); + js.set("receivable", 0); + js.set("receipts", 0); + JSONArray snArray = new JSONArray(pushDatas.size()); + for (String data : pushDatas) { + JSONObject jsonObject = new JSONObject(); + jsonObject.set("sn", data); + jsonObject.set("qty", 1); + snArray.add(jsonObject); + } + js.set("snList", snArray); + js.remove("sns"); + if (StrUtil.isNotEmpty(oldProperties.getPushNodeUrl())) { + try { + log.info("自定义推送节点数据:{}", js.toString()); + String post = HttpUtil.post(oldProperties.getPushNodeUrl(), js.toString()); + log.info("推送结果:{}", post); + } catch (Exception e) { + e.printStackTrace(); + log.error("推送节点数据错误:{}", e); + } + } + } + private String uploadFile(String body) { //文本内容和保存为本地文件 并上传 String logPath = FileLogsUtil.saveFileLogs(body);