diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/BmsServiceFeign.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/BmsServiceFeign.java index caf732f29..9d7fcfa35 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/BmsServiceFeign.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/BmsServiceFeign.java @@ -78,4 +78,8 @@ public interface BmsServiceFeign { */ @GetMapping("/settlementCustomersParametersApi/getListBySettlementCustomersId") AjaxResult getListBySettlementCustomersId(@RequestParam("settlementCustomersId") Long settlementCustomersId); + + @PostMapping("/settlementCustomersApi/updatePushContractManageJobId") + AjaxResult updatePushContractManageJobId(@RequestParam("settlementCustomersId") Long settlementCustomersId, + @RequestParam("jobId") Integer jobId); } \ No newline at end of file diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteBmsFeignFallbackFactory.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteBmsFeignFallbackFactory.java index e6b97690d..a851b12d8 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteBmsFeignFallbackFactory.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteBmsFeignFallbackFactory.java @@ -77,6 +77,11 @@ public class RemoteBmsFeignFallbackFactory implements FallbackFactory formMap = BeanUtil.beanToMap(addReq); + + HttpResponse response = HttpRequest.post(url) + .header("Authorization", accessToken) + .form(formMap) //传入map,不再传实体 + .execute(); + + String body = response.body(); + log.info("xxl‑job addJob resp:{}", body); + XxlApiResp resp = JSONUtil.toBean(body, XxlApiResp.class); + if (resp != null && resp.getCode() == 200) { + return Integer.valueOf(resp.getContent().toString()); + } + log.error("新增xxl‑job任务失败,resp:{}", body); + return null; + } catch (Exception e) { + log.error("调用xxl‑job addJob异常", e); + return null; + } + } + + + /** + * 删除任务 + * @param jobId 任务id + * @return true成功 + */ + public boolean removeJob(Integer jobId) { + String url = adminUrl + "/api/jobinfo/remove"; + try (HttpResponse response = HttpRequest.post(url) + .header("Authorization", accessToken) + .form("id", jobId) + .execute()) { + String body = response.body(); + XxlApiResp resp = JSONUtil.toBean(body, XxlApiResp.class); + if (resp != null && resp.getCode() == 200) { + return true; + } + log.error("删除xxl‑job任务失败 jobId:{},resp:{}", jobId, body); + return false; + } catch (Exception e) { + log.error("调用xxl‑job removeJob异常", e); + return false; + } + } + + /** + * 暂停任务 + */ + public boolean pauseJob(Integer jobId) { + String url = adminUrl + "/api/jobinfo/pause"; + try (HttpResponse response = HttpRequest.post(url) + .header("Authorization", accessToken) + .form("id", jobId) + .execute()) { + String body = response.body(); + XxlApiResp resp = JSONUtil.toBean(body, XxlApiResp.class); + return resp != null && resp.getCode() == 200; + } catch (Exception e) { + log.error("pauseJob异常", e); + return false; + } + } + + + //---------------- 实体 ---------------- + + @Data + public static class JobInfoAddReq { + /** 执行器组ID xxl_job_group.id */ + private Integer jobGroup; + /** 任务描述 */ + private String jobDesc; + /** 路由策略 ROUND:轮询 */ + private String executorRouteStrategy = "ROUND"; + /** cron表达式 23点 0 0 23 * * ? */ + private String jobCron; + /** @XxlJob 注解handler名称 */ + private String executorHandler; + /** 任务参数,这里存业务单号 */ + private String executorParam; + /** 阻塞策略 SERIAL_EXECUTION单机串行 */ + private String executorBlockStrategy = "SERIAL_EXECUTION"; + /** 超时时间 0不限制 */ + private Integer executorTimeout = 0; + /** 失败重试次数 */ + private Integer executorFailRetryCount = 0; + /** BEAN模式 */ + private String glueType = "BEAN"; + private String glueSource = ""; + private String glueRemark = ""; + /** 1启用 0停止 */ + private Integer triggerStatus = 1; + } + + @Data + public static class XxlApiResp { + private Integer code; + private Object content; + private String msg; + } +} \ No newline at end of file diff --git a/mhd_bms/src/main/java/com/mhd/bms/application/server/settlementCustomers/SettlementCustomersApplicationService.java b/mhd_bms/src/main/java/com/mhd/bms/application/server/settlementCustomers/SettlementCustomersApplicationService.java index 5b8f83044..5d64df651 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/application/server/settlementCustomers/SettlementCustomersApplicationService.java +++ b/mhd_bms/src/main/java/com/mhd/bms/application/server/settlementCustomers/SettlementCustomersApplicationService.java @@ -10,6 +10,7 @@ import com.mhd.bms.domain.settlementCustomers.repository.mapper.SettlementCustom import com.mhd.bms.domain.settlementCustomers.repository.po.SettlementCustomersPO; import com.mhd.bms.domain.settlementCustomers.repository.todo.SettlementCustomersDO; import com.mhd.bms.domain.settlementCustomers.repository.persistence.SettlementCustomersImpl; +import com.mhd.bms.domain.settlementCustomers.repository.util.XxlJobOpenApiUtil; import com.mhd.bms.domain.settlementCustomers.service.SettlementCustomersDomainService; import com.mhd.bms.domain.settlementCustomersNcConfig.entity.SettlementCustomersNcConfig; import com.mhd.bms.domain.settlementCustomersNcConfig.repository.facade.ISettlementCustomersNcConfigService; @@ -38,6 +39,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -73,6 +75,9 @@ public class SettlementCustomersApplicationService { private ISettlementCustomersNcConfigService settlementCustomersNcConfigService; private static final int SYNC_BATCH_SIZE = 500; + @Value("${xxl.job.admin.addresses}") + private String adminAddresses; + private static final String token = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjozNTYzLCJ0b3BPcmdhbml6YXRpb25JZCI6MjgyNywidXNlcl9rZXkiOiI0N2MzY2U4My0wMmFjLTQ0NTQtOTdiYS1lYmQwMDc2MzNiNDMiLCJ1c2VybmFtZSI6ImNhbmdtYSJ9.tnZyywwburfBo3Kizdhfk5eYdXbrrZ9976Z0W7GrS6UqSpKwfI2RwdRwfYx7DbD7Ri1Fdj_eOVxBkjvdFF226Q"; /** * 分页查询结算对象列表 @@ -328,6 +333,15 @@ public class SettlementCustomersApplicationService { if (paramResult == null || !"200".equals(String.valueOf(paramResult.get("code")))) { throw new ServiceException("保存合同参数失败"); } + Long settlementEntityId = settlementCustomersDO.getSettlementEntityId(); + if (settlementEntityId != null) { + stopXxlJob(settlementCustomersDO.getPushBillingRecordJobId()); + stopXxlJob(settlementCustomersDO.getPushBillManageJobId()); + Integer jobId = addXxlJob(String.valueOf(settlementEntityId)); + Integer jobId1 = addXxlJob1(String.valueOf(settlementEntityId)); + settlementCustomersDO.setPushBillingRecordJobId(jobId); + settlementCustomersDO.setPushBillManageJobId(jobId1); + } } else { throw new ServiceException("创建临时合同失败"); } @@ -338,6 +352,55 @@ public class SettlementCustomersApplicationService { return settlementCustomersDomainService.update(settlementCustomersDO); } + public Integer addXxlJob(String shipperId) { + //1.实例化工具类,建议交给Spring管理 + XxlJobOpenApiUtil apiUtil = new XxlJobOpenApiUtil(adminAddresses,token); + + //2.构建新增任务参数 + XxlJobOpenApiUtil.JobInfoAddReq req = new XxlJobOpenApiUtil.JobInfoAddReq(); + req.setJobGroup(3); //你的执行器组id + req.setJobDesc("散租推送计费单据/流水任务,结算对象id:" + shipperId); + req.setJobCron("0 0 1 * * ?"); + req.setExecutorHandler("pushBillingRecord"); + req.setExecutorParam(shipperId); //传入业务单号 + + //3.调用创建任务接口 ,返回任务ID + Integer xxlJobId = apiUtil.addJob(req); + if(xxlJobId == null){ + // 创建定时任务失败,抛异常/重试,不要让单据直接保存成功 + throw new RuntimeException("创建夜间定时任务失败"); + } + return xxlJobId; + } + + public Integer addXxlJob1(String shipperId) { + //1.实例化工具类,建议交给Spring管理 + XxlJobOpenApiUtil apiUtil = new XxlJobOpenApiUtil(adminAddresses,token); + + //2.构建新增任务参数 + XxlJobOpenApiUtil.JobInfoAddReq req = new XxlJobOpenApiUtil.JobInfoAddReq(); + req.setJobGroup(6); //你的执行器组id + req.setJobDesc("计费单据/流水生成发票任务,结算对象id:" + shipperId); + req.setJobCron("0 0 1 * * ?"); + req.setExecutorHandler("pushBillManage"); + req.setExecutorParam(shipperId); //传入业务单号 + + //3.调用创建任务接口 ,返回任务ID + Integer xxlJobId = apiUtil.addJob(req); + if(xxlJobId == null){ + // 创建定时任务失败,抛异常/重试,不要让单据直接保存成功 + throw new RuntimeException("创建夜间定时任务失败"); + } + return xxlJobId; + } + + public void stopXxlJob(Integer shipperId) { + //1.实例化工具类,建议交给Spring管理 + XxlJobOpenApiUtil apiUtil = new XxlJobOpenApiUtil(adminAddresses,token); + //3.调用创建任务接口 ,返回任务ID + apiUtil.pauseJob(shipperId); + } + private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyMMdd"); private static final Random RANDOM = new Random(); @@ -573,6 +636,13 @@ public class SettlementCustomersApplicationService { return saveEntity; } + public Boolean updatePushContractManageToBmsJobId(Long settlementCustomersId, Integer jobId) { + return settlementCustomersImpl.lambdaUpdate() + .eq(SettlementCustomers::getSettlementCustomersId, settlementCustomersId) + .set(SettlementCustomers::getPushContractManageToBmsJobId, jobId) + .update(); + } + private SettlementCustomersDO buildDriverSettlementCustomerDO(UserDriverPo userDriverPo, LoginUser loginUser, Long organizationId) { SettlementCustomersDO saveEntity = new SettlementCustomersDO(); saveEntity.setSettlementEntityId(userDriverPo.getUserId()); diff --git a/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/entity/SettlementCustomers.java b/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/entity/SettlementCustomers.java index 52d80fbcf..3a6780cf5 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/entity/SettlementCustomers.java +++ b/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/entity/SettlementCustomers.java @@ -96,5 +96,11 @@ public class SettlementCustomers extends BaseVOEntity{ private String settlementCurrency; @ApiModelProperty(name = "组织代码") private String orgCode; + @ApiModelProperty(name = "散租推送计费单据/流水任务id") + private Integer pushBillingRecordJobId; + @ApiModelProperty(name = "整租推送计费单据/流水任务id") + private Integer pushContractManageToBmsJobId; + @ApiModelProperty(name = "生成应收账单任务id") + private Integer pushBillManageJobId; } \ No newline at end of file diff --git a/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/repository/po/SettlementCustomersPO.java b/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/repository/po/SettlementCustomersPO.java index e31f35662..75d30689b 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/repository/po/SettlementCustomersPO.java +++ b/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/repository/po/SettlementCustomersPO.java @@ -132,6 +132,12 @@ public class SettlementCustomersPO extends BaseVOEntity{ private Date businessCreateTime; @ApiModelProperty(name = "组织代码") private String orgCode; + @ApiModelProperty(name = "散租推送计费单据/流水任务id") + private Integer pushBillingRecordJobId; + @ApiModelProperty(name = "整租推送计费单据/流水任务id") + private Integer pushContractManageToBmsJobId; + @ApiModelProperty(name = "生成应收账单任务id") + private Integer pushBillManageJobId; List settlementCustomersNcConfigs; List settlementCustomersParameters; diff --git a/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/repository/todo/SettlementCustomersDO.java b/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/repository/todo/SettlementCustomersDO.java index f2753742f..02a472756 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/repository/todo/SettlementCustomersDO.java +++ b/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/repository/todo/SettlementCustomersDO.java @@ -135,6 +135,12 @@ public class SettlementCustomersDO extends BaseVOEntity{ private String documentTypeCode; @ApiModelProperty(name = "组织代码") private String orgCode; + @ApiModelProperty(name = "散租推送计费单据/流水任务id") + private Integer pushBillingRecordJobId; + @ApiModelProperty(name = "整租推送计费单据/流水任务id") + private Integer pushContractManageToBmsJobId; + @ApiModelProperty(name = "生成应收账单任务id") + private Integer pushBillManageJobId; @ApiModelProperty("结算对象参数") private List settlementCustomersParameters; diff --git a/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/repository/util/XxlJobOpenApiUtil.java b/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/repository/util/XxlJobOpenApiUtil.java index 4ebe08220..41953d8c4 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/repository/util/XxlJobOpenApiUtil.java +++ b/mhd_bms/src/main/java/com/mhd/bms/domain/settlementCustomers/repository/util/XxlJobOpenApiUtil.java @@ -38,7 +38,7 @@ public class XxlJobOpenApiUtil { Map formMap = BeanUtil.beanToMap(addReq); HttpResponse response = HttpRequest.post(url) - .header("XXL-JOB-ACCESS-TOKEN", accessToken) + .header("Authorization", accessToken) .form(formMap) //传入map,不再传实体 .execute(); @@ -65,7 +65,7 @@ public class XxlJobOpenApiUtil { public boolean removeJob(Integer jobId) { String url = adminUrl + "/api/jobinfo/remove"; try (HttpResponse response = HttpRequest.post(url) - .header("XXL‑JOB‑ACCESS‑TOKEN", accessToken) + .header("Authorization", accessToken) .form("id", jobId) .execute()) { String body = response.body(); @@ -87,7 +87,7 @@ public class XxlJobOpenApiUtil { public boolean pauseJob(Integer jobId) { String url = adminUrl + "/api/jobinfo/pause"; try (HttpResponse response = HttpRequest.post(url) - .header("XXL‑JOB‑ACCESS‑TOKEN", accessToken) + .header("Authorization", accessToken) .form("id", jobId) .execute()) { String body = response.body(); diff --git a/mhd_bms/src/main/java/com/mhd/bms/interfaces/dto/settlementCustomers/SettlementCustomersDTO.java b/mhd_bms/src/main/java/com/mhd/bms/interfaces/dto/settlementCustomers/SettlementCustomersDTO.java index 7c3c7e22a..ee5ec5d61 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/interfaces/dto/settlementCustomers/SettlementCustomersDTO.java +++ b/mhd_bms/src/main/java/com/mhd/bms/interfaces/dto/settlementCustomers/SettlementCustomersDTO.java @@ -135,6 +135,12 @@ public class SettlementCustomersDTO extends BaseVOEntity{ private String documentTypeCode; @ApiModelProperty(name = "组织代码") private String orgCode; + @ApiModelProperty(name = "散租推送计费单据/流水任务id") + private Integer pushBillingRecordJobId; + @ApiModelProperty(name = "整租推送计费单据/流水任务id") + private Integer pushContractManageToBmsJobId; + @ApiModelProperty(name = "生成应收账单任务id") + private Integer pushBillManageJobId; @ApiModelProperty("结算对象参数") private List settlementCustomersParameters; diff --git a/mhd_bms/src/main/java/com/mhd/bms/interfaces/facadeApi/SettlementCustomersApi.java b/mhd_bms/src/main/java/com/mhd/bms/interfaces/facadeApi/SettlementCustomersApi.java index ed2fa4bbf..869a33446 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/interfaces/facadeApi/SettlementCustomersApi.java +++ b/mhd_bms/src/main/java/com/mhd/bms/interfaces/facadeApi/SettlementCustomersApi.java @@ -137,6 +137,13 @@ public class SettlementCustomersApi extends BaseController{ return AjaxResult.success(settlementCustomersApplicationService.getFirstBySettlementEntityId(settlementEntityId, topOrganizationId)); } + @ApiOperation("根据结算对象ID更新整租推送任务ID") + @PostMapping("/updatePushContractManageJobId") + public AjaxResult updatePushContractManageJobId(@RequestParam("settlementCustomersId") Long settlementCustomersId, + @RequestParam("jobId") Integer jobId) { + Boolean result = settlementCustomersApplicationService.updatePushContractManageToBmsJobId(settlementCustomersId, jobId); + return toAjax(result); + } @@ -145,4 +152,5 @@ public class SettlementCustomersApi extends BaseController{ -} + +} \ No newline at end of file diff --git a/mhd_bms/src/main/resources/mapper/SettlementCustomersMapper.xml b/mhd_bms/src/main/resources/mapper/SettlementCustomersMapper.xml index e3b71ac36..6ec30e44c 100644 --- a/mhd_bms/src/main/resources/mapper/SettlementCustomersMapper.xml +++ b/mhd_bms/src/main/resources/mapper/SettlementCustomersMapper.xml @@ -44,6 +44,9 @@ + + + @@ -117,6 +120,9 @@ bd.document_type, bd.document_type_code, a.org_code, + a.push_billing_record_job_id, + a.push_contract_manage_to_bms_job_id, + a.push_bill_manage_job_id, bd.create_time as business_create_time from settlement_customers a left join "NGWL_TEST_USER"."USER_SHIPPER" b on a.settlement_entity_id = b.user_id