feat:江体小程序定时任务
This commit is contained in:
@@ -3,6 +3,7 @@ package com.xiang.app.modules.jntyzx.service;
|
||||
|
||||
import com.xiang.app.modules.jntyzx.entity.pojo.VenueInfoDO;
|
||||
import com.xiang.app.modules.jntyzx.entity.resp.JntyzxResponse;
|
||||
import com.xiang.app.modules.jntyzx.entity.resp.OrderCreateResp;
|
||||
import com.xiang.app.modules.jntyzx.entity.resp.query.SitePositionList;
|
||||
|
||||
import java.util.List;
|
||||
@@ -30,7 +31,7 @@ public interface IJntyzxHttpService {
|
||||
* 订单创建
|
||||
* @return
|
||||
*/
|
||||
Boolean createOrder(List<VenueInfoDO> venueInfos, String token);
|
||||
JntyzxResponse<OrderCreateResp> createOrder(List<VenueInfoDO> venueInfos, String token);
|
||||
|
||||
/**
|
||||
* 心跳监测
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.xiang.app.modules.jntyzx.service;
|
||||
|
||||
|
||||
import com.xiang.app.modules.jntyzx.entity.pojo.OrderInfoDO;
|
||||
import com.xiang.app.modules.jntyzx.entity.pojo.UserTokenInfoDO;
|
||||
import com.xiang.app.modules.jntyzx.entity.pojo.VenueInfoDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,5 +13,7 @@ import java.util.List;
|
||||
*/
|
||||
public interface IJtOrderService {
|
||||
|
||||
boolean createOrder(List<VenueInfoDO> venueInfoDOS, UserTokenInfoDO userTokenInfoDO);
|
||||
|
||||
List<OrderInfoDO> queryNoPayOrder();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public interface IVenueService {
|
||||
List<SitePositionList> queryVenueService();
|
||||
List<SitePositionList> queryTomorrowVenue();
|
||||
List<VenueInfoDO> queryCanBuyVenue();
|
||||
List<VenueInfoDO> queryTomorrowCanBuyVenue();
|
||||
List<VenueInfoDO> queryToday6210VenueInfo();
|
||||
|
||||
/**
|
||||
@@ -23,4 +24,11 @@ public interface IVenueService {
|
||||
* @return
|
||||
*/
|
||||
boolean saveOrUpdateTodayVenueInfo(List<SitePositionList> sitePositionLists);
|
||||
|
||||
/**
|
||||
* 更新第二天的场地信息
|
||||
* @param sitePositionLists
|
||||
* @return
|
||||
*/
|
||||
boolean saveTomorrowVenueInfo(List<SitePositionList> sitePositionLists);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,11 @@ import com.xiang.app.modules.jntyzx.entity.resp.query.SitePositionList;
|
||||
import com.xiang.app.modules.jntyzx.entity.resp.query.VenueList;
|
||||
import com.xiang.app.modules.jntyzx.manage.IOrderCreateInfoManage;
|
||||
import com.xiang.app.modules.jntyzx.service.IJntyzxHttpService;
|
||||
import com.xiang.app.modules.jntyzx.utils.JntyzxSaltEncodeUtils;
|
||||
import com.xiang.xmc.service.cache.service.IRedisService;
|
||||
import com.xiang.xmc.service.http.helper.BaseHttpHelp;
|
||||
import com.xiang.xmc.service.http.helper.HttpHelper;
|
||||
import com.xiang.xmc.service.http.helper.HttpHelperFactory;
|
||||
import com.xiang.xservice.basic.utils.Base64;
|
||||
import com.xiang.xservice.basic.utils.JsonUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -109,8 +112,7 @@ public class JntyzxHttpServiceImpl implements IJntyzxHttpService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean createOrder(List<VenueInfoDO> venueInfos, String token) {
|
||||
|
||||
public JntyzxResponse<OrderCreateResp> createOrder(List<VenueInfoDO> venueInfos, String token) {
|
||||
List<SubscribeVo> vos = Lists.newArrayList();
|
||||
for (VenueInfoDO venueInfo : venueInfos) {
|
||||
SubscribeVo subscribeVo = new SubscribeVo();
|
||||
@@ -145,7 +147,7 @@ public class JntyzxHttpServiceImpl implements IJntyzxHttpService {
|
||||
subscribeRequest.setSubscribeVos(vos);
|
||||
subscribeRequest.setBookTime(venueInfos.get(0).getAppointments());
|
||||
subscribeRequest.setPaymentMethod(1);
|
||||
subscribeRequest.setSvCiphertext(sonAddSalt(JsonUtils.toJsonString(vos)));
|
||||
subscribeRequest.setSvCiphertext(JntyzxSaltEncodeUtils.sonAddSalt(JsonUtils.toJsonString(vos)));
|
||||
subscribeRequest.setJsonObject(jsonObject);
|
||||
|
||||
Map<String, String> params = Maps.newHashMap();
|
||||
@@ -153,32 +155,15 @@ public class JntyzxHttpServiceImpl implements IJntyzxHttpService {
|
||||
String resp = HttpHelper.doPost(UrlConstant.ADD_SUBSCRIBE, params, JsonUtils.toJsonString(subscribeRequest));
|
||||
if (StringUtils.isBlank(resp)) {
|
||||
log.info("请求结果为空");
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
JntyzxResponse<OrderCreateResp> response = JSON.parseObject(resp, new TypeReference<JntyzxResponse<OrderCreateResp>>() {
|
||||
});
|
||||
if (Objects.isNull(response)) {
|
||||
log.info("请求结果为空");
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
if (response.getSuccess()) {
|
||||
OrderCreateResp createResp = response.getResult();
|
||||
if (Objects.nonNull(createResp)) {
|
||||
String orderId = createResp.getId();
|
||||
redisService.set(RedisKeyConstant.JNTYZX_ORDER_CREATE_KEY + orderId, String.valueOf(System.currentTimeMillis()));
|
||||
OrderInfoDO orderInfoDO = new OrderInfoDO();
|
||||
orderInfoDO.setOrderId(orderId);
|
||||
orderInfoDO.setParams(JsonUtils.toJsonString(subscribeRequest));
|
||||
orderInfoDO.setCreateTime(LocalDateTime.now());
|
||||
orderInfoDO.setUsername(token);
|
||||
orderInfoDO.setPlaceName(vos.get(0).getPlaceName());
|
||||
orderInfoDO.setDate(LocalDate.now());
|
||||
orderInfoDO.setOrderStatus(0);
|
||||
orderCreateInfoManage.save(orderInfoDO);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return response;
|
||||
}
|
||||
@Override
|
||||
public JntyzxResponse healthDeclaration(String token, String openId) {
|
||||
@@ -214,30 +199,4 @@ public class JntyzxHttpServiceImpl implements IJntyzxHttpService {
|
||||
jsonObject.put("default05", null);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
private static int[] getMonthAndDay() {
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
int month = currentDate.getMonthValue();
|
||||
int day = currentDate.getDayOfMonth();
|
||||
return new int[]{month, day};
|
||||
}
|
||||
|
||||
private String sonAddSalt(String json) {
|
||||
String svCiphertext = "";
|
||||
String suiji = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
String token1 = String.valueOf(suiji.charAt((int) (Math.random() * (double) suiji.length())));
|
||||
String token2 = String.valueOf(suiji.charAt((int) (Math.random() * (double) suiji.length())));
|
||||
svCiphertext = Base64.encode(json.getBytes(StandardCharsets.UTF_8));
|
||||
int[] monthAndDay = getMonthAndDay();
|
||||
int month = monthAndDay[0];
|
||||
int day = monthAndDay[1];
|
||||
if (month == 1) {
|
||||
svCiphertext = (svCiphertext = token1 + svCiphertext).substring(0, day - 1) + token2 + svCiphertext.substring(day - 1);
|
||||
} else if (day == 1) {
|
||||
svCiphertext = token2 + svCiphertext.substring(0, month - 1) + token1 + svCiphertext.substring(month - 1);
|
||||
} else {
|
||||
svCiphertext = (svCiphertext = svCiphertext.substring(0, month - 1) + token1 + svCiphertext.substring(month - 1)).substring(0, day - 1) + token2 + svCiphertext.substring(day - 1);
|
||||
}
|
||||
return svCiphertext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,78 @@
|
||||
package com.xiang.app.modules.jntyzx.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.xiang.app.common.service.dingtalk.JtDingTalkFactory;
|
||||
import com.xiang.app.modules.jntyzx.constants.RedisKeyConstant;
|
||||
import com.xiang.app.modules.jntyzx.entity.pojo.OrderInfoDO;
|
||||
import com.xiang.app.modules.jntyzx.entity.pojo.UserTokenInfoDO;
|
||||
import com.xiang.app.modules.jntyzx.entity.pojo.VenueInfoDO;
|
||||
import com.xiang.app.modules.jntyzx.entity.resp.JntyzxResponse;
|
||||
import com.xiang.app.modules.jntyzx.entity.resp.OrderCreateResp;
|
||||
import com.xiang.app.modules.jntyzx.manage.IOrderCreateInfoManage;
|
||||
import com.xiang.app.modules.jntyzx.service.IJntyzxHttpService;
|
||||
import com.xiang.app.modules.jntyzx.service.IJtOrderService;
|
||||
import com.xiang.xmc.service.cache.service.IRedisService;
|
||||
import com.xiang.xservice.basic.utils.JsonUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-16 16:17
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class OrderInfoServiceImpl implements IJtOrderService {
|
||||
|
||||
private final IOrderCreateInfoManage orderCreateInfoManage;
|
||||
private final IJntyzxHttpService jntyzxHttpService;
|
||||
private final IRedisService redisService;
|
||||
private final JtDingTalkFactory dingTalkFactory;
|
||||
@Override
|
||||
public List<OrderInfoDO> queryNoPayOrder() {
|
||||
return orderCreateInfoManage.queryNoPayOrder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createOrder(List<VenueInfoDO> venueInfoDOS, UserTokenInfoDO userTokenInfoDO) {
|
||||
|
||||
String order = (String) redisService.get(RedisKeyConstant.JNTYZX_ORDER_CREATE_KEY + userTokenInfoDO.getName());
|
||||
if (StringUtils.isNotBlank(order)) {
|
||||
log.info("用户:{}已经有成功预订了场地", userTokenInfoDO.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
JntyzxResponse<OrderCreateResp> orderResp = jntyzxHttpService.createOrder(venueInfoDOS, userTokenInfoDO.getToken());
|
||||
if (Objects.isNull(orderResp)) {
|
||||
return false;
|
||||
}
|
||||
if (orderResp.getSuccess()) {
|
||||
OrderCreateResp result = orderResp.getResult();
|
||||
if (Objects.nonNull(result)) {
|
||||
String orderId = result.getId();
|
||||
if (StringUtils.isNotBlank(orderId)) {
|
||||
redisService.set(RedisKeyConstant.JNTYZX_ORDER_CREATE_KEY + userTokenInfoDO.getName(), orderId);
|
||||
OrderInfoDO orderInfoDO = new OrderInfoDO();
|
||||
orderInfoDO.setOrderId(orderId);
|
||||
orderInfoDO.setCreateTime(LocalDateTime.now());
|
||||
orderInfoDO.setUsername(userTokenInfoDO.getName());
|
||||
orderInfoDO.setPlaceName(venueInfoDOS.get(0).getPlaceName());
|
||||
orderInfoDO.setDate(LocalDate.now());
|
||||
orderInfoDO.setOrderStatus(0);
|
||||
orderCreateInfoManage.save(orderInfoDO);
|
||||
}
|
||||
}
|
||||
}
|
||||
dingTalkFactory.sendMsg("用户" + userTokenInfoDO.getName() + "预订场地号:" + venueInfoDOS.get(0).getPlaceName() + "结果返回:" + JSON.toJSONString(orderResp));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,11 @@ public class VenueServiceImpl implements IVenueService {
|
||||
return venueInfoManage.queryByType(LocalDate.now(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VenueInfoDO> queryTomorrowCanBuyVenue() {
|
||||
return venueInfoManage.queryByType(LocalDate.now().plusDays(1), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VenueInfoDO> queryToday6210VenueInfo() {
|
||||
List<VenueInfoDO> venueInfoDOS = venueInfoManage.queryByDate(LocalDate.now());
|
||||
@@ -127,6 +132,29 @@ public class VenueServiceImpl implements IVenueService {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveTomorrowVenueInfo(List<SitePositionList> sitePositionLists) {
|
||||
for (SitePositionList sitePositionList : sitePositionLists) {
|
||||
VenueInfoDO venueInfoDO = new VenueInfoDO();
|
||||
venueInfoDO.setDate(LocalDate.now().plusDays(1));
|
||||
venueInfoDO.setCreateTime(LocalDateTime.now());
|
||||
venueInfoDO.setPlaceName(sitePositionList.getPlaceName());
|
||||
venueInfoDO.setPlaceMainId(sitePositionList.getId());
|
||||
venueInfoDO.setPlaceId(sitePositionList.getPlaceId());
|
||||
venueInfoDO.setScheduleId(Integer.valueOf(sitePositionList.getScheduleId()));
|
||||
venueInfoDO.setSjName(sitePositionList.getSjName());
|
||||
venueInfoDO.setContacts(sitePositionList.getContacts());
|
||||
venueInfoDO.setType(sitePositionList.getType());
|
||||
venueInfoDO.setMoney(sitePositionList.getMoney());
|
||||
venueInfoDO.setClassName(sitePositionList.getClassName());
|
||||
venueInfoDO.setClassCode(sitePositionList.getClassCode());
|
||||
venueInfoDO.setAppointments(sitePositionList.getAppointments());
|
||||
venueInfoDO.setCTypeCode(sitePositionList.getCtypeCode());
|
||||
venueInfoManage.save(venueInfoDO);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateDatabase(List<SitePositionList> list, boolean isToday) {
|
||||
List<VenueInfoDO> venueInfoDOS = Lists.newArrayList();
|
||||
if (isToday) {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.xiang.app.modules.jntyzx.utils;
|
||||
|
||||
import com.xiang.xservice.basic.utils.Base64;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class JntyzxSaltEncodeUtils {
|
||||
|
||||
private static int[] getMonthAndDay() {
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
int month = currentDate.getMonthValue();
|
||||
int day = currentDate.getDayOfMonth();
|
||||
return new int[]{month, day};
|
||||
}
|
||||
|
||||
public static String sonAddSalt(String json) {
|
||||
String svCiphertext = "";
|
||||
String suiji = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
String token1 = String.valueOf(suiji.charAt((int) (Math.random() * (double) suiji.length())));
|
||||
String token2 = String.valueOf(suiji.charAt((int) (Math.random() * (double) suiji.length())));
|
||||
svCiphertext = Base64.encode(json.getBytes(StandardCharsets.UTF_8));
|
||||
int[] monthAndDay = getMonthAndDay();
|
||||
int month = monthAndDay[0];
|
||||
int day = monthAndDay[1];
|
||||
if (month == 1) {
|
||||
svCiphertext = (svCiphertext = token1 + svCiphertext).substring(0, day - 1) + token2 + svCiphertext.substring(day - 1);
|
||||
} else if (day == 1) {
|
||||
svCiphertext = token2 + svCiphertext.substring(0, month - 1) + token1 + svCiphertext.substring(month - 1);
|
||||
} else {
|
||||
svCiphertext = (svCiphertext = svCiphertext.substring(0, month - 1) + token1 + svCiphertext.substring(month - 1)).substring(0, day - 1) + token2 + svCiphertext.substring(day - 1);
|
||||
}
|
||||
return svCiphertext;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.xiang.app.modules.jntyzx.utils;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class WeekendUtils {
|
||||
|
||||
public static String isWeekend() {
|
||||
LocalDate tomorrow = LocalDate.now().plusDays(1);
|
||||
DayOfWeek dayOfWeek = tomorrow.getDayOfWeek();
|
||||
String isWeekend = "0";
|
||||
if (dayOfWeek.getValue() == 6 || dayOfWeek.getValue() == 7 ) {
|
||||
isWeekend = "1";
|
||||
}
|
||||
return isWeekend;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user