Commit 4ffa67f5 authored by YangZhaoJun1's avatar YangZhaoJun1

Merge branch 'master' of http://103.249.252.109:90/lcy/education

# Conflicts:
#	src/main/resources/application-dev.yml
parents 7398ef7d d4c9f080
package org.rcisoft.business.bcode.controller; package org.rcisoft.business.bcode.controller;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.*;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.rcisoft.business.bcode.model.BCodeFile; import org.rcisoft.business.bcode.model.BCodeFile;
import org.rcisoft.business.bcode.service.BCodeService; import org.rcisoft.business.bcode.service.BCodeService;
...@@ -11,6 +9,7 @@ import org.rcisoft.common.controller.PaginationController; ...@@ -11,6 +9,7 @@ import org.rcisoft.common.controller.PaginationController;
import org.rcisoft.core.constant.MessageConstant; import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.exception.ServiceException; import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.CommandResult;
import org.rcisoft.core.result.Result; import org.rcisoft.core.result.Result;
import org.rcisoft.core.result.ResultServiceEnums; import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.util.CompileUtil; import org.rcisoft.core.util.CompileUtil;
...@@ -74,6 +73,34 @@ public class BCodeController extends PaginationController { ...@@ -74,6 +73,34 @@ public class BCodeController extends PaginationController {
@ApiOperation(value="实验是否启动", notes="实验是否启动")
@ApiImplicitParams({@ApiImplicitParam(name = "slId", value = "开课ID", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "chapId", value = "章节ID", required = true, dataType = "varchar")})
@GetMapping(value = "/isStartedExam")
public Result isStartedExam(@RequestParam("slId") String slId,
@RequestParam("chapId") String chapId){
Integer result = bCodeServiceImpl.isOpenLxcFromUser(UserUtil.getUserInfoProp(getToken(), UserUtil.USER_ID), slId, chapId);
return Result.builder(new PersistModel(result),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
result);
}
@ApiOperation(value="关闭实验", notes="关闭实验")
@GetMapping(value = "/stopExam")
public Result stopExam(){
CommandResult result = bCodeServiceImpl.stopExam(UserUtil.getUserInfoProp(getToken(), UserUtil.USER_ID));
return Result.builder(new PersistModel(result.isSuccess()? 1 : 0),
result.getMessage(),
result.getMessage(),
result);
}
@ApiOperation(value="保存实验代码", notes="学生保存自己的实验") @ApiOperation(value="保存实验代码", notes="学生保存自己的实验")
@ApiImplicitParams({@ApiImplicitParam(name = "slId", value = "开课ID", required = true, dataType = "varchar"), @ApiImplicitParams({@ApiImplicitParam(name = "slId", value = "开课ID", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "chapId", value = "章节ID", required = true, dataType = "varchar"), @ApiImplicitParam(name = "chapId", value = "章节ID", required = true, dataType = "varchar"),
......
...@@ -20,7 +20,7 @@ public interface BCodeLxcService { ...@@ -20,7 +20,7 @@ public interface BCodeLxcService {
* 关闭code 容器 * 关闭code 容器
* @param lxc * @param lxc
*/ */
public void stopBCodeLxc(BCodeLxc lxc); public CommandResult stopBCodeLxc(BCodeLxc lxc);
/** /**
* 清理 code 容器 * 清理 code 容器
......
...@@ -2,6 +2,7 @@ package org.rcisoft.business.bcode.service; ...@@ -2,6 +2,7 @@ package org.rcisoft.business.bcode.service;
import org.rcisoft.business.bcode.model.BCodeFile; import org.rcisoft.business.bcode.model.BCodeFile;
import org.rcisoft.business.bcode.model.StudentFile; import org.rcisoft.business.bcode.model.StudentFile;
import org.rcisoft.core.result.CommandResult;
import java.util.List; import java.util.List;
...@@ -34,4 +35,20 @@ public interface BCodeService { ...@@ -34,4 +35,20 @@ public interface BCodeService {
String exportFiles(String slId, String studentId, String type, String slCode); String exportFiles(String slId, String studentId, String type, String slCode);
List<StudentFile> queryAllStudentCode(String slId, String chapterId); List<StudentFile> queryAllStudentCode(String slId, String chapterId);
/**
* 判断是否开启
*
* @param userId
* @return 1 未开
* 0 已开
*/
Integer isOpenLxcFromUser(String userId,String slId,String chapterId);
/**
* 关闭 实验环境
* @param userId
* @return
*/
CommandResult stopExam(String userId);
} }
...@@ -12,6 +12,7 @@ import org.rcisoft.core.result.ResultCode; ...@@ -12,6 +12,7 @@ import org.rcisoft.core.result.ResultCode;
import org.rcisoft.core.service.RcRedisService; import org.rcisoft.core.service.RcRedisService;
import org.rcisoft.core.service.SerializationUtils; import org.rcisoft.core.service.SerializationUtils;
import org.rcisoft.core.util.FreemarkerUtil; import org.rcisoft.core.util.FreemarkerUtil;
import org.rcisoft.core.util.TaskUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean; import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -82,8 +83,12 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -82,8 +83,12 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
result = new CommandResult(ResultCode.FAIL,"容器配置文件有误!",lxc); result = new CommandResult(ResultCode.FAIL,"容器配置文件有误!",lxc);
return result; return result;
} }
/*启动路径*/
String dockerPath = global.getPHYSICAL_UPLOAD_SERVER_LOCATION() + File.separator +
global.getLxcDockerfilePath() + File.separator + lxc.getUserId() + File.separator;
/*2.docker-compose 起容器*/ /*2.docker-compose 起容器*/
result = lxcCommand.startOrDownLxc(destPath); log.info("执行路径:{}",dockerPath);
result = lxcCommand.startOrDownLxc(dockerPath);
if(!result.isSuccess()) { if(!result.isSuccess()) {
result = new CommandResult(ResultCode.FAIL,"容器启动失败!",lxc); result = new CommandResult(ResultCode.FAIL,"容器启动失败!",lxc);
return result; return result;
...@@ -103,7 +108,7 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -103,7 +108,7 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
Map jobParam = new HashMap(); Map jobParam = new HashMap();
jobParam.put("redisKeyId",key); jobParam.put("redisKeyId",key);
jobParam.put("containerName",this.getModelProject(lxc.getCode()) + "_" + lxc.getUserId()); jobParam.put("containerName",this.getModelProject(lxc.getCode()) + "_" + lxc.getUserId());
jobParam.put("containerPath",destPath); jobParam.put("containerPath",dockerPath);
jobParam.put("containerPort",port); jobParam.put("containerPort",port);
JobDetail job = JobBuilder.newJob(StopLxcJob.class). JobDetail job = JobBuilder.newJob(StopLxcJob.class).
withIdentity(global.getLxcPrefix() + lxc.getUserId(), JOB_LXC_GROUP). withIdentity(global.getLxcPrefix() + lxc.getUserId(), JOB_LXC_GROUP).
...@@ -113,17 +118,8 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -113,17 +118,8 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
.withIdentity(global.getLxcPrefix() + lxc.getUserId()) .withIdentity(global.getLxcPrefix() + lxc.getUserId())
.startAt(endTime).build(); .startAt(endTime).build();
// 触发器时间设定 // 触发器时间设定
Scheduler sched = schedulerFactoryBean.getScheduler();
/*触发器*/ /*触发器*/
try { TaskUtil.startSchedule(schedulerFactoryBean.getScheduler(),trigger,job);
sched.scheduleJob(job, trigger);
// 启动
if (!sched.isShutdown()) {
sched.start();
}
}catch (Exception e){
log.error(e.getMessage());
}
/*5.端口放进去 */ /*5.端口放进去 */
rcRedisServiceImpl.setList("lxcKeys", rcRedisServiceImpl.setList("lxcKeys",
key); key);
...@@ -178,8 +174,24 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -178,8 +174,24 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
@Override @Override
public void stopBCodeLxc(BCodeLxc lxc) { public CommandResult stopBCodeLxc(BCodeLxc lxc) {
/*1.拼key*/
String key = global.getLxcPrefix() + "_" + lxc.getUserId();
/*2.拼docker-compose.yml */
String destPath = global.getPHYSICAL_UPLOAD_SERVER_LOCATION() + File.separator +
global.getLxcDockerfilePath() + File.separator + lxc.getUserId() + File.separator;;
CommandResult commandResult = null;
commandResult = lxcCommand.startOrDownLxc(destPath,false);
if(!commandResult.isSuccess())
return commandResult;
/*3.移除容器*/
rcRedisServiceImpl.remove(key);
/*4.移除端口*/
rcRedisServiceImpl.removeList("lxcKeys",
key);
rcRedisServiceImpl.removeList("lxcPorts",lxc.getContainerPort() + "");
return commandResult;
} }
......
...@@ -18,6 +18,7 @@ import org.rcisoft.business.bstudent.entity.BStudentDto; ...@@ -18,6 +18,7 @@ import org.rcisoft.business.bstudent.entity.BStudentDto;
import org.rcisoft.common.component.Global; import org.rcisoft.common.component.Global;
import org.rcisoft.core.exception.ServiceException; import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.CommandResult; import org.rcisoft.core.result.CommandResult;
import org.rcisoft.core.result.ResultCode;
import org.rcisoft.core.result.ResultExceptionEnum; import org.rcisoft.core.result.ResultExceptionEnum;
import org.rcisoft.core.result.ResultServiceEnums; import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.service.RcRedisService; import org.rcisoft.core.service.RcRedisService;
...@@ -509,4 +510,44 @@ public class BCodeServiceImpl implements BCodeService { ...@@ -509,4 +510,44 @@ public class BCodeServiceImpl implements BCodeService {
} }
return studentFiles; return studentFiles;
} }
@Override
public Integer isOpenLxcFromUser(String userId,String slId,String chapterId) {
BCodeLxc lxc = null;
/*容器是否已启动*/
byte[] results = rcRedisServiceImpl.getBytes(global.getLxcPrefix() + "_" + userId);
if(null != results) {
lxc = SerializationUtils.deserializer(results, BCodeLxc.class);
/*别的课或别的节已开启容器,返回错误*/
if(null != lxc && (!slId.equals(lxc.getSl()) || !chapterId.equals(lxc.getChapterId()))){
/*已开*/
return 0;
}
/*再次打开已开启的容器*/
return 1;
}
/*未开*/
return 1;
}
@Override
public CommandResult stopExam(String userId) {
BCodeLxc lxc = null;
/*容器是否已启动*/
byte[] results = rcRedisServiceImpl.getBytes(global.getLxcPrefix() + "_" + userId);
if(null != results) {
lxc = SerializationUtils.deserializer(results, BCodeLxc.class);
/*别的课或别的节已开启容器,返回错误*/
if(null == lxc)
return new CommandResult(ResultCode.FAIL,"未开启实验",null);
else {
/*关闭容器*/
return bCodeLxcServiceImpl.stopBCodeLxc(lxc);
}
}
/*未开*/
return new CommandResult(ResultCode.FAIL,"未开启实验",null);
}
} }
...@@ -70,14 +70,16 @@ public class ClearLxcJob implements Job { ...@@ -70,14 +70,16 @@ public class ClearLxcJob implements Job {
if(null != shutdown && shutdown.after(new Date())) if(null != shutdown && shutdown.after(new Date()))
return; return;
/*到点了*/ /*到点了*/
containerPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + containerPath = global.getPHYSICAL_UPLOAD_SERVER_LOCATION() + File.separator +
global.getLxcDockerfilePath() + File.separator + lxc.getUserId() + File.separator; global.getLxcDockerfilePath() + File.separator + lxc.getUserId() + File.separator;
/*关闭容器*/ /*关闭容器*/
/*2.docker-compose 起容器*/ /*2.docker-compose 起容器*/
CommandResult commandResult = null; CommandResult commandResult = null;
commandResult = lxcCommand.startOrDownLxc(containerPath,false); commandResult = lxcCommand.startOrDownLxc(containerPath,false);
/*关闭失败 返回 不删除key*/
if(!commandResult.isSuccess()) if(!commandResult.isSuccess())
return; return;
}
/*3.移除容器*/ /*3.移除容器*/
rcRedisServiceImpl.remove(key); rcRedisServiceImpl.remove(key);
/*4.移除端口*/ /*4.移除端口*/
...@@ -85,5 +87,4 @@ public class ClearLxcJob implements Job { ...@@ -85,5 +87,4 @@ public class ClearLxcJob implements Job {
key); key);
rcRedisServiceImpl.removeList("lxcPorts",lxc.getContainerPort() + ""); rcRedisServiceImpl.removeList("lxcPorts",lxc.getContainerPort() + "");
} }
}
} }
...@@ -5,6 +5,7 @@ import org.apache.commons.lang3.StringUtils; ...@@ -5,6 +5,7 @@ import org.apache.commons.lang3.StringUtils;
import org.quartz.Job; import org.quartz.Job;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; import org.quartz.JobExecutionException;
import org.rcisoft.common.component.Global;
import org.rcisoft.core.command.LxcCommand; import org.rcisoft.core.command.LxcCommand;
import org.rcisoft.core.result.CommandResult; import org.rcisoft.core.result.CommandResult;
import org.rcisoft.core.service.RcRedisService; import org.rcisoft.core.service.RcRedisService;
...@@ -25,6 +26,10 @@ public class StopLxcJob implements Job { ...@@ -25,6 +26,10 @@ public class StopLxcJob implements Job {
@Autowired @Autowired
private LxcCommand lxcCommand; private LxcCommand lxcCommand;
@Autowired
private Global global;
@Override @Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
/*1.容器名称*/ /*1.容器名称*/
...@@ -37,11 +42,14 @@ public class StopLxcJob implements Job { ...@@ -37,11 +42,14 @@ public class StopLxcJob implements Job {
log.info("----任务异常----"); log.info("----任务异常----");
return; return;
} }
/*非远程*/
if(!"1".equals(global.getLxcIsRemote())){
File filePath = new File(containerPath); File filePath = new File(containerPath);
if(!filePath.exists() || !filePath.isDirectory()){ if (!filePath.exists() || !filePath.isDirectory()) {
log.info("----任务路径异常----"); log.info("----任务路径异常----");
return; return;
} }
}
/*关闭容器*/ /*关闭容器*/
/*2.docker-compose 起容器*/ /*2.docker-compose 起容器*/
CommandResult commandResult = null; CommandResult commandResult = null;
......
package org.rcisoft.business.listener; package org.rcisoft.business.component;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.rcisoft.business.bcode.task.ClearLxcJob;
import org.rcisoft.core.util.TaskUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.scheduling.quartz.SchedulerFactoryBean; import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;
import javax.servlet.ServletContextEvent; import java.util.HashMap;
import javax.servlet.ServletContextListener;
/** /**
* Created by lcy on 18/1/19. * Created by lcy on 18/1/20.
* *
* * 容器所有bean都被defined 之后触发
*
* JobDetail job = JobBuilder.newJob(ClearLxcJob.class).
withIdentity(IDENTITY_LXC_GROUP, JOB_LXC_GROUP).
usingJobData(new JobDataMap(new HashMap())).build();
Trigger trigger = TriggerBuilder.newTrigger().forJob(job)
.usingJobData(new JobDataMap(new HashMap()))
.withIdentity(IDENTITY_LXC_GROUP)
.startNow().build();
// 触发器时间设定
Scheduler sched = schedulerFactoryBean.getScheduler();
try {
sched.scheduleJob(job, trigger);
// 启动
if (!sched.isShutdown()) {
sched.start();
}
}catch (Exception e){
log.error(e.getMessage());
}
*/ */
@Slf4j @Slf4j
public class RcListener implements ServletContextListener { @Component
public class RcApplicationRunner implements ApplicationRunner {
/*任务组名*/ /*任务组名*/
...@@ -48,16 +34,17 @@ public class RcListener implements ServletContextListener { ...@@ -48,16 +34,17 @@ public class RcListener implements ServletContextListener {
@Override @Override
public void contextDestroyed(ServletContextEvent arg0) { public void run(ApplicationArguments args) throws Exception {
JobDetail job = JobBuilder.newJob(ClearLxcJob.class).
} withIdentity(IDENTITY_LXC_GROUP, JOB_LXC_GROUP).
usingJobData(new JobDataMap(new HashMap())).build();
/** Trigger trigger = TriggerBuilder.newTrigger().forJob(job)
* 执行任务 .usingJobData(new JobDataMap(new HashMap()))
* @param arg0 .withIdentity(IDENTITY_LXC_GROUP)
*/ .startNow().build();
@Override // 触发器时间设定
public void contextInitialized(ServletContextEvent arg0) { /*触发器*/
TaskUtil.startSchedule(schedulerFactoryBean.getScheduler(),trigger,job);
} }
} }
...@@ -27,7 +27,7 @@ public class ApplicationContextHolder implements ApplicationContextAware { ...@@ -27,7 +27,7 @@ public class ApplicationContextHolder implements ApplicationContextAware {
} }
/** /**
* Get bean by class * Get component by class
* *
* @param clazz * @param clazz
* @param <T> * @param <T>
...@@ -38,7 +38,7 @@ public class ApplicationContextHolder implements ApplicationContextAware { ...@@ -38,7 +38,7 @@ public class ApplicationContextHolder implements ApplicationContextAware {
} }
/** /**
* Get bean by class name * Get component by class name
* *
* @param name * @param name
* @param <T> * @param <T>
......
...@@ -34,6 +34,11 @@ public class Global { ...@@ -34,6 +34,11 @@ public class Global {
@Value("${global.path.base_upload_server_location}") @Value("${global.path.base_upload_server_location}")
private String BASE_UPLOAD_SERVER_LOCATION; private String BASE_UPLOAD_SERVER_LOCATION;
/*容器外路径*/
@Value("${global.path.physical_upload_server_location}")
private String PHYSICAL_UPLOAD_SERVER_LOCATION;
/*课程相关文件路径*/ /*课程相关文件路径*/
@Value("${global.path.course_location}") @Value("${global.path.course_location}")
private String COURSE_LOCATION; private String COURSE_LOCATION;
......
...@@ -19,6 +19,10 @@ public class PaginationController<T> extends ResponseController { ...@@ -19,6 +19,10 @@ public class PaginationController<T> extends ResponseController {
protected static final String PAGINATIONKEY = "pagination"; protected static final String PAGINATIONKEY = "pagination";
protected static final int INIT_PAGE = 1;
protected static final int INIT_ROWS = 10;
public PaginationController() { public PaginationController() {
} }
...@@ -32,10 +36,9 @@ public class PaginationController<T> extends ResponseController { ...@@ -32,10 +36,9 @@ public class PaginationController<T> extends ResponseController {
} }
@ModelAttribute @ModelAttribute
private void setPagnationAttribute(HttpServletRequest request, Integer rows, Integer page, String sort, String order) { private void setPagnationAttribute(HttpServletRequest request, Integer rows, Integer page, String sort) {
PageUtil _paginationUtility; PageUtil _paginationUtility = new PageUtil();
if(rows != null && page != null && sort != null ) { if(rows != null && page != null && sort != null ) {
_paginationUtility = new PageUtil();
_paginationUtility.setPageNum(page.intValue()); _paginationUtility.setPageNum(page.intValue());
_paginationUtility.setPageSize(rows.intValue()); _paginationUtility.setPageSize(rows.intValue());
_paginationUtility.setOrderBy(sort); _paginationUtility.setOrderBy(sort);
...@@ -43,15 +46,18 @@ public class PaginationController<T> extends ResponseController { ...@@ -43,15 +46,18 @@ public class PaginationController<T> extends ResponseController {
} }
else if(rows != null && page != null) { else if(rows != null && page != null) {
_paginationUtility = new PageUtil();
_paginationUtility.setPageNum(page.intValue()); _paginationUtility.setPageNum(page.intValue());
_paginationUtility.setPageSize(rows.intValue()); _paginationUtility.setPageSize(rows.intValue());
request.setAttribute(PAGINATIONKEY, _paginationUtility);
} else if(sort != null && order != null) { } else if(sort != null) {
_paginationUtility = new PageUtil(); _paginationUtility.setOrderBy(sort);
_paginationUtility.setOrderBy(sort + " " + order);
request.setAttribute(PAGINATIONKEY, _paginationUtility);
} }
else{
_paginationUtility.setPageNum(INIT_ROWS);
_paginationUtility.setPageSize(INIT_PAGE);
}
request.setAttribute(PAGINATIONKEY, _paginationUtility);
} }
......
...@@ -26,13 +26,27 @@ public class ValidatedController extends HttpServletController { ...@@ -26,13 +26,27 @@ public class ValidatedController extends HttpServletController {
public ValidatedController() { public ValidatedController() {
} }
/**
* 第一版 验证写在controller里的
* @param br
* @return
*/
public boolean hasErrors(BindingResult br) { public boolean hasErrors(BindingResult br) {
ValidatedResult vr = new ValidatedResult(); ValidatedResult vr = ValidatedResult.builder(br);
vr.dealBindingResult(br);
this.request.setAttribute("validerrors", vr); this.request.setAttribute("validerrors", vr);
return vr.hasErrors().booleanValue(); return vr.hasErrors().booleanValue();
} }
/**
* 第二版写在 aop里的
* @param br
* @return
*/
public static boolean hasErrorsByStatic(BindingResult br) {
ValidatedResult vr = ValidatedResult.builder(br);
return vr.hasErrors().booleanValue();
}
public Map<String, String[]> getErrorsMap() { public Map<String, String[]> getErrorsMap() {
ValidatedResult vr = (ValidatedResult)this.request.getAttribute("validerrors"); ValidatedResult vr = (ValidatedResult)this.request.getAttribute("validerrors");
return vr.getErrorsMap(); return vr.getErrorsMap();
...@@ -49,8 +63,7 @@ public class ValidatedController extends HttpServletController { ...@@ -49,8 +63,7 @@ public class ValidatedController extends HttpServletController {
} }
protected void setBindError(BindingResult br, Result result, String message){ protected void setBindError(BindingResult br, Result result, String message){
ValidatedResult vr = new ValidatedResult(); ValidatedResult vr = ValidatedResult.builder(br);
result.setErrorMessage(message,vr); result.setErrorMessage(message,vr);
} }
} }
package org.rcisoft.config;
import org.apache.poi.ss.formula.functions.T;
import org.rcisoft.core.aop.EntityParamAspect;
import org.rcisoft.core.aop.IdGenAspect;
import org.rcisoft.core.aop.PageUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Created by lcy on 18/1/21.
*/
@Configuration
public class AopConfig {
/**
* 分页 bean
* @return
*/
@Bean
public PageUtil<T> pageUtil(){
return new PageUtil<T>();
}
/**
* id bean
* @return
*/
@Bean
public IdGenAspect idGenAspect(){
return new IdGenAspect();
}
/**
* web param validation
* @return
*/
@Bean
public EntityParamAspect entityParamAspect(){
return new EntityParamAspect();
}
}
...@@ -4,13 +4,11 @@ import com.alibaba.fastjson.JSON; ...@@ -4,13 +4,11 @@ import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.rcisoft.business.listener.RcListener;
import org.rcisoft.core.exception.ServiceException; import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.Result; import org.rcisoft.core.result.Result;
import org.rcisoft.core.result.ResultCode; import org.rcisoft.core.result.ResultCode;
import org.rcisoft.core.util.ResultGenerator; import org.rcisoft.core.util.ResultGenerator;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
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.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
...@@ -241,14 +239,5 @@ public class MvcConfig extends WebMvcConfigurerAdapter { ...@@ -241,14 +239,5 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
} }
/**
* 监听器
* @return
*/
@Bean
public ServletListenerRegistrationBean servletListenerRegistrationBean(){
ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean();
servletListenerRegistrationBean.setListener(new RcListener());
return servletListenerRegistrationBean;
}
} }
...@@ -21,7 +21,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic ...@@ -21,7 +21,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
*/ */
@Configuration @Configuration
@EnableWebSecurity //开启WebSecurity支持 @EnableWebSecurity //开启WebSecurity支持
@EnableGlobalMethodSecurity(prePostEnabled = true) //开启prePostEnabled注解支持 @EnableGlobalMethodSecurity(prePostEnabled = true) //开启prePostEnabled注解支持 支持方法级别的安全设置 hasRole()
public class SecurityConfig extends WebSecurityConfigurerAdapter { public class SecurityConfig extends WebSecurityConfigurerAdapter {
...@@ -67,7 +67,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -67,7 +67,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
http http
.csrf() .csrf() //csrf 对 post delete put 等 进行校验 token 和jwt一样 beforeSecond:{ request.setRequestHeader()}
.disable() //由于使用的是JWT,我们这里不需要csrf .disable() //由于使用的是JWT,我们这里不需要csrf
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) //禁用session .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) //禁用session
.and() .and()
......
package org.rcisoft.core.aop;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.rcisoft.common.controller.ValidatedController;
import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.validate.ValidatedResult;
import org.springframework.validation.BindingResult;
/**
* Created by lcy on 18/1/21.
*/
@Aspect
@Slf4j
public class EntityParamAspect {
/**
* 环绕aop service.*ByPagination 分页拦截
* @param proceedingJoinPoint
* @return
*/
@Around("execution(* org.rcisoft..*.controller.*Controller.add*(..))")
public Object beforeAddValidate(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
return dealWithParameterValidate(proceedingJoinPoint);
}
@Around("execution(* org.rcisoft..*.controller.*Controller.update*(..))")
public Object beforeUpdateValidate(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
return dealWithParameterValidate(proceedingJoinPoint);
}
/**
* 处理 增加/修改 方法参数验证
* @param proceedingJoinPoint
* @return
*/
private Object dealWithParameterValidate(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
try {
/*验证 长度必须大于1*/
if(proceedingJoinPoint.getArgs().length < 2)
return proceedingJoinPoint.proceed();
/*BindingResult 必须写在第二个参数里*/
Object bindResult = proceedingJoinPoint.getArgs()[1];
if(!(bindResult instanceof BindingResult))
return proceedingJoinPoint.proceed();
BindingResult br = (BindingResult)bindResult;
/*有无异常*/
if(ValidatedController.hasErrorsByStatic(br))
throw new ServiceException(4004, ValidatedResult.builder(br).getValidatedMessage().getResponse());
/*
不能直接返回
return Result.builder(new PersistModel(0),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_INFO_INVALID,
ValidatedResult.builder(br));
com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.springframework.validation.DefaultMessageCodesResolver
and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
(through reference chain: org.rcisoft.core.result.Result["data"]->org.rcisoft.core.validate.ValidatedResult["br"]->
org.springframework.validation.BeanPropertyBindingResult["messageCodesResolver"])
getOutputStream() has already been called for this response
*/
else
return proceedingJoinPoint.proceed();
} catch (Throwable var5) {
log.error(var5.getMessage());
throw var5;
}
}
}
...@@ -2,6 +2,7 @@ package org.rcisoft.core.aop; ...@@ -2,6 +2,7 @@ package org.rcisoft.core.aop;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.rcisoft.core.entity.IdEntity; import org.rcisoft.core.entity.IdEntity;
import org.rcisoft.core.util.IdGen; import org.rcisoft.core.util.IdGen;
...@@ -11,8 +12,7 @@ import java.util.Date; ...@@ -11,8 +12,7 @@ import java.util.Date;
/** /**
* Created by lcy on 17/11/23. * Created by lcy on 17/11/23.
*/ */
//@Aspect @Aspect
//@Component
public class IdGenAspect { public class IdGenAspect {
/** /**
* 插入前 判断是否 存在id * 插入前 判断是否 存在id
......
...@@ -2,13 +2,13 @@ package org.rcisoft.core.aop; ...@@ -2,13 +2,13 @@ package org.rcisoft.core.aop;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.rcisoft.common.model.CommonPageGridModel; import org.rcisoft.common.model.CommonPageGridModel;
import org.rcisoft.common.model.GridModel; import org.rcisoft.common.model.GridModel;
import org.rcisoft.core.model.PageInfo; import org.rcisoft.core.model.PageInfo;
import org.springframework.stereotype.Component;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
...@@ -18,8 +18,8 @@ import java.util.List; ...@@ -18,8 +18,8 @@ import java.util.List;
* @author cy * @author cy
* Created by cy on 16/5/20. * Created by cy on 16/5/20.
*/ */
@Component
@Aspect @Aspect
@Slf4j
public class PageUtil<T> extends PageInfo<T> implements Serializable { public class PageUtil<T> extends PageInfo<T> implements Serializable {
private static final long serialVersionUID = 8730332880750989562L; private static final long serialVersionUID = 8730332880750989562L;
...@@ -67,7 +67,7 @@ public class PageUtil<T> extends PageInfo<T> implements Serializable { ...@@ -67,7 +67,7 @@ public class PageUtil<T> extends PageInfo<T> implements Serializable {
* @return * @return
*/ */
@Around("execution(* org.rcisoft..*.service.impl.*ServiceImpl.*ByPagination(..))") @Around("execution(* org.rcisoft..*.service.impl.*ServiceImpl.*ByPagination(..))")
public List<T> preparedPageHeplerAndloadingPageInfoSetResults(ProceedingJoinPoint proceedingJoinPoint) { public List<T> preparedPageHeplerAndloadingPageInfoSetResults(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
PageUtil paginationUtility = (PageUtil)proceedingJoinPoint.getArgs()[0]; PageUtil paginationUtility = (PageUtil)proceedingJoinPoint.getArgs()[0];
PageHelper.startPage(paginationUtility.getPageNum(), paginationUtility.getPageSize(), paginationUtility.getOrderBy()); PageHelper.startPage(paginationUtility.getPageNum(), paginationUtility.getPageSize(), paginationUtility.getOrderBy());
try { try {
...@@ -76,8 +76,8 @@ public class PageUtil<T> extends PageInfo<T> implements Serializable { ...@@ -76,8 +76,8 @@ public class PageUtil<T> extends PageInfo<T> implements Serializable {
this.setPageInfo(paginationUtility, pageInfo); this.setPageInfo(paginationUtility, pageInfo);
return e; return e;
} catch (Throwable var5) { } catch (Throwable var5) {
var5.printStackTrace(); log.error(var5.getMessage());
return null; throw var5;
} }
} }
......
...@@ -58,11 +58,13 @@ public class LxcCommand { ...@@ -58,11 +58,13 @@ public class LxcCommand {
CommandResult commandResult = null; CommandResult commandResult = null;
try { try {
File dirPath = new File(dest); File dirPath = new File(dest);
if(!dirPath.exists() || !dirPath.isDirectory()){ if(!isRemote) {
if (!dirPath.exists() || !dirPath.isDirectory()) {
log.error("目录错误 ...." + dest); log.error("目录错误 ...." + dest);
commandResult = new CommandResult(ResultCode.FAIL,"目录不存在",null); commandResult = new CommandResult(ResultCode.FAIL, "目录不存在", null);
return commandResult; return commandResult;
} }
}
if (isStart) if (isStart)
if (isRemote) if (isRemote)
remoteExecuteCommand.execute(START_LXC_COMMAND,dest); remoteExecuteCommand.execute(START_LXC_COMMAND,dest);
...@@ -73,8 +75,10 @@ public class LxcCommand { ...@@ -73,8 +75,10 @@ public class LxcCommand {
remoteExecuteCommand.execute(DOWN_LXC_COMMAND,dest); remoteExecuteCommand.execute(DOWN_LXC_COMMAND,dest);
else else
Runtime.getRuntime().exec("cd " + dest + " && " + DOWN_LXC_COMMAND); Runtime.getRuntime().exec("cd " + dest + " && " + DOWN_LXC_COMMAND);
if(!isRemote) {
dirPath.delete(); dirPath.delete();
} }
}
commandResult = new CommandResult(ResultCode.SUCCESS,null,null); commandResult = new CommandResult(ResultCode.SUCCESS,null,null);
}catch (Exception e){ }catch (Exception e){
log.error(e.getMessage()); log.error(e.getMessage());
......
package org.rcisoft.core.result;
/**
* Created with family.
* User: cy
* Date: 16/5/20
* Time: 下午1:47
* description:
*/
public class MainStatus implements ResponseMessage {
private static final long serialVersionUID = -7441079017861505376L;
private String status;
public MainStatus() {
}
public String getStatus() {
return this.status;
}
public void setStatus(String status) {
this.status = status;
}
public String getMapperKey() {
return "mainstatus";
}
}
\ No newline at end of file
...@@ -11,4 +11,6 @@ import java.io.Serializable; ...@@ -11,4 +11,6 @@ import java.io.Serializable;
*/ */
public interface ResponseMessage extends Serializable { public interface ResponseMessage extends Serializable {
String getMapperKey(); String getMapperKey();
String getResponse();
} }
package org.rcisoft.core.result; package org.rcisoft.core.result;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -9,22 +14,41 @@ import java.util.Map; ...@@ -9,22 +14,41 @@ import java.util.Map;
* Time: 下午1:45 * Time: 下午1:45
* description: * description:
*/ */
public class ValidatedMessage extends MainStatus implements ResponseMessage { @Data
public class ValidatedMessage implements ResponseMessage {
private static final long serialVersionUID = -8037198481805394212L; private static final long serialVersionUID = -8037198481805394212L;
private Map<String, String[]> validmessage;
public ValidatedMessage() { private Map<String, String[]> validMap;
private ValidatedMessage() {
}
@Override
public String getMapperKey(){
return "validatedMessage";
} }
public Map<String, String[]> getValidmessage() { private ValidatedMessage(Map<String, String[]> errorsMap){
return this.validmessage; this.validMap = errorsMap;
} }
public void setValidmessage(Map<String, String[]> validmessage) { public static ValidatedMessage builder(Map<String, String[]> errorsMap){
this.validmessage = validmessage; return new ValidatedMessage(errorsMap);
} }
public String getMapperKey() {
return "validmessage"; private String validmessage;
/**
* 错误信息
* @return
*/
@Override
public String getResponse(){
List<String> list = new ArrayList<String>();
for(Map.Entry<String,String[]> entry : this.validMap.entrySet()){
list.add(entry.getKey() + " 异常 " + entry.getValue()[0]);
}
return StringUtils.join(list,";");
} }
} }
package org.rcisoft.core.util;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import java.io.Serializable;
/**
* Created by lcy on 18/1/20.
*/
@Slf4j
public class TaskUtil implements Serializable{
private static final long serialVersionUID = -4513365435486468892L;
/**
* 开启 schedule
* @param sched
* @param trigger
* @param job
* @return
*/
public static boolean startSchedule(Scheduler sched,Trigger trigger,JobDetail job){
try {
sched.scheduleJob(job, trigger);
// 启动
if (!sched.isShutdown()) {
sched.start();
}
}catch (Exception e){
log.error(e.getMessage());
return false;
}
return true;
}
}
...@@ -5,6 +5,7 @@ import org.rcisoft.core.result.ValidatedMessage; ...@@ -5,6 +5,7 @@ import org.rcisoft.core.result.ValidatedMessage;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError; import org.springframework.validation.FieldError;
import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
...@@ -14,12 +15,24 @@ import java.util.Map; ...@@ -14,12 +15,24 @@ import java.util.Map;
* @author cy * @author cy
* Created by cy on 16/5/20. * Created by cy on 16/5/20.
*/ */
public class ValidatedResult { public class ValidatedResult implements Serializable{
private static final long serialVersionUID = -118855035745939849L;
private Boolean hasErrors = Boolean.valueOf(false); private Boolean hasErrors = Boolean.valueOf(false);
private Map<String, String[]> errorsMap; private Map<String, String[]> errorsMap;
private BindingResult br; private BindingResult br;
public ValidatedResult() { private ValidatedResult() {
}
private ValidatedResult(BindingResult br) {
this.br = br;
this.dealBindingResult();
}
public static ValidatedResult builder(BindingResult br){
return new ValidatedResult(br);
} }
public Boolean hasErrors() { public Boolean hasErrors() {
...@@ -34,7 +47,11 @@ public class ValidatedResult { ...@@ -34,7 +47,11 @@ public class ValidatedResult {
return this.br; return this.br;
} }
public Map<String, String[]> dealBindingResult(BindingResult br) { /**
* 生成map
* @return
*/
public Map<String, String[]> dealBindingResult() {
this.br = br; this.br = br;
this.errorsMap = new HashMap(); this.errorsMap = new HashMap();
if(br.hasErrors()) { if(br.hasErrors()) {
...@@ -52,9 +69,6 @@ public class ValidatedResult { ...@@ -52,9 +69,6 @@ public class ValidatedResult {
} }
public ResponseMessage getValidatedMessage() { public ResponseMessage getValidatedMessage() {
ValidatedMessage vm = new ValidatedMessage(); return ValidatedMessage.builder(this.errorsMap);
vm.setStatus("2");
vm.setValidmessage(this.errorsMap);
return vm;
} }
} }
...@@ -9,7 +9,6 @@ import org.rcisoft.common.model.TreeViewModel; ...@@ -9,7 +9,6 @@ import org.rcisoft.common.model.TreeViewModel;
import org.rcisoft.core.constant.MessageConstant; import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result; import org.rcisoft.core.result.Result;
import org.rcisoft.core.validate.ValidatedResult;
import org.rcisoft.sys.dept.entity.SysDept; import org.rcisoft.sys.dept.entity.SysDept;
import org.rcisoft.sys.dept.service.SysDeptService; import org.rcisoft.sys.dept.service.SysDeptService;
import org.rcisoft.sys.role.entity.SysRole; import org.rcisoft.sys.role.entity.SysRole;
...@@ -86,14 +85,6 @@ public class SysDeptController extends ResponseController { ...@@ -86,14 +85,6 @@ public class SysDeptController extends ResponseController {
@ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")}) @ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")})
@PostMapping("adminLog/deptAdd") @PostMapping("adminLog/deptAdd")
public Result deptAdd(@Valid SysDept dept, BindingResult br){ public Result deptAdd(@Valid SysDept dept, BindingResult br){
if(super.hasErrors(br)){
ValidatedResult vr = new ValidatedResult();
vr.dealBindingResult(br);
return Result.builder(new PersistModel(0),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_INFO_INVALID,
vr);
}
PersistModel persistModel = sysDeptServiceImpl.persistDept(dept,getToken()); PersistModel persistModel = sysDeptServiceImpl.persistDept(dept,getToken());
return Result.builder(persistModel, return Result.builder(persistModel,
MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_SUCCESS,
...@@ -113,16 +104,8 @@ public class SysDeptController extends ResponseController { ...@@ -113,16 +104,8 @@ public class SysDeptController extends ResponseController {
@ApiImplicitParam(name = "deptCode", value = "部门编号", required = false, dataType = "varchar"), @ApiImplicitParam(name = "deptCode", value = "部门编号", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "seqDate", value = "排序日期", required = false, dataType = "varchar"), @ApiImplicitParam(name = "seqDate", value = "排序日期", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")}) @ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")})
@PostMapping("adminLog/deptUpdate") @PostMapping("updateDept")
public Result deptUpdate(@Valid SysDept dept, BindingResult br){ public Result update(@Valid SysDept dept, BindingResult br){
if(super.hasErrors(br)){
ValidatedResult vr = new ValidatedResult();
vr.dealBindingResult(br);
return Result.builder(new PersistModel(0),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_INFO_INVALID,
vr);
}
PersistModel persistModel = sysDeptServiceImpl.mergeDept(dept,getToken()); PersistModel persistModel = sysDeptServiceImpl.mergeDept(dept,getToken());
return Result.builder(persistModel, return Result.builder(persistModel,
MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_SUCCESS,
...@@ -132,7 +115,7 @@ public class SysDeptController extends ResponseController { ...@@ -132,7 +115,7 @@ public class SysDeptController extends ResponseController {
@ApiOperation(value="删除部门", notes="根据ID删除部门") @ApiOperation(value="删除部门", notes="根据ID删除部门")
@ApiImplicitParam(name = "id", value = "businessId", required = true, dataType = "varchar", paramType = "path") @ApiImplicitParam(name = "id", value = "businessId", required = true, dataType = "varchar", paramType = "path")
@PostMapping("adminLog/deptDelete/{id}") @PostMapping("deptDelete/{id}")
public Result deptDelete(@PathVariable("id") String id){ public Result deptDelete(@PathVariable("id") String id){
PersistModel persistModel = sysDeptServiceImpl.removeDept(id,getToken()); PersistModel persistModel = sysDeptServiceImpl.removeDept(id,getToken());
return Result.builder(persistModel, return Result.builder(persistModel,
......
...@@ -5,6 +5,7 @@ package org.rcisoft.sys.dept.entity; ...@@ -5,6 +5,7 @@ package org.rcisoft.sys.dept.entity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.rcisoft.core.entity.IdEntity; import org.rcisoft.core.entity.IdEntity;
import javax.persistence.Entity; import javax.persistence.Entity;
...@@ -29,7 +30,8 @@ public class SysDept extends IdEntity<SysDept> { ...@@ -29,7 +30,8 @@ public class SysDept extends IdEntity<SysDept> {
private String parentId; //父机构id private String parentId; //父机构id
/*<property name="useCodeAsDefaultMessage" value="false" />*/
@Length(min = 2,max = 10,message = "部门名称{min}和{max}之间")
private String name; //部门名称 private String name; //部门名称
private String deptCode; //部门编号 private String deptCode; //部门编号
......
...@@ -2,7 +2,9 @@ package org.rcisoft.sys.dept.service.impl; ...@@ -2,7 +2,9 @@ package org.rcisoft.sys.dept.service.impl;
import org.rcisoft.common.model.TreeViewModel; import org.rcisoft.common.model.TreeViewModel;
import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.ResultExceptionEnum;
import org.rcisoft.core.util.UserUtil; import org.rcisoft.core.util.UserUtil;
import org.rcisoft.sys.dept.dao.SysDeptRepository; import org.rcisoft.sys.dept.dao.SysDeptRepository;
import org.rcisoft.sys.dept.entity.SysDept; import org.rcisoft.sys.dept.entity.SysDept;
...@@ -78,9 +80,10 @@ public class SysDeptServiceImpl implements SysDeptService { ...@@ -78,9 +80,10 @@ public class SysDeptServiceImpl implements SysDeptService {
@Override @Override
public PersistModel mergeDept(SysDept dept, String token) { public PersistModel mergeDept(SysDept dept, String token) {
//修改操作 //修改操作
UserUtil.setCurrentPersistOperation(dept); throw new ServiceException(ResultExceptionEnum.EXIST_LXC_SERVER);
/*UserUtil.setCurrentPersistOperation(dept);
int line = sysDeptRepository.updateByPrimaryKeySelective(dept); int line = sysDeptRepository.updateByPrimaryKeySelective(dept);
return new PersistModel(line); return new PersistModel(line);*/
} }
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT) @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
......
...@@ -10,7 +10,6 @@ import org.rcisoft.common.model.TreeViewModel; ...@@ -10,7 +10,6 @@ import org.rcisoft.common.model.TreeViewModel;
import org.rcisoft.core.constant.MessageConstant; import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result; import org.rcisoft.core.result.Result;
import org.rcisoft.core.validate.ValidatedResult;
import org.rcisoft.sys.menu.entity.SysMenu; import org.rcisoft.sys.menu.entity.SysMenu;
import org.rcisoft.sys.menu.service.SysMenuService; import org.rcisoft.sys.menu.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -83,14 +82,6 @@ public class SysMenuController extends ResponseController { ...@@ -83,14 +82,6 @@ public class SysMenuController extends ResponseController {
@ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")}) @ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")})
@PostMapping("adminLog/menuAdd") @PostMapping("adminLog/menuAdd")
public Result menuAdd(@Valid SysMenu menu, BindingResult br){ public Result menuAdd(@Valid SysMenu menu, BindingResult br){
if(super.hasErrors(br)){
ValidatedResult vr = new ValidatedResult();
vr.dealBindingResult(br);
return Result.builder(new PersistModel(0),
MessageConstant.MESSAGE_ALERT_INFO_INVALID,
MessageConstant.MESSAGE_ALERT_ERROR,
vr);
}
PersistModel persistModel = sysMenuServiceImpl.persistMenu(menu,getToken()); PersistModel persistModel = sysMenuServiceImpl.persistMenu(menu,getToken());
return Result.builder(persistModel, return Result.builder(persistModel,
MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_SUCCESS,
...@@ -115,14 +106,6 @@ public class SysMenuController extends ResponseController { ...@@ -115,14 +106,6 @@ public class SysMenuController extends ResponseController {
@ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")}) @ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")})
@PostMapping("adminLog/menuUpdate") @PostMapping("adminLog/menuUpdate")
public Result menuUpdate(@Valid SysMenu menu, BindingResult br){ public Result menuUpdate(@Valid SysMenu menu, BindingResult br){
if(super.hasErrors(br)){
ValidatedResult vr = new ValidatedResult();
vr.dealBindingResult(br);
return Result.builder(new PersistModel(0),
MessageConstant.MESSAGE_ALERT_INFO_INVALID,
MessageConstant.MESSAGE_ALERT_ERROR,
vr);
}
PersistModel persistModel = sysMenuServiceImpl.mergeMenu(menu,getToken()); PersistModel persistModel = sysMenuServiceImpl.mergeMenu(menu,getToken());
return Result.builder(persistModel, return Result.builder(persistModel,
MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_SUCCESS,
......
...@@ -8,7 +8,6 @@ import org.rcisoft.common.model.GridModel; ...@@ -8,7 +8,6 @@ import org.rcisoft.common.model.GridModel;
import org.rcisoft.core.constant.MessageConstant; import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result; import org.rcisoft.core.result.Result;
import org.rcisoft.core.validate.ValidatedResult;
import org.rcisoft.sys.role.entity.SysRole; import org.rcisoft.sys.role.entity.SysRole;
import org.rcisoft.sys.role.service.SysRoleService; import org.rcisoft.sys.role.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -109,16 +108,6 @@ public class SysRoleController extends PaginationController<SysRole> { ...@@ -109,16 +108,6 @@ public class SysRoleController extends PaginationController<SysRole> {
@ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")}) @ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")})
@PostMapping(value = "adminLog/roleUpdate") @PostMapping(value = "adminLog/roleUpdate")
public Result roleUpdate(@Valid SysRole sysRole, BindingResult br){ public Result roleUpdate(@Valid SysRole sysRole, BindingResult br){
Result result = new Result();
if(super.hasErrors(br)){
ValidatedResult vr = new ValidatedResult();
vr.dealBindingResult(br);
result.setSucessMessage(MessageConstant.MESSAGE_ALERT_INFO_INVALID,vr);
return Result.builder(new PersistModel(0),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_INFO_INVALID,
vr);
}
PersistModel persistModel = sysRoleServiceImpl.mergeRole(sysRole,getToken()); PersistModel persistModel = sysRoleServiceImpl.mergeRole(sysRole,getToken());
return Result.builder(persistModel, return Result.builder(persistModel,
MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_SUCCESS,
...@@ -150,17 +139,10 @@ public class SysRoleController extends PaginationController<SysRole> { ...@@ -150,17 +139,10 @@ public class SysRoleController extends PaginationController<SysRole> {
@PostMapping(value = "adminLog/rolePermission") @PostMapping(value = "adminLog/rolePermission")
public Result rolePermission(@RequestParam("roleId") String roleId, @RequestParam("role_menus") String role_menus ){ public Result rolePermission(@RequestParam("roleId") String roleId, @RequestParam("role_menus") String role_menus ){
PersistModel persistModel = sysRoleServiceImpl.doAuthorization(roleId,role_menus,getToken()); return Result.builder(sysRoleServiceImpl.doAuthorization(roleId,role_menus,getToken()),
if(persistModel.isSuccessBySinglePersist())
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
roleId); roleId);
else
return Result.builder(new PersistModel(0),
MessageConstant.MESSAGE_ALERT_ERROR,
MessageConstant.MESSAGE_ALERT_ERROR,
roleId);
} }
@ApiOperation(value="岗位绑定", notes="岗位绑定") @ApiOperation(value="岗位绑定", notes="岗位绑定")
......
...@@ -105,6 +105,7 @@ global: ...@@ -105,6 +105,7 @@ global:
max_password: 16 max_password: 16
path: path:
base_upload_server_location: /working/resource/eduServer/ base_upload_server_location: /working/resource/eduServer/
physical_upload_server_location: /working/dockervolume/edu2_data_ubuntu/eduServer
course_location: course course_location: course
lesson_location: lesson lesson_location: lesson
sl_location: sl sl_location: sl
...@@ -142,6 +143,6 @@ global: ...@@ -142,6 +143,6 @@ global:
html_project: '1002' html_project: '1002'
serverLxc: serverLxc:
ip: 192.168.1.130 ip: 106.2.3.134
username: root username: root
password: 123456 password: 91isoft_xunda
\ No newline at end of file \ No newline at end of file
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