定时任务同步
parent
0131540f11
commit
8580d469d0
|
|
@ -5,6 +5,10 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import com.cpxt.biz.domain.BizOrderTask;
|
||||
import com.cpxt.biz.service.IBizOrderTaskService;
|
||||
import com.cpxt.quartz.domain.SysJob;
|
||||
import com.cpxt.quartz.service.ISysJobService;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
|
@ -35,6 +39,9 @@ public class BizOrderTaskController extends BaseController
|
|||
@Autowired
|
||||
private IBizOrderTaskService bizOrderTaskService;
|
||||
|
||||
@Autowired
|
||||
private ISysJobService jobService;
|
||||
|
||||
/**
|
||||
* 查询订单任务列表
|
||||
*/
|
||||
|
|
@ -102,4 +109,32 @@ public class BizOrderTaskController extends BaseController
|
|||
{
|
||||
return toAjax(bizOrderTaskService.deleteBizOrderTaskByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务状态修改
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
|
||||
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/changeStatus")
|
||||
public AjaxResult changeStatus(@RequestBody BizOrderTask orderTask) throws SchedulerException
|
||||
{
|
||||
// 同步修改task表中的状态
|
||||
bizOrderTaskService.updateBizOrderTaskStatus(orderTask.getJobId(),orderTask.getStatus());
|
||||
SysJob newJob = jobService.selectJobById(orderTask.getJobId());
|
||||
newJob.setStatus(orderTask.getStatus());
|
||||
return toAjax(jobService.changeStatus(newJob));
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务立即执行一次
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
|
||||
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/run")
|
||||
public AjaxResult run(@RequestBody BizOrderTask orderTask) throws SchedulerException
|
||||
{
|
||||
SysJob newJob = jobService.selectJobById(orderTask.getJobId());
|
||||
boolean result = jobService.run(newJob);
|
||||
return result ? success() : error("任务不存在或已过期!");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,22 @@ public class SysLoginController
|
|||
return ajax;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录方法
|
||||
*
|
||||
* @param loginBody 登录信息
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/appLogin")
|
||||
public AjaxResult appLogin(@RequestBody LoginBody loginBody)
|
||||
{
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
// 生成令牌
|
||||
String token = loginService.appLogin(loginBody.getUsername(), loginBody.getPassword());
|
||||
ajax.put(Constants.TOKEN, token);
|
||||
return ajax;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class SysLoginService
|
|||
|
||||
/**
|
||||
* 登录验证
|
||||
*
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @param code 验证码
|
||||
|
|
@ -100,6 +100,52 @@ public class SysLoginService
|
|||
return tokenService.createToken(loginUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录验证
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @return 结果
|
||||
*/
|
||||
public String appLogin(String username, String password)
|
||||
{
|
||||
// 验证码校验
|
||||
// validateCaptcha(username, code, uuid);
|
||||
// 登录前置校验
|
||||
loginPreCheck(username, password);
|
||||
// 用户验证
|
||||
Authentication authentication = null;
|
||||
try
|
||||
{
|
||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
|
||||
AuthenticationContextHolder.setContext(authenticationToken);
|
||||
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
|
||||
authentication = authenticationManager.authenticate(authenticationToken);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e instanceof BadCredentialsException)
|
||||
{
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
||||
throw new UserPasswordNotMatchException();
|
||||
}
|
||||
else
|
||||
{
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
AuthenticationContextHolder.clearContext();
|
||||
}
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
||||
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
||||
recordLoginInfo(loginUser.getUserId());
|
||||
// 生成token
|
||||
return tokenService.createToken(loginUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
*
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import java.util.List;
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cpxt.biz.domain.BizOrderTask;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* 订单任务Mapper接口
|
||||
|
|
@ -16,4 +18,6 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
public interface BizOrderTaskMapper extends BaseMapper<BizOrderTask>
|
||||
{
|
||||
|
||||
@Update("update biz_order_task set status = #{status} where job_id = ${jobId}")
|
||||
void updateBizOrderTaskStatus(@Param("jobId") Long jobId,@Param("status") String status);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,4 +58,6 @@ public interface IBizOrderTaskService
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteBizOrderTaskById(Integer id);
|
||||
|
||||
void updateBizOrderTaskStatus(Long jobId,String status);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,4 +141,9 @@ public class BizOrderTaskServiceImpl implements IBizOrderTaskService
|
|||
{
|
||||
return bizOrderTaskMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBizOrderTaskStatus(Long jobId,String status) {
|
||||
bizOrderTaskMapper.updateBizOrderTaskStatus(jobId,status);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue