推送车型套餐为商品

This commit is contained in:
19173159168
2025-09-05 00:17:54 +08:00
parent e93d15535e
commit 88dece40d9
9 changed files with 177 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package com.ruoyi.api;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.orders.domain.ZcOrderSub; import com.ruoyi.orders.domain.ZcOrderSub;
import com.ruoyi.orders.dto.PushItemRequest;
import com.ruoyi.orders.dto.RefundRequest; import com.ruoyi.orders.dto.RefundRequest;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -21,8 +22,10 @@ public class DataPushApi {
@Autowired @Autowired
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
@Value(value = "${pay.refundUrl}") @Value(value = "${dataPush.refundUrl}")
private String refundUrl; private String refundUrl;
@Value(value = "${dataPush.pushItemUrl}")
private String pushItemUrl;
@Value(value = "${dataPush.sendAddCompanyUrl}") @Value(value = "${dataPush.sendAddCompanyUrl}")
private String sendAddCompanyUrl; private String sendAddCompanyUrl;
@ -158,4 +161,51 @@ public class DataPushApi {
} }
} }
public boolean sendPushItem(PushItemRequest pushItemRequest) {
try {
// 打印请求参数便于调试
String jsonParams = objectMapper.writeValueAsString(pushItemRequest);
logger.info("推送车型、套餐为商品请求参数: {}", jsonParams);
// 发送HTTP请求调用添加接口
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.getForEntity(pushItemUrl + "?brandId="+pushItemRequest.getBrandId()+"&carModelId="+pushItemRequest.getCarModelId()+"&carRuleId="+pushItemRequest.getCarRuleId()+"&batteryRuleId="+pushItemRequest.getBatteryRuleId(), String.class);
// 处理退款接口响应
if (response.getStatusCode() == HttpStatus.OK) {
// 解析响应内容检查return_code是否为SUCCESS
String responseBody = response.getBody();
if (responseBody != null) {
try {
// 使用ObjectMapper解析JSON响应
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
Object returnCode = responseMap.get("code");
if ("10000".equals(returnCode)) {
logger.info("推送车型、套餐为商品成功");
return true;
} else {
logger.error("推送车型、套餐为商品失败,响应: {}", responseBody);
return false;
}
} catch (Exception jsonEx) {
logger.error("推送车型、套餐为商品解析响应异常,响应: {}", responseBody, jsonEx);
return false;
}
} else {
logger.error("推送车型、套餐为商品返回空响应");
return false;
}
} else {
logger.error("推送车型、套餐为商品失败,响应: {}",response.getBody());
return false;
}
} catch (Exception e) {
logger.error("推送车型、套餐为商品异常", e);
return false;
}
}
} }

View File

@ -1,7 +1,10 @@
package com.ruoyi.operation.mapper; package com.ruoyi.operation.mapper;
import java.util.List; import java.util.List;
import java.util.Map;
import com.ruoyi.operation.domain.ZcCarModelPackage; import com.ruoyi.operation.domain.ZcCarModelPackage;
import com.ruoyi.orders.dto.PushItemRequest;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
/** /**
@ -45,7 +48,7 @@ public interface ZcCarModelPackageMapper
* @return 结果 * @return 结果
*/ */
public int updateZcCarModelPackage(ZcCarModelPackage zcCarModelPackage); public int updateZcCarModelPackage(ZcCarModelPackage zcCarModelPackage);
public int updateZcCarModelPackageStatus(Long id);
/** /**
* 删除车型与租车规则关联 * 删除车型与租车规则关联
* *
@ -65,4 +68,6 @@ public interface ZcCarModelPackageMapper
* @return 结果 * @return 结果
*/ */
public int deleteZcCarModelPackageByIds(String[] ids); public int deleteZcCarModelPackageByIds(String[] ids);
public List<PushItemRequest> selectZcCarModelPackageNotPush();
} }

View File

@ -62,4 +62,9 @@ public interface IZcCarModelPackageService
* @return 结果 * @return 结果
*/ */
public int deleteZcCarModelPackageById(Long id); public int deleteZcCarModelPackageById(Long id);
/**
* 推送车型绑定的套餐关系为商品至支付宝
*/
public void carModelCommodityToAlipay();
} }

View File

@ -1,7 +1,10 @@
package com.ruoyi.operation.service.impl; package com.ruoyi.operation.service.impl;
import java.util.List; import java.util.List;
import com.ruoyi.api.DataPushApi;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.orders.dto.PushItemRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.operation.mapper.ZcCarModelPackageMapper; import com.ruoyi.operation.mapper.ZcCarModelPackageMapper;
@ -16,10 +19,12 @@ import com.ruoyi.common.core.text.Convert;
* @date 2025-07-10 * @date 2025-07-10
*/ */
@Service @Service
public class ZcCarModelPackageServiceImpl implements IZcCarModelPackageService public class ZcCarModelPackageServiceImpl implements IZcCarModelPackageService
{ {
@Autowired @Autowired
private ZcCarModelPackageMapper zcCarModelPackageMapper; private ZcCarModelPackageMapper zcCarModelPackageMapper;
@Autowired
private DataPushApi dataPushApi;
/** /**
* 查询车型与租车规则关联 * 查询车型与租车规则关联
@ -111,4 +116,18 @@ public class ZcCarModelPackageServiceImpl implements IZcCarModelPackageService
{ {
return zcCarModelPackageMapper.deleteZcCarModelPackageById(id); return zcCarModelPackageMapper.deleteZcCarModelPackageById(id);
} }
/**
* 批量推送车型组装后变为商品
*/
@Override
public void carModelCommodityToAlipay() {
List<PushItemRequest> list = zcCarModelPackageMapper.selectZcCarModelPackageNotPush();
for (PushItemRequest pushItemRequest : list) {
boolean bool = dataPushApi.sendPushItem(pushItemRequest);
if(bool) {
zcCarModelPackageMapper.updateZcCarModelPackageStatus(pushItemRequest.getId());
}
}
}
} }

View File

@ -0,0 +1,50 @@
package com.ruoyi.orders.dto;
public class PushItemRequest {
private Long id;
private Long carModelId;
private Long carRuleId;
private Long brandId;
private Long batteryRuleId;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getCarModelId() {
return carModelId;
}
public void setCarModelId(Long carModelId) {
this.carModelId = carModelId;
}
public Long getCarRuleId() {
return carRuleId;
}
public void setCarRuleId(Long carRuleId) {
this.carRuleId = carRuleId;
}
public Long getBrandId() {
return brandId;
}
public void setBrandId(Long brandId) {
this.brandId = brandId;
}
public Long getBatteryRuleId() {
return batteryRuleId;
}
public void setBatteryRuleId(Long batteryRuleId) {
this.batteryRuleId = batteryRuleId;
}
}

View File

@ -0,0 +1,26 @@
package com.ruoyi.task;
import com.ruoyi.operation.service.IZcCarModelPackageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@EnableScheduling
@Component
public class CarModelCommodityTask {
private static final Logger logger = LoggerFactory.getLogger(CarModelCommodityTask.class);
@Autowired
private IZcCarModelPackageService zcCarModelPackageService;
@Scheduled(cron = "0 30 * * * ?")
public void carModelCommodityTask() {
logger.info("执行推送车型+套餐变商品任务--开始");
zcCarModelPackageService.carModelCommodityToAlipay();
logger.info("执行推送车型+套餐变商品任务--结束");
}
}

View File

@ -83,10 +83,10 @@ renren:
expire: 604800 expire: 604800
header: token header: token
pay:
refundUrl: http://115.190.8.52:8019/api/payment/refund
dataPush: dataPush:
refundUrl: http://115.190.8.52:8019/api/payment/refund
pushItemUrl: http://115.190.8.52:8019/item/sync/item
sendAddCompanyUrl: http://115.190.8.52:8016/send/companyinfo/ sendAddCompanyUrl: http://115.190.8.52:8016/send/companyinfo/
sendAddStoreUrl: http://115.190.8.52:8016/send/storeinfo/ sendAddStoreUrl: http://115.190.8.52:8016/send/storeinfo/
sendAddUserUrl: http://115.190.8.52:8016/send/userinfo/ sendAddUserUrl: http://115.190.8.52:8016/send/userinfo/

View File

@ -34,7 +34,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectZcCarModelPackageVo"/> <include refid="selectZcCarModelPackageVo"/>
where id = #{id} where id = #{id}
</select> </select>
<select id="selectZcCarModelPackageNotPush" resultType="com.ruoyi.orders.dto.PushItemRequest">
select mp.id,
mp.car_model_id as 'carModelId',
mp.car_rule_id as 'carRuleId',
m.brand_id as 'brandId',
rb.battery_rule_id as 'batteryRuleId'
from zc_car_model_package mp
left join zc_car_model m on mp.car_model_id = m.id
left join zc_rent_car_rule_battery rb on mp.car_rule_id = rb.car_rule_id
where mp.status = '0'
</select>
<insert id="insertZcCarModelPackage" parameterType="ZcCarModelPackage" useGeneratedKeys="true" keyProperty="id"> <insert id="insertZcCarModelPackage" parameterType="ZcCarModelPackage" useGeneratedKeys="true" keyProperty="id">
insert into zc_car_model_package insert into zc_car_model_package
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
@ -82,6 +93,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>
<update id="updateZcCarModelPackageStatus">
update zc_car_model_package set status = '1' where id = #{id}
</update>
<delete id="deleteZcCarModelPackageById" parameterType="Long"> <delete id="deleteZcCarModelPackageById" parameterType="Long">
delete from zc_car_model_package where id = #{id} delete from zc_car_model_package where id = #{id}

View File

@ -115,7 +115,7 @@ public class Constants
/** /**
* 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加) * 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加)
*/ */
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" }; public static final String[] JOB_WHITELIST_STR = { "com.ruoyi.task" };
/** /**
* 定时任务违规的字符 * 定时任务违规的字符