自动生成job
This commit is contained in:
+70
@@ -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());
|
||||
|
||||
+6
@@ -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;
|
||||
|
||||
}
|
||||
+6
@@ -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<SettlementCustomersNcConfig> settlementCustomersNcConfigs;
|
||||
List<SettlementCustomersParameters> settlementCustomersParameters;
|
||||
|
||||
+6
@@ -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<SettlementCustomersParametersDTO> settlementCustomersParameters;
|
||||
|
||||
|
||||
+3
-3
@@ -38,7 +38,7 @@ public class XxlJobOpenApiUtil {
|
||||
Map<String, Object> 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();
|
||||
|
||||
+6
@@ -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<SettlementCustomersParametersDTO> settlementCustomersParameters;
|
||||
|
||||
@@ -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{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,6 +44,9 @@
|
||||
<result property="documentTypeCode" column="document_type_code" />
|
||||
<result property="businessCreateTime" column="business_create_time" />
|
||||
<result property="orgCode" column="org_code" />
|
||||
<result property="pushBillingRecordJobId" column="push_billing_record_job_id" />
|
||||
<result property="pushContractManageToBmsJobId" column="push_contract_manage_to_bms_job_id" />
|
||||
<result property="pushBillManageJobId" column="push_bill_manage_job_id" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="business_document_where">
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user