mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
feat(Mtjywpm): add syncInProgressData method for synchronizing ongoing orders
This commit is contained in:
@@ -3,6 +3,7 @@ package cn.lihongjie.coal.mtjywpm.repository;
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.mtjywpm.entity.MtjywpmEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
@@ -26,4 +27,8 @@ public interface MtjywpmRepository extends BaseRepository<MtjywpmEntity> {
|
||||
*/
|
||||
@Query("select e from MtjywpmEntity e where e.postatus in ('3', '1', '2') or e.postatusname like '%应单中%' or e.postatusname like '%竞价中%'")
|
||||
List<MtjywpmEntity> findIncompleteOrders();
|
||||
|
||||
@Modifying
|
||||
@Query("update MtjywpmEntity e set e.status = :status where e.tradercode = :tradercode")
|
||||
void updateStatusByTradercode(String tradercode, int status);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.lihongjie.coal.mtjywpm.service;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.mtjywpm.dto.CreateMtjywpmDto;
|
||||
@@ -15,6 +16,11 @@ import cn.lihongjie.coal.rabbitmq.RabbitMQService;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -22,6 +28,7 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -37,11 +44,14 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class MtjywpmService extends BaseService<MtjywpmEntity, MtjywpmRepository> {
|
||||
@Autowired private CommonMapper commonMapper;
|
||||
private static final String API_URL = "https://www.ctctc.cn/search_list_gg.jspx";
|
||||
private static final int PAGE_SIZE = 50;
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER =
|
||||
@@ -112,6 +122,10 @@ public class MtjywpmService extends BaseService<MtjywpmEntity, MtjywpmRepository
|
||||
|
||||
if (dataList == null || dataList.isEmpty()) {
|
||||
log.info("未找到交易单号为 {} 的数据", tradercode);
|
||||
// 标记为禁用
|
||||
|
||||
repository.updateStatusByTradercode(tradercode.trim(), 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -212,9 +226,7 @@ public class MtjywpmService extends BaseService<MtjywpmEntity, MtjywpmRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步未完成的订单
|
||||
*/
|
||||
/** 同步未完成的订单 */
|
||||
public void syncIncrement() {
|
||||
syncIncrement(null, null);
|
||||
}
|
||||
@@ -265,8 +277,7 @@ public class MtjywpmService extends BaseService<MtjywpmEntity, MtjywpmRepository
|
||||
* @param page
|
||||
* @param tradercode
|
||||
*/
|
||||
private List<Map<String, Object>> fetchDataFromApi(
|
||||
int page, String tradercode) {
|
||||
private List<Map<String, Object>> fetchDataFromApi(int page, String tradercode) {
|
||||
return fetchDataFromApi(page, tradercode, PAGE_SIZE);
|
||||
}
|
||||
|
||||
@@ -572,4 +583,48 @@ public class MtjywpmService extends BaseService<MtjywpmEntity, MtjywpmRepository
|
||||
log.warn("解析竞价时间失败: {}", jjtime, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void syncInProgressData() {
|
||||
|
||||
List<MtjywpmEntity> all =
|
||||
this.repository.findAll(
|
||||
new Specification<MtjywpmEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<MtjywpmEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
|
||||
// 只同步状态为“应单中”的订单 postatus = 3
|
||||
// 只同步当天的订单 jjdate = today
|
||||
// 只同步结束时间小于当前时间的订单 jjendtime <= now 表示已经结束
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(root.get("postatus"), "3"),
|
||||
criteriaBuilder.equal(root.get("jjdate"), LocalDate.now()),
|
||||
criteriaBuilder.equal(root.get("status"), 1),
|
||||
criteriaBuilder.lessThanOrEqualTo(
|
||||
root.get("bidendtime"), LocalDateTime.now()));
|
||||
}
|
||||
});
|
||||
|
||||
if (all.isEmpty()) {
|
||||
log.info("没有需要同步的应单中订单");
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> set = all.stream().map(x -> x.getTradercode()).collect(Collectors.toSet());
|
||||
|
||||
for (String s : set) {
|
||||
try {
|
||||
|
||||
syncSingleOrder(s);
|
||||
|
||||
log.info("同步交易单号为 {} 的应单中订单完成", s);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
log.error("同步交易单号为 {} 的应单中订单失败", s, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import cn.lihongjie.coal.mtjywpm.service.MtjywpmService
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def service = ioc.getBean(MtjywpmService.class)
|
||||
|
||||
service.syncInProgressData()
|
||||
|
||||
Reference in New Issue
Block a user