Commit aca80b0a by jx-art

查询配置模板添加缓存 修改查询Bug (字段修改)

parent 933e7902
...@@ -13,9 +13,9 @@ public interface ChangeExecConfigService { ...@@ -13,9 +13,9 @@ public interface ChangeExecConfigService {
List<ChangeExecConfig> queryChangeExecConfig(Long changeTemplateId); List<ChangeExecConfig> queryChangeExecConfig(Long changeTemplateId);
Boolean addChangeExecConfig(Long id,List<ChangeExecConfig> changeExecConfigs); List<ChangeExecConfig> addChangeExecConfig(Long id,List<ChangeExecConfig> changeExecConfigs);
Boolean updateChangeExecConfig(Long id,List<ChangeExecConfig> changeExecConfigs); List<ChangeExecConfig> updateChangeExecConfig(Long id,List<ChangeExecConfig> changeExecConfigs);
Boolean deleteChangeConfig(Long changeTemplateId); Boolean deleteChangeConfig(Long changeTemplateId);
......
package com.netease.mail.yanxuan.change.biz.service.impl; package com.netease.mail.yanxuan.change.biz.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.netease.mail.yanxuan.change.biz.meta.exception.ExceptionFactory; import com.netease.mail.yanxuan.change.biz.meta.exception.ExceptionFactory;
import com.netease.mail.yanxuan.change.biz.service.change.ChangeConfigService; import com.netease.mail.yanxuan.change.biz.service.change.ChangeConfigService;
import com.netease.mail.yanxuan.change.biz.service.change.ChangeExecConfigService; import com.netease.mail.yanxuan.change.biz.service.change.ChangeExecConfigService;
...@@ -20,11 +21,13 @@ import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeConfigQueryReq; ...@@ -20,11 +21,13 @@ import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeConfigQueryReq;
import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeConfigReq; import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeConfigReq;
import com.netease.mail.yanxuan.change.dal.meta.model.vo.ChangeConfigVO; import com.netease.mail.yanxuan.change.dal.meta.model.vo.ChangeConfigVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
/** /**
* @author WangJiaXiang * @author WangJiaXiang
...@@ -45,6 +48,13 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService { ...@@ -45,6 +48,13 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
@Autowired @Autowired
private ChangeExecConfigService execConfigService; private ChangeExecConfigService execConfigService;
@Autowired
private StringRedisTemplate redisTemplate;
private ValueOperations<String, String> value;
private static final String CHANGE_CONFIG = "changeConfig:";
@Override @Override
public AjaxResult queryChanges(Integer pageNum, Integer pageSize, ChangeConfigQueryReq req) { public AjaxResult queryChanges(Integer pageNum, Integer pageSize, ChangeConfigQueryReq req) {
//进行分页 //进行分页
...@@ -60,8 +70,10 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService { ...@@ -60,8 +70,10 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
return AjaxResult.of(ResponseCodeEnum.PARAM_ERROR); return AjaxResult.of(ResponseCodeEnum.PARAM_ERROR);
} }
//尝试从reids里面 获取 如果获取到了直接返回 //尝试从reids里面 获取 如果获取到了直接返回
String changeConfigVO = getValue().get(id.toString());
if (changeConfigVO != null){
return AjaxResult.success(JSONObject.parseObject(changeConfigVO, ChangeConfigVO.class));
}
//从数据库中取出数据 //从数据库中取出数据
ChangeConfig changeConfig = changeConfigService.queryChangeConfig(id); ChangeConfig changeConfig = changeConfigService.queryChangeConfig(id);
if (changeConfig == null){ if (changeConfig == null){
...@@ -76,12 +88,10 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService { ...@@ -76,12 +88,10 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
return AjaxResult.of(ResponseCodeEnum.NO_FOUND); return AjaxResult.of(ResponseCodeEnum.NO_FOUND);
} }
//组装数据 //组装数据
ChangeConfigVO vo = new ChangeConfigVO(); changeConfigVO = getChangeConfigVO(changeConfig, changeTypes, changeExecConfigs);
vo.setChangeConfig(changeConfig);
vo.setChangeTypes(changeTypes);
vo.setChangeExecConfigs(changeExecConfigs);
//如果没有查询后返回redis //如果没有查询后返回redis
return AjaxResult.success(vo); getValue().set(CHANGE_CONFIG+id,changeConfigVO,1, TimeUnit.DAYS);
return AjaxResult.success(JSONObject.parseObject(changeConfigVO, ChangeConfigVO.class));
} }
@Override @Override
...@@ -91,8 +101,11 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService { ...@@ -91,8 +101,11 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
List<ChangeType> changeTypes = typeService.addChangeType(changeConfigReq.getChangeTypes()); List<ChangeType> changeTypes = typeService.addChangeType(changeConfigReq.getChangeTypes());
ChangeConfig changeConfig = parameterSplicing(changeTypes,changeConfigReq); ChangeConfig changeConfig = parameterSplicing(changeTypes,changeConfigReq);
changeConfig = changeConfigService.addChangeConfig(changeConfig); changeConfig = changeConfigService.addChangeConfig(changeConfig);
execConfigService.addChangeExecConfig(changeConfig.getId(),changeConfigReq.getChangeExecConfigs()); List<ChangeExecConfig> changeExecConfigs = execConfigService.addChangeExecConfig(changeConfig.getId(), changeConfigReq.getChangeExecConfigs());
//参数拼装
String changeConfigVO = getChangeConfigVO(changeConfig, changeTypes, changeExecConfigs);
//新增后添加到redis //新增后添加到redis
getValue().set(CHANGE_CONFIG+changeConfig.getId(),changeConfigVO,1, TimeUnit.DAYS);
return AjaxResult.success(); return AjaxResult.success();
} }
...@@ -107,7 +120,10 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService { ...@@ -107,7 +120,10 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
ChangeConfig changeConfig = parameterSplicing(changeTypes,changeConfigReq); ChangeConfig changeConfig = parameterSplicing(changeTypes,changeConfigReq);
changeConfigService.updateChangeConfig(changeConfig); changeConfigService.updateChangeConfig(changeConfig);
//修改 //修改
execConfigService.updateChangeExecConfig(changeConfigReq.getId(),changeConfigReq.getChangeExecConfigs()); List<ChangeExecConfig> changeExecConfigs = execConfigService.updateChangeExecConfig(changeConfigReq.getId(), changeConfigReq.getChangeExecConfigs());
//装在reids
String changeConfigVO = getChangeConfigVO(changeConfig, changeTypes, changeExecConfigs);
getValue().set(CHANGE_CONFIG+changeConfig.getId(),changeConfigVO,1, TimeUnit.DAYS);
//修改后更新redis //修改后更新redis
return AjaxResult.success(); return AjaxResult.success();
} }
...@@ -124,6 +140,7 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService { ...@@ -124,6 +140,7 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
typeService.deleteChangeTypes(changeTypes); typeService.deleteChangeTypes(changeTypes);
execConfigService.deleteChangeConfig(id); execConfigService.deleteChangeConfig(id);
// 缓存内删除 // 缓存内删除
redisTemplate.delete(CHANGE_CONFIG+id);
return AjaxResult.success(); return AjaxResult.success();
} }
...@@ -154,9 +171,9 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService { ...@@ -154,9 +171,9 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
throw ExceptionFactory.createBiz(ResponseCode.PARAMETER_DEFICIENCY); throw ExceptionFactory.createBiz(ResponseCode.PARAMETER_DEFICIENCY);
} }
//验证变更主体 //验证变更主体
Boolean containsChangeSubject = ChangeSubjectEnum.getByType(changeConfigReq.getChangeSubject()); ChangeSubjectEnum containsChangeSubject = ChangeSubjectEnum.getByType(changeConfigReq.getChangeSubject());
if (!containsChangeSubject){ if (containsChangeSubject == null){
throw ExceptionFactory.createBiz(ResponseCode.NO_DATA,"变更主体不存在"); throw ExceptionFactory.createBiz(ResponseCode.CANT_FOUND,"变更主体不存在");
} }
changeConfig.setChangeSubject(changeConfigReq.getChangeSubject()); changeConfig.setChangeSubject(changeConfigReq.getChangeSubject());
if (changeConfigReq.getChangeLevel() == null){ if (changeConfigReq.getChangeLevel() == null){
...@@ -192,4 +209,20 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService { ...@@ -192,4 +209,20 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
return changeConfig; return changeConfig;
} }
private ValueOperations<String, String> getValue(){
if (value == null){
value = redisTemplate.opsForValue();
}
return value;
}
private String getChangeConfigVO(ChangeConfig changeConfig,List<ChangeType> changeTypes,List<ChangeExecConfig> changeExecConfigs){
ChangeConfigVO vo = new ChangeConfigVO();
vo.setChangeConfig(changeConfig);
vo.setChangeTypes(changeTypes);
vo.setChangeExecConfigs(changeExecConfigs);
return JSONObject.toJSONString(vo);
}
} }
...@@ -23,7 +23,7 @@ public class ChangeExecConfigServiceImpl implements ChangeExecConfigService { ...@@ -23,7 +23,7 @@ public class ChangeExecConfigServiceImpl implements ChangeExecConfigService {
} }
@Override @Override
public Boolean addChangeExecConfig(Long id,List<ChangeExecConfig> changeExecConfigs) { public List<ChangeExecConfig> addChangeExecConfig(Long id,List<ChangeExecConfig> changeExecConfigs) {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
//循环添加 //循环添加
for (ChangeExecConfig changeExecConfig : changeExecConfigs){ for (ChangeExecConfig changeExecConfig : changeExecConfigs){
...@@ -33,16 +33,16 @@ public class ChangeExecConfigServiceImpl implements ChangeExecConfigService { ...@@ -33,16 +33,16 @@ public class ChangeExecConfigServiceImpl implements ChangeExecConfigService {
//行动项,变更风险描述, 变更验证措施, 需要判断字段长度 参数验证 暂不验证 //行动项,变更风险描述, 变更验证措施, 需要判断字段长度 参数验证 暂不验证
mapper.insertSelective(changeExecConfig); mapper.insertSelective(changeExecConfig);
} }
return true; return changeExecConfigs;
} }
@Override @Override
public Boolean updateChangeExecConfig(Long id,List<ChangeExecConfig> changeExecConfigs) { public List<ChangeExecConfig> updateChangeExecConfig(Long id,List<ChangeExecConfig> changeExecConfigs) {
//删除原来的行动 //删除原来的行动
deleteChangeConfig(id); deleteChangeConfig(id);
//重新载入新的行动项 //重新载入新的行动项
addChangeExecConfig(id,changeExecConfigs); addChangeExecConfig(id,changeExecConfigs);
return true; return addChangeExecConfig(id,changeExecConfigs);
} }
@Override @Override
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
</select> </select>
<select id="queryByparentChangeClassId" resultType="com.netease.mail.yanxuan.change.dal.entity.ChangeType"> <select id="queryByparentChangeClassId" resultType="com.netease.mail.yanxuan.change.dal.entity.ChangeType">
select * from TB_YX_QC_CHANGE_TYPE where id = #{parentId} or id = #{sonId} and `delete` = 0 select * from TB_YX_QC_CHANGE_TYPE where id = #{parentId} or id = #{sonId} and delete_type = 0
</select> </select>
<!--此查询暂时不需要。。。--> <!--此查询暂时不需要。。。-->
<!-- <select id="queryChangeDepartment" resultType="com.netease.mail.yanxuan.change.dal.meta.model.po.ChangeExecConfigPo" parameterType="java.lang.Long">--> <!-- <select id="queryChangeDepartment" resultType="com.netease.mail.yanxuan.change.dal.meta.model.po.ChangeExecConfigPo" parameterType="java.lang.Long">-->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment