Commit 779ebe73 by 穆龙飞

modify:修改字段

parent b824b6d0
......@@ -2,14 +2,14 @@ package com.netease.mail.yanxuan.change.biz.service.impl.change;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
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.ChangeExecConfigService;
import com.netease.mail.yanxuan.change.common.bean.AjaxResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.netease.mail.yanxuan.change.biz.meta.exception.ExceptionFactory;
import com.netease.mail.yanxuan.change.biz.service.change.AdminChangeConfigService;
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.ChangeTypeService;
import com.netease.mail.yanxuan.change.common.bean.AjaxResult;
import com.netease.mail.yanxuan.change.common.bean.RequestLocalBean;
import com.netease.mail.yanxuan.change.common.bean.ResponseCode;
import com.netease.mail.yanxuan.change.common.bean.ResponseCodeEnum;
......@@ -32,6 +32,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
......@@ -43,43 +44,38 @@ import java.util.concurrent.TimeUnit;
@Service
public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
private static final String CHANGE_CONFIG = "changeConfig:";
@Autowired
public ChangeConfigMapper mapper;
Logger logger = LoggerFactory.getLogger(AdminChangeConfigServiceImpl.class);
@Autowired
private ChangeTypeService typeService;
@Autowired
private ChangeConfigService changeConfigService;
@Autowired
private ChangeExecConfigService execConfigService;
@Autowired
private StringRedisTemplate redisTemplate;
private ValueOperations<String, String> value;
private static final String CHANGE_CONFIG = "changeConfig:";
Logger logger = LoggerFactory.getLogger(AdminChangeConfigServiceImpl.class);
@Override
public AjaxResult queryChanges(Integer pageNum, Integer pageSize, ChangeConfigQueryReq req) {
ChangeConfigArrayVO vo = new ChangeConfigArrayVO();
//进行分页
PageHelper.startPage(pageNum,pageSize);
PageHelper.startPage(pageNum, pageSize);
List<ChangeConfigPo> changeConfigPos = mapper.selectChangeConfigPo(req);
PageInfo<ChangeConfigPo> pageInfo = new PageInfo<>(changeConfigPos);
Long total = pageInfo.getTotal();
PageVO pageVO = buildPageVo(total.intValue(), pageSize, pageNum);
vo.setChangeConfigs(pageInfo.getList());
List<ChangeConfigPo> changeConfig = pageInfo.getList();
changeConfig.forEach(i -> i.getParticipateChangeExecDepartment().replace("[", "").replace("]", ""));
vo.setChangeConfigs(changeConfig);
vo.setPageVo(pageVO);
return AjaxResult.success(vo);
}
@Override
public AjaxResult queryDetail(Long id,Long sonChangeClassId) {
public AjaxResult queryDetail(Long id, Long sonChangeClassId) {
String changeConfigVO;
//尝试从reids里面 获取 如果获取到了直接返回
if (id != null) {
......@@ -89,63 +85,63 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
}
}
//从数据库中取出数据
ChangeConfig changeConfig = changeConfigService.queryChangeConfig(id,sonChangeClassId);
if (changeConfig == null){
ChangeConfig changeConfig = changeConfigService.queryChangeConfig(id, sonChangeClassId);
if (changeConfig == null) {
return AjaxResult.of(ResponseCodeEnum.NO_FOUND);
}
List<ChangeType> changeTypes = typeService.queryChangeType(changeConfig.getParentChangeClassId(), changeConfig.getSonChangeClassId(), true);
if (changeTypes == null || changeTypes.size() != 2){
if (changeTypes == null || changeTypes.size() != 2) {
return AjaxResult.of(ResponseCodeEnum.NO_FOUND);
}
List<ChangeExecConfig> changeExecConfigs = execConfigService.queryChangeExecConfig(changeConfig.getId());
if (changeExecConfigs == null || changeExecConfigs.size() == 0){
if (changeExecConfigs == null || changeExecConfigs.size() == 0) {
return AjaxResult.of(ResponseCodeEnum.NO_FOUND);
}
//组装数据
changeConfigVO = getChangeConfigVO(changeConfig, changeTypes, changeExecConfigs);
//如果没有查询后返回redis
getValue().set(CHANGE_CONFIG+id,changeConfigVO,1, TimeUnit.DAYS);
getValue().set(CHANGE_CONFIG + id, changeConfigVO, 1, TimeUnit.DAYS);
return AjaxResult.success(JSON.parseObject(changeConfigVO, ChangeConfigVO.class));
}
@Override
@Transactional
public AjaxResult createChange(ChangeConfigReq changeConfigReq) {
logger.info("查看入参值"+changeConfigReq.toString());
logger.info("查看入参值" + changeConfigReq.toString());
//添加一级二级类目
List<ChangeType> changeTypes = typeService.addChangeType(changeConfigReq.getChangeTypes());
ChangeConfig changeConfig = parameterSplicing(changeTypes,changeConfigReq);
ChangeConfig changeConfig = parameterSplicing(changeTypes, changeConfigReq);
changeConfig = changeConfigService.addChangeConfig(changeConfig);
List<ChangeExecConfig> changeExecConfigs = execConfigService.addChangeExecConfig(changeConfig.getId(), changeConfigReq.getChangeExeConfig());
//参数拼装
String changeConfigVO = getChangeConfigVO(changeConfig, changeTypes, changeExecConfigs);
//新增后添加到redis
getValue().set(CHANGE_CONFIG+changeConfig.getId(),changeConfigVO,1, TimeUnit.DAYS);
getValue().set(CHANGE_CONFIG + changeConfig.getId(), changeConfigVO, 1, TimeUnit.DAYS);
return AjaxResult.success();
}
@Override
@Transactional
public AjaxResult modifyChange(ChangeConfigReq changeConfigReq) {
if (changeConfigReq.getId() == null){
return AjaxResult.of(9001,"修改变更模板主键id不能为空");
if (changeConfigReq.getId() == null) {
return AjaxResult.of(9001, "修改变更模板主键id不能为空");
}
//先查询注入ID后在修改
ChangeConfig config = changeConfigService.queryChangeConfig(changeConfigReq.getId());
if (config == null){
return AjaxResult.of(9001,"未找到变更类型配置");
if (config == null) {
return AjaxResult.of(9001, "未找到变更类型配置");
}
changeConfigReq.getChangeTypes().get(0).setId(config.getParentChangeClassId());
changeConfigReq.getChangeTypes().get(1).setId(config.getSonChangeClassId());
//新增类似
List<ChangeType> changeTypes = typeService.updateChangeType(changeConfigReq.getChangeTypes());
ChangeConfig changeConfig = parameterSplicing(changeTypes,changeConfigReq);
ChangeConfig changeConfig = parameterSplicing(changeTypes, changeConfigReq);
changeConfigService.updateChangeConfig(changeConfig);
//修改
List<ChangeExecConfig> changeExecConfigs = execConfigService.updateChangeExecConfig(changeConfigReq.getId(), changeConfigReq.getChangeExeConfig());
//装在reids
String changeConfigVO = getChangeConfigVO(changeConfig, changeTypes, changeExecConfigs);
getValue().set(CHANGE_CONFIG+changeConfig.getId(),changeConfigVO,1, TimeUnit.DAYS);
String changeConfigVO = getChangeConfigVO(changeConfig, changeTypes, changeExecConfigs);
getValue().set(CHANGE_CONFIG + changeConfig.getId(), changeConfigVO, 1, TimeUnit.DAYS);
//修改后更新redis
return AjaxResult.success();
}
......@@ -153,11 +149,11 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
@Override
@Transactional
public AjaxResult deleteChange(ChangeConfigDeleteReq id) {
if (id == null && id.getId() == null){
if (id == null && id.getId() == null) {
return AjaxResult.of(ResponseCodeEnum.PARAM_ERROR);
}
ChangeConfig changeConfig = changeConfigService.queryChangeConfig(id.getId());
if (changeConfig == null){
if (changeConfig == null) {
return AjaxResult.of(ResponseCodeEnum.NO_FOUND);
}
changeConfigService.deleteChangeConfig(id.getId());
......@@ -165,7 +161,7 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
typeService.deleteChangeTypes(changeTypes);
execConfigService.deleteChangeConfig(id.getId());
// 缓存内删除
redisTemplate.delete(CHANGE_CONFIG+id.getId());
redisTemplate.delete(CHANGE_CONFIG + id.getId());
return AjaxResult.success();
}
......@@ -181,56 +177,57 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
/**
* 添加变更模板并参数拼接
*
* @param changeTypes
* @param changeConfigReq
* @return
*/
private ChangeConfig parameterSplicing(List<ChangeType> changeTypes,ChangeConfigReq changeConfigReq){
private ChangeConfig parameterSplicing(List<ChangeType> changeTypes, ChangeConfigReq changeConfigReq) {
ChangeConfig changeConfig = new ChangeConfig();
changeConfig.setParentChangeClassId(changeTypes.get(0).getId());
changeConfig.setSonChangeClassId(changeTypes.get(1).getId());
if (changeConfigReq.getId() != null){
if (changeConfigReq.getId() != null) {
changeConfig.setId(changeConfigReq.getId());
}
if (changeConfigReq.getChangeSubject() == null){
if (changeConfigReq.getChangeSubject() == null) {
throw ExceptionFactory.createBiz(ResponseCode.PARAMETER_DEFICIENCY);
}
//验证变更主体
ChangeSubjectEnum containsChangeSubject = ChangeSubjectEnum.getByType(changeConfigReq.getChangeSubject());
if (containsChangeSubject == null){
throw ExceptionFactory.createBiz(ResponseCode.CANT_FOUND,"变更主体不存在");
if (containsChangeSubject == null) {
throw ExceptionFactory.createBiz(ResponseCode.CANT_FOUND, "变更主体不存在");
}
changeConfig.setChangeSubject(changeConfigReq.getChangeSubject());
if (changeConfigReq.getChangeLevel() == null){
if (changeConfigReq.getChangeLevel() == null) {
throw ExceptionFactory.createBiz(ResponseCode.PARAMETER_DEFICIENCY);
}
changeConfig.setChangeLevel(changeConfigReq.getChangeLevel());
if (changeConfigReq.getChangeDepartment() == null){
if (changeConfigReq.getChangeDepartment() == null) {
throw ExceptionFactory.createBiz(ResponseCode.PARAMETER_DEFICIENCY);
}
changeConfig.setChangeDepartment(changeConfigReq.getChangeDepartment());
if (changeConfigReq.getChangeCommanderType() == null){
if (changeConfigReq.getChangeCommanderType() == null) {
throw ExceptionFactory.createBiz(ResponseCode.PARAMETER_DEFICIENCY);
//如果是执行人就从head里面把邮箱装载
}else if (changeConfigReq.getChangeCommanderType() == 1){
} else if (changeConfigReq.getChangeCommanderType() == 1) {
changeConfigReq.setChangeCommander(RequestLocalBean.getUid());
}
changeConfig.setChangeCommanderType(changeConfigReq.getChangeCommanderType());
if (changeConfigReq.getChangeCommander() == null){
if (changeConfigReq.getChangeCommander() == null) {
throw ExceptionFactory.createBiz(ResponseCode.PARAMETER_DEFICIENCY);
}
changeConfig.setChangeCommander(changeConfigReq.getChangeCommander());
if (changeConfigReq.getNeedFile() == null){
if (changeConfigReq.getNeedFile() == null) {
throw ExceptionFactory.createBiz(ResponseCode.PARAMETER_DEFICIENCY);
}
changeConfig.setNeedFile(changeConfigReq.getNeedFile());
changeConfig.setCreateTime(System.currentTimeMillis());
changeConfig.setUpdateTime(System.currentTimeMillis());
if (changeConfigReq.getChangeExeConfig() == null || changeConfigReq.getChangeExeConfig().size() >=21){
if (changeConfigReq.getChangeExeConfig() == null || changeConfigReq.getChangeExeConfig().size() >= 21) {
throw ExceptionFactory.createBiz(ResponseCode.EXEC_CONFIG_LENGTH);
}
List<String> list = new ArrayList<>();
for (ChangeExecConfig execConfig : changeConfigReq.getChangeExeConfig()){
for (ChangeExecConfig execConfig : changeConfigReq.getChangeExeConfig()) {
list.add(execConfig.getChangeExecDepartment());
}
changeConfig.setParticipateChangeExecDepartment(list.toString());
......@@ -238,14 +235,14 @@ public class AdminChangeConfigServiceImpl implements AdminChangeConfigService {
}
private ValueOperations<String, String> getValue(){
if (value == null){
private ValueOperations<String, String> getValue() {
if (value == null) {
value = redisTemplate.opsForValue();
}
return value;
}
private String getChangeConfigVO(ChangeConfig changeConfig,List<ChangeType> changeTypes,List<ChangeExecConfig> changeExecConfigs){
private String getChangeConfigVO(ChangeConfig changeConfig, List<ChangeType> changeTypes, List<ChangeExecConfig> changeExecConfigs) {
ChangeConfigVO vo = new ChangeConfigVO();
vo.setChangeConfig(changeConfig);
vo.setChangeTypes(changeTypes);
......
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