feat:()修改策略信息存储方法
parent
2e5cb19f4f
commit
a1ed677f0f
|
@ -3,11 +3,12 @@ package com.muyu.enterprise.cache;
|
|||
import com.muyu.common.cache.CacheAbsBacis;
|
||||
import com.muyu.domain.WarnRule;
|
||||
import com.muyu.domain.WarnStrategy;
|
||||
import com.muyu.domain.resp.WarnRuleResp;
|
||||
|
||||
/**
|
||||
* 预警策略缓存服务
|
||||
*/
|
||||
public class WarnStrategyCacheService extends CacheAbsBacis<String, WarnStrategy> {
|
||||
public class WarnStrategyCacheService extends CacheAbsBacis<String, WarnRuleResp> {
|
||||
@Override
|
||||
public void clear() {
|
||||
|
||||
|
|
|
@ -43,11 +43,6 @@ public class WarnRule extends BaseEntity{
|
|||
@Excel(name = "规则名称")
|
||||
private String ruleName;
|
||||
|
||||
/** 策略id */
|
||||
@Schema(type = "Integer",description = "策略id")
|
||||
@Excel(name = "策略id")
|
||||
private Integer strategyId;
|
||||
|
||||
/** 报文数据类型id */
|
||||
@Schema(type = "Integer",description = "报文数据类型id")
|
||||
@Excel(name = "报文数据类型id")
|
||||
|
@ -87,7 +82,6 @@ public class WarnRule extends BaseEntity{
|
|||
return WarnRule.builder()
|
||||
.warnRuleId(supplier.get())
|
||||
.ruleName(warnRule.getRuleName())
|
||||
.strategyId(warnRule.getStrategyId())
|
||||
.msgTypeId(warnRule.getMsgTypeId())
|
||||
.slideTime(warnRule.getSlideTime())
|
||||
.slideFrequency(warnRule.getSlideFrequency())
|
||||
|
@ -102,7 +96,6 @@ public class WarnRule extends BaseEntity{
|
|||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getWarnRuleId())
|
||||
.append("ruleName", getRuleName())
|
||||
.append("strategyId", getStrategyId())
|
||||
.append("msgTypeId", getMsgTypeId())
|
||||
.append("slideTime", getSlideTime())
|
||||
.append("slideFrequency", getSlideFrequency())
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package com.muyu.domain.resp;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.domain.WarnRule;
|
||||
import com.muyu.domain.WarnStrategy;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Tag(name = "规则列表", description = "规则列表")
|
||||
public class WarnRuleResp {
|
||||
|
||||
/** 策略id */
|
||||
@Schema(type = "Long",description = "策略id")
|
||||
@TableId( type = IdType.AUTO)
|
||||
private Long warnStrategyId;
|
||||
|
||||
/** 策略名称 */
|
||||
@Schema(type = "String",description = "策略名称")
|
||||
@Excel(name = "策略名称")
|
||||
private String strategyName;
|
||||
|
||||
/** 报文模版id */
|
||||
@Schema(type = "Integer",description = "报文模版id")
|
||||
@Excel(name = "报文模版id")
|
||||
private Integer messageTemplateId;
|
||||
|
||||
/** 车辆类型id */
|
||||
@Schema(type = "Long",description = "车辆类型id")
|
||||
@Excel(name = "车辆类型id")
|
||||
private Long vehicleTypeId;
|
||||
|
||||
/** 规则集合 */
|
||||
@Schema(type = "List",description = "规则集合")
|
||||
private List<WarnRule> warnRuleList;
|
||||
|
||||
public static WarnRuleResp build(WarnStrategy warnStrategy, List<WarnRule> warnRuleList){
|
||||
return WarnRuleResp.builder()
|
||||
.warnStrategyId(warnStrategy.getWarnStrategyId())
|
||||
.strategyName(warnStrategy.getStrategyName())
|
||||
.messageTemplateId(warnStrategy.getMessageTemplateId())
|
||||
.vehicleTypeId(warnStrategy.getVehicleTypeId())
|
||||
.warnRuleList(warnRuleList)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,7 @@ import com.muyu.common.security.utils.SecurityUtils;
|
|||
import com.muyu.common.system.domain.LoginUser;
|
||||
import com.muyu.domain.WarnStrategy;
|
||||
import com.muyu.domain.req.BoundFenceGroupReq;
|
||||
import com.muyu.domain.resp.WarnRuleResp;
|
||||
import com.muyu.domain.resp.WarnStrategyAndVinResp;
|
||||
import com.muyu.enterprise.cache.AllVehicleCacheService;
|
||||
import com.muyu.enterprise.cache.AllWarnStrategyAndVinCacheService;
|
||||
|
@ -81,8 +82,8 @@ public class VehicleController extends BaseController {
|
|||
vehicleList.forEach(vehicle -> {
|
||||
vehicleCacheService.put(vehicle.getVehicleVin(), vehicle);
|
||||
if(vehicle.getWarnStrategyId()!=null){
|
||||
WarnStrategy warnStrategy = warnStrategyService.getById(vehicle.getWarnStrategyId());
|
||||
warnStrategyCacheService.put(vehicle.getVehicleVin(),warnStrategy);
|
||||
WarnRuleResp respList = warnStrategyService.findByWarnStrategyId(vehicle.getWarnStrategyId());
|
||||
warnStrategyCacheService.put(vehicle.getVehicleVin(), respList);
|
||||
}
|
||||
});
|
||||
return getDataTable(list);
|
||||
|
|
|
@ -92,4 +92,13 @@ public class WarnRuleController {
|
|||
return Result.success(warnRuleService.removeById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据外键id查询集合
|
||||
*/
|
||||
@GetMapping("/getWarnStrategyList/{warnStrategyId}")
|
||||
@Operation(summary = "根据外键id查询集合", description = "根据外键id查询集合")
|
||||
public Result<List<WarnRule>> findByWarnStrategyId(@PathVariable("warnStrategyId") Long warnStrategyId) {
|
||||
List<WarnRule> list = warnRuleService.findBywarnStrategyId(warnStrategyId);
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.muyu.common.core.domain.Result;
|
|||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import com.muyu.domain.WarnStrategy;
|
||||
import com.muyu.domain.resp.WarnRuleResp;
|
||||
import com.muyu.domain.resp.WarnStrategyAndVinResp;
|
||||
import com.muyu.enterprise.cache.AllWarnStrategyAndVinCacheService;
|
||||
import com.muyu.enterprise.cache.AllWarnStrategyCacheService;
|
||||
|
@ -64,17 +65,6 @@ public class WarnStrategyController {
|
|||
return Result.success(warnStrategyService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则策略双表联查
|
||||
* @param warnVehicleReq
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(path = "ruleStrategyList",method = RequestMethod.POST)
|
||||
// @Operation(summary = "策略规则双表联查", description = "获取所有策略规则双表联查")
|
||||
// public Result<List<WarnVehicleResp>> ruleStrategyList(@RequestBody WarnVehicleReq warnVehicleReq){
|
||||
// return Result.success(warnStrategyService.ruleStrategyList(warnVehicleReq));
|
||||
// }
|
||||
|
||||
/**
|
||||
* 添加策略
|
||||
* @param warnStrategy
|
||||
|
@ -85,13 +75,13 @@ public class WarnStrategyController {
|
|||
public Result strategyAdd(@Validated @RequestBody WarnStrategy warnStrategy){
|
||||
|
||||
boolean save = warnStrategyService.save(warnStrategy);
|
||||
//存进Redis
|
||||
//获取用户信息
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
//获取租户唯一标识
|
||||
String databaseName = loginUser.getSysUser().getDatabaseName();
|
||||
warnStrategyCacheService.put(databaseName+warnStrategy.getWarnStrategyId(),warnStrategy);
|
||||
return Result.success();
|
||||
// //存进Redis
|
||||
// //获取用户信息
|
||||
// LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
// //获取租户唯一标识
|
||||
// String databaseName = loginUser.getSysUser().getDatabaseName();
|
||||
// warnStrategyCacheService.put(databaseName+warnStrategy.getWarnStrategyId(),warnStrategy);
|
||||
return Result.success(save);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,4 +120,16 @@ public class WarnStrategyController {
|
|||
return Result.success(warnStrategyAndVinResp);
|
||||
}
|
||||
|
||||
// findbyid resp warnrulelist.set
|
||||
/**
|
||||
* 根据resp查询List集合,将rule查询到的集合添加到List集合中
|
||||
* @param warnStrategyId
|
||||
*/
|
||||
@RequestMapping(path = "/warnRuleRespList",method = RequestMethod.POST)
|
||||
@Operation(summary = "根据resp查询List集合,将rule查询到的集合添加到List集合中", description = "根据resp查询List集合,将rule查询到的集合添加到List集合中")
|
||||
public Result<WarnRuleResp> respStrategyList(@PathVariable("warnStrategyId") Long warnStrategyId) {
|
||||
WarnRuleResp warnRuleRespList=warnStrategyService.findByWarnStrategyId(warnStrategyId);
|
||||
return Result.success(warnRuleRespList);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,14 @@ package com.muyu.enterprise.mapper;
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.domain.WarnRule;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface WarnRuleMapper extends BaseMapper<WarnRule> {
|
||||
|
||||
@Select("SELECT * FROM warn_rule WHERE warn_strategy_id=#{warnStrategyId}")
|
||||
List<WarnRule> findBywarnStrategyId(Long warnStrategyId);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.enterprise.mapper;
|
|||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.muyu.domain.WarnStrategy;
|
||||
import com.muyu.domain.resp.WarnRuleResp;
|
||||
import com.muyu.domain.resp.WarnStrategyAndVinResp;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
@ -16,4 +17,13 @@ public interface WarnStrategyMapper extends MPJBaseMapper<WarnStrategy> {
|
|||
@Select("SELECT vehicle.vehicle_vin, warn_strategy.warn_strategy_id, warn_strategy.vehicle_type_id, warn_strategy.message_template_id FROM vehicle LEFT JOIN warn_strategy ON vehicle.warn_strategy_id = warn_strategy.warn_strategy_id WHERE vehicle.warn_strategy_id = #{warn_strategy_id}")
|
||||
List<WarnStrategyAndVinResp> findById(Long vehicleId);
|
||||
|
||||
/**
|
||||
* 查询列表(存Redis)
|
||||
* @param warnStrategyId
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from warn_strategy where warn_strategy_id = #{warn_strategy_id}")
|
||||
WarnRuleResp findByWarnStrategyId(Long warnStrategyId);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,5 +3,15 @@ package com.muyu.enterprise.service;
|
|||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.domain.WarnRule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface WarnRuleService extends IService<WarnRule> {
|
||||
|
||||
/**
|
||||
* 根据预警策略ID查询预警规则集合
|
||||
* @param warnStrategyId
|
||||
* @return
|
||||
*/
|
||||
List<WarnRule> findBywarnStrategyId(Long warnStrategyId);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.enterprise.service;
|
|||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.domain.WarnStrategy;
|
||||
import com.muyu.domain.req.WarnVehicleReq;
|
||||
import com.muyu.domain.resp.WarnRuleResp;
|
||||
import com.muyu.domain.resp.WarnStrategyAndVinResp;
|
||||
import com.muyu.domain.resp.WarnVehicleResp;
|
||||
|
||||
|
@ -20,5 +21,10 @@ public interface WarnStrategyService extends IService<WarnStrategy> {
|
|||
|
||||
List<WarnStrategyAndVinResp> findById(Long warnStrategyId);
|
||||
|
||||
|
||||
/**
|
||||
* 查询列表(存Redis)
|
||||
* @param warnStrategyId
|
||||
* @return
|
||||
*/
|
||||
WarnRuleResp findByWarnStrategyId(Long warnStrategyId);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,25 @@
|
|||
package com.muyu.enterprise.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.domain.WarnRule;
|
||||
import com.muyu.enterprise.mapper.WarnRuleMapper;
|
||||
import com.muyu.enterprise.service.WarnRuleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class WarnRuleServiceImpl extends ServiceImpl<WarnRuleMapper, WarnRule> implements WarnRuleService {
|
||||
|
||||
@Autowired
|
||||
private WarnRuleMapper warnRuleMapper;
|
||||
|
||||
@Override
|
||||
public List<WarnRule> findBywarnStrategyId(Long warnStrategyId) {
|
||||
List<WarnRule> warnRules = warnRuleMapper.findBywarnStrategyId(warnStrategyId);
|
||||
return warnRules;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.muyu.domain.MessageTemplate;
|
||||
import com.muyu.domain.WarnRule;
|
||||
import com.muyu.domain.resp.WarnRuleResp;
|
||||
import com.muyu.domain.resp.WarnStrategyAndVinResp;
|
||||
import com.muyu.enterprise.controller.WarnRuleController;
|
||||
import com.muyu.enterprise.mapper.WarnStrategyMapper;
|
||||
import com.muyu.enterprise.service.WarnRuleService;
|
||||
import com.muyu.enterprise.service.WarnStrategyService;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.domain.VehicleType;
|
||||
|
@ -17,6 +21,8 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service
|
||||
public class WarnStrategyServiceImpl extends ServiceImpl<WarnStrategyMapper, WarnStrategy>
|
||||
|
@ -25,6 +31,9 @@ public class WarnStrategyServiceImpl extends ServiceImpl<WarnStrategyMapper, War
|
|||
@Autowired
|
||||
private WarnStrategyMapper warnStrategyMapper;
|
||||
|
||||
@Autowired
|
||||
private WarnRuleService warnRuleService;
|
||||
|
||||
|
||||
@Override
|
||||
public List<WarnVehicleResp> selectList(WarnVehicleReq req) {
|
||||
|
@ -45,10 +54,17 @@ public class WarnStrategyServiceImpl extends ServiceImpl<WarnStrategyMapper, War
|
|||
@Override
|
||||
public List<WarnStrategyAndVinResp> findById(Long warnStrategyId) {
|
||||
List<WarnStrategyAndVinResp> byId = warnStrategyMapper.findById(warnStrategyId);
|
||||
if (byId == null) {
|
||||
return null;
|
||||
}
|
||||
return byId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WarnRuleResp findByWarnStrategyId(Long warnStrategyId) {
|
||||
|
||||
WarnRuleResp warnRuleResp = warnStrategyMapper.findByWarnStrategyId(warnStrategyId);
|
||||
List<WarnRule> bywarnStrategyId = warnRuleService.findBywarnStrategyId(warnStrategyId);
|
||||
warnRuleResp.setWarnRuleList(bywarnStrategyId);
|
||||
return warnRuleResp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue