|
|
|
@ -3,6 +3,8 @@ package com.hai.service.impl; |
|
|
|
|
import com.hai.common.exception.ErrorCode; |
|
|
|
|
import com.hai.common.exception.ErrorHelp; |
|
|
|
|
import com.hai.common.exception.SysCode; |
|
|
|
|
import com.hai.common.utils.DateUtil; |
|
|
|
|
import com.hai.common.utils.RedisUtil; |
|
|
|
|
import com.hai.dao.HighGasOilPriceTaskMapper; |
|
|
|
|
import com.hai.entity.HighGasOilPrice; |
|
|
|
|
import com.hai.entity.HighGasOilPriceOfficial; |
|
|
|
@ -11,6 +13,7 @@ import com.hai.entity.HighGasOilPriceTaskExample; |
|
|
|
|
import com.hai.enum_type.GasTaskExecutionTypeEnum; |
|
|
|
|
import com.hai.enum_type.GasTaskPriceTypeEnum; |
|
|
|
|
import com.hai.enum_type.GasTaskStatusEnum; |
|
|
|
|
import com.hai.msg.entity.MsgTopic; |
|
|
|
|
import com.hai.service.HighGasOilPriceOfficialService; |
|
|
|
|
import com.hai.service.HighGasOilPriceService; |
|
|
|
|
import com.hai.service.HighGasOilPriceTaskService; |
|
|
|
@ -28,6 +31,9 @@ import java.util.Map; |
|
|
|
|
@Service("gasOilPriceTaskService") |
|
|
|
|
public class HighGasOilPriceTaskServiceImpl implements HighGasOilPriceTaskService { |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private RedisUtil redisUtil; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private HighGasOilPriceTaskMapper gasOilPriceTaskMapper; |
|
|
|
|
|
|
|
|
@ -64,56 +70,58 @@ public class HighGasOilPriceTaskServiceImpl implements HighGasOilPriceTaskServic |
|
|
|
|
// 立刻执行
|
|
|
|
|
if (gasOilPriceTask.getExecutionType().equals(GasTaskExecutionTypeEnum.type1.getStatus())) { |
|
|
|
|
businessHandle(gasOilPriceTask); |
|
|
|
|
|
|
|
|
|
} else if (gasOilPriceTask.getExecutionType().equals(GasTaskExecutionTypeEnum.type2.getStatus())) { |
|
|
|
|
redisUtil.set(MsgTopic.oilPriceTask.getName() + "-" + gasOilPriceTask, DateUtil.getSecondDiff(new Date(), gasOilPriceTask.getStartTime())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(propagation= Propagation.REQUIRED) |
|
|
|
|
public void businessHandle(HighGasOilPriceTask gasOilPriceTask) { |
|
|
|
|
// 立刻执行
|
|
|
|
|
if (gasOilPriceTask.getExecutionType().equals(GasTaskExecutionTypeEnum.type1.getStatus())) { |
|
|
|
|
gasOilPriceTask.setStartTime(new Date()); |
|
|
|
|
gasOilPriceTask.setStatus(GasTaskStatusEnum.status2.getStatus()); |
|
|
|
|
editData(gasOilPriceTask); |
|
|
|
|
|
|
|
|
|
// 国标价
|
|
|
|
|
if (gasOilPriceTask.getPriceType().equals(GasTaskPriceTypeEnum.type1.getStatus())) { |
|
|
|
|
// 查询国标价油品价格
|
|
|
|
|
HighGasOilPriceOfficial price = gasOilPriceOfficialService.getPrice(gasOilPriceTask.getRegionId(), gasOilPriceTask.getOilNo()); |
|
|
|
|
if (price == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到油品价格"); |
|
|
|
|
} |
|
|
|
|
gasOilPriceOfficialService.editPrice(gasOilPriceTask.getRegionId(), gasOilPriceTask.getOilNo(), gasOilPriceTask.getPrice()); |
|
|
|
|
|
|
|
|
|
new Thread(() -> { |
|
|
|
|
gasOilPriceOfficialService.refreshGasPriceOfficial(gasOilPriceTask.getRegionId(), gasOilPriceTask.getOilNo()); |
|
|
|
|
}).start(); |
|
|
|
|
} |
|
|
|
|
gasOilPriceTask.setStartTime(new Date()); |
|
|
|
|
gasOilPriceTask.setStatus(GasTaskStatusEnum.status2.getStatus()); |
|
|
|
|
editData(gasOilPriceTask); |
|
|
|
|
|
|
|
|
|
// 油站价
|
|
|
|
|
if (gasOilPriceTask.getPriceType().equals(GasTaskPriceTypeEnum.type2.getStatus())) { |
|
|
|
|
// 查询油品价格
|
|
|
|
|
HighGasOilPrice price = gasOilPriceService.getGasOilPriceByStoreAndOilNo(gasOilPriceTask.getMerStoreId(), gasOilPriceTask.getOilNo()); |
|
|
|
|
if (price == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到油品价格"); |
|
|
|
|
} |
|
|
|
|
price.setPriceGun(gasOilPriceTask.getPrice()); |
|
|
|
|
price.setPriceVip(gasOilPriceTask.getPrice().subtract(price.getPreferentialMargin())); |
|
|
|
|
gasOilPriceService.editGasOilPrice(price); |
|
|
|
|
// 国标价
|
|
|
|
|
if (gasOilPriceTask.getPriceType().equals(GasTaskPriceTypeEnum.type1.getStatus())) { |
|
|
|
|
// 查询国标价油品价格
|
|
|
|
|
HighGasOilPriceOfficial price = gasOilPriceOfficialService.getPrice(gasOilPriceTask.getRegionId(), gasOilPriceTask.getOilNo()); |
|
|
|
|
if (price == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到油品价格"); |
|
|
|
|
} |
|
|
|
|
gasOilPriceOfficialService.editPrice(gasOilPriceTask.getRegionId(), gasOilPriceTask.getOilNo(), gasOilPriceTask.getPrice()); |
|
|
|
|
|
|
|
|
|
// 优惠幅度
|
|
|
|
|
if (gasOilPriceTask.getPriceType().equals(GasTaskPriceTypeEnum.type3.getStatus())) { |
|
|
|
|
// 查询油品价格
|
|
|
|
|
HighGasOilPrice price = gasOilPriceService.getGasOilPriceByStoreAndOilNo(gasOilPriceTask.getMerStoreId(), gasOilPriceTask.getOilNo()); |
|
|
|
|
if (price == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到油品价格"); |
|
|
|
|
} |
|
|
|
|
price.setPreferentialMargin(gasOilPriceTask.getPrice()); |
|
|
|
|
price.setPriceVip(price.getPriceGun().subtract(price.getPreferentialMargin())); |
|
|
|
|
gasOilPriceService.editGasOilPrice(price); |
|
|
|
|
new Thread(() -> { |
|
|
|
|
gasOilPriceOfficialService.refreshGasPriceOfficial(gasOilPriceTask.getRegionId(), gasOilPriceTask.getOilNo()); |
|
|
|
|
}).start(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 油站价
|
|
|
|
|
if (gasOilPriceTask.getPriceType().equals(GasTaskPriceTypeEnum.type2.getStatus())) { |
|
|
|
|
// 查询油品价格
|
|
|
|
|
HighGasOilPrice price = gasOilPriceService.getGasOilPriceByStoreAndOilNo(gasOilPriceTask.getMerStoreId(), gasOilPriceTask.getOilNo()); |
|
|
|
|
if (price == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到油品价格"); |
|
|
|
|
} |
|
|
|
|
price.setPriceGun(gasOilPriceTask.getPrice()); |
|
|
|
|
price.setPriceVip(gasOilPriceTask.getPrice().subtract(price.getPreferentialMargin())); |
|
|
|
|
gasOilPriceService.editGasOilPrice(price); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 优惠幅度
|
|
|
|
|
if (gasOilPriceTask.getPriceType().equals(GasTaskPriceTypeEnum.type3.getStatus())) { |
|
|
|
|
// 查询油品价格
|
|
|
|
|
HighGasOilPrice price = gasOilPriceService.getGasOilPriceByStoreAndOilNo(gasOilPriceTask.getMerStoreId(), gasOilPriceTask.getOilNo()); |
|
|
|
|
if (price == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到油品价格"); |
|
|
|
|
} |
|
|
|
|
price.setPreferentialMargin(gasOilPriceTask.getPrice()); |
|
|
|
|
price.setPriceVip(price.getPriceGun().subtract(price.getPreferentialMargin())); |
|
|
|
|
gasOilPriceService.editGasOilPrice(price); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -130,6 +138,9 @@ public class HighGasOilPriceTaskServiceImpl implements HighGasOilPriceTaskServic |
|
|
|
|
} |
|
|
|
|
detail.setStatus(GasTaskStatusEnum.status0.getStatus()); |
|
|
|
|
editData(detail); |
|
|
|
|
|
|
|
|
|
// 从redis中删除任务
|
|
|
|
|
redisUtil.del(MsgTopic.oilPriceTask.getName() + "-" + taskId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|