提交代码

dev-discount
胡锐 3 years ago
parent 1e9806066b
commit abaf6d1697
  1. 19
      hai-bweb/src/main/java/com/bweb/config/RedisConfig.java
  2. 34
      hai-bweb/src/main/java/com/bweb/config/msg/RedisKeyExpirationListener.java
  3. 106
      hai-bweb/src/main/java/com/bweb/controller/HighGasOilPriceTaskController.java
  4. 3
      hai-service/src/main/java/com/hai/msg/entity/MsgTopic.java
  5. 6
      hai-service/src/main/java/com/hai/service/HighGasOilPriceTaskService.java
  6. 13
      hai-service/src/main/java/com/hai/service/impl/HighGasOilPriceTaskServiceImpl.java

@ -3,12 +3,16 @@ package com.bweb.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.hai.msg.entity.MsgTopic;
import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.*; import org.springframework.data.redis.core.*;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;
@ -17,6 +21,19 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
@EnableCaching //开启注解 @EnableCaching //开启注解
public class RedisConfig extends CachingConfigurerSupport { public class RedisConfig extends CachingConfigurerSupport {
@Bean(destroyMethod = "destroy")
public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory factory,
MessageListener driverLBSMsgListener) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(factory);
//可以添加多个 messageListener
container.addMessageListener(driverLBSMsgListener, new PatternTopic(MsgTopic.oilPriceTask.getName()));
return container;
}
/** /**
* retemplate相关配置 * retemplate相关配置
* @param factory * @param factory
@ -106,4 +123,4 @@ public class RedisConfig extends CachingConfigurerSupport {
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) { public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForZSet(); return redisTemplate.opsForZSet();
} }
} }

@ -0,0 +1,34 @@
package com.bweb.config.msg;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;
/**
* @author hurui
* @version 1.0
* @ClassName RedisKeyExpirationListener
* @description: TODO
* @date 2021/8/19 10:00
*/
@Component
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
private static Logger logger = LoggerFactory.getLogger(RedisKeyExpirationListener.class);
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
super(listenerContainer);
}
public void onMessage(Message message, byte[] pattern) {
try {
System.out.println(message);
} catch (Exception e) {
logger.error("redis过期事件异常:",e);
}
}
}

@ -6,9 +6,18 @@ import com.github.pagehelper.PageInfo;
import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighGasOilPriceTask;
import com.hai.entity.HighMerchantStore;
import com.hai.entity.SecDictionary;
import com.hai.entity.SecRegion;
import com.hai.enum_type.GasTaskPriceTypeEnum;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
import com.hai.model.UserInfoModel;
import com.hai.service.CommonService;
import com.hai.service.HighGasOilPriceTaskService; import com.hai.service.HighGasOilPriceTaskService;
import com.hai.service.HighMerchantStoreService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -18,6 +27,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
@Controller @Controller
@ -30,19 +40,95 @@ public class HighGasOilPriceTaskController {
@Resource @Resource
private HighGasOilPriceTaskService gasOilPriceTaskService; private HighGasOilPriceTaskService gasOilPriceTaskService;
@RequestMapping(value="/addTask",method = RequestMethod.POST) @Resource
private HighMerchantStoreService merchantStoreService;
@Resource
private CommonService commonService;
@Resource
private UserCenter userCenter;
@RequestMapping(value="/batchAddTask",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "增加任务") @ApiOperation(value = "批量增加任务")
public ResponseData addTask(@RequestBody JSONObject body) { public ResponseData batchAddTask(@RequestBody List<HighGasOilPriceTask> taskList) {
try { try {
if (body.getLong("regionId") == null UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class);
|| body.getInteger("oilNo") == null if (userInfoModel == null) {
|| body.getBigDecimal("price") == null log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!","");
) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, "");
}
if (taskList == null || taskList.size() == 0) {
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!",""); log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!","");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
for (HighGasOilPriceTask task : taskList) {
if (task.getPriceType() == null
|| task.getPrice() == null
|| task.getOilNo() == null
|| task.getExecutionType() == null
) {
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!","");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 执行方式 1. 立刻执行 2. 定时执行
if (task.getExecutionType().equals(2) && task.getStartTime() == null) {
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!","");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未配置执行时间");
}
// 价格类型 1. 国标价 2. 油站价 3. 优惠幅度
if (task.getPriceType().equals(GasTaskPriceTypeEnum.type1.getStatus())) {
if (task.getRegionId() == null) {
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!","");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未配置区域");
}
// 加油站
SecRegion region = commonService.getRegionsById(task.getRegionId());
if (region == null) {
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!","");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到区域");
}
task.setRegionId(region.getRegionId());
task.setRegionName(region.getRegionName());
}
// 价格类型 1. 国标价 2. 油站价 3. 优惠幅度
if (task.getPriceType().equals(GasTaskPriceTypeEnum.type2.getStatus())
|| task.getPriceType().equals(GasTaskPriceTypeEnum.type3.getStatus())) {
if (task.getMerStoreId() == null) {
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!","");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未配置加油站");
}
// 加油站
HighMerchantStore store = merchantStoreService.getDetailById(task.getMerStoreId());
if (store == null) {
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!","");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到加油站");
}
task.setMerStoreId(store.getId());
task.setMerStoreName(store.getStoreName());
task.setMerStoreAddress(store.getAddress());
}
// 查询油品
SecDictionary oil = commonService.mappingSysCode("GAS_OIL_TYPE", task.getOilNo().toString());
if (oil == null) {
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!","");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
task.setOilType(Integer.parseInt(oil.getExt1()));
task.setOilTypeName(oil.getExt2());
task.setOilNoName(oil.getCodeName());
task.setOpUserId(userInfoModel.getSecUser().getId());
task.setOpUserName(userInfoModel.getSecUser().getUserName());
}
gasOilPriceTaskService.batchAddTask(taskList);
return ResponseMsgUtil.success("操作成功"); return ResponseMsgUtil.success("操作成功");
} catch (Exception e) { } catch (Exception e) {
@ -103,6 +189,12 @@ public class HighGasOilPriceTaskController {
Map<String, Object> param = new HashMap<>(); Map<String, Object> param = new HashMap<>();
param.put("regionId", regionId); param.put("regionId", regionId);
param.put("regionName", regionName); param.put("regionName", regionName);
param.put("merStoreId", status);
param.put("merStoreName", status);
param.put("oilType", status);
param.put("oilNo", status);
param.put("priceType", status);
param.put("executionType", status);
param.put("status", status); param.put("status", status);
PageHelper.startPage(pageNum,pageSize); PageHelper.startPage(pageNum,pageSize);

@ -3,7 +3,8 @@ package com.hai.msg.entity;
public enum MsgTopic { public enum MsgTopic {
// 门店账户业务员 // 门店账户业务员
MerStoreAccount("mer-store-account"); MerStoreAccount("mer-store-account"),
oilPriceTask("OIL-PRICE-TASK");
private String name; private String name;

@ -17,6 +17,12 @@ public interface HighGasOilPriceTaskService {
*/ */
void editData(HighGasOilPriceTask gasOilPriceTask); void editData(HighGasOilPriceTask gasOilPriceTask);
/**
* 批量增加价格任务
* @param taskList
*/
void batchAddTask(List<HighGasOilPriceTask> taskList);
/** /**
* 增加价格任务 * 增加价格任务
* @param gasOilPriceTask * @param gasOilPriceTask

@ -17,6 +17,8 @@ import com.hai.service.HighGasOilPriceTaskService;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
@ -48,14 +50,21 @@ public class HighGasOilPriceTaskServiceImpl implements HighGasOilPriceTaskServic
} }
@Override @Override
@Transactional(propagation= Propagation.REQUIRED)
public void batchAddTask(List<HighGasOilPriceTask> taskList) {
for (HighGasOilPriceTask task : taskList) {
addTask(task);
}
}
@Override
@Transactional(propagation= Propagation.REQUIRED)
public void addTask(HighGasOilPriceTask gasOilPriceTask) { public void addTask(HighGasOilPriceTask gasOilPriceTask) {
editData(gasOilPriceTask); editData(gasOilPriceTask);
// 立刻执行 // 立刻执行
if (gasOilPriceTask.getExecutionType().equals(GasTaskExecutionTypeEnum.type1.getStatus())) { if (gasOilPriceTask.getExecutionType().equals(GasTaskExecutionTypeEnum.type1.getStatus())) {
businessHandle(gasOilPriceTask); businessHandle(gasOilPriceTask);
} }
} }
@Override @Override

Loading…
Cancel
Save