定时任务同步

master
luojian 2024-12-21 17:14:09 +08:00
parent 0131540f11
commit 8580d469d0
6 changed files with 109 additions and 1 deletions

View File

@ -5,6 +5,10 @@ import javax.servlet.http.HttpServletResponse;
import com.cpxt.biz.domain.BizOrderTask; import com.cpxt.biz.domain.BizOrderTask;
import com.cpxt.biz.service.IBizOrderTaskService; 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.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -35,6 +39,9 @@ public class BizOrderTaskController extends BaseController
@Autowired @Autowired
private IBizOrderTaskService bizOrderTaskService; private IBizOrderTaskService bizOrderTaskService;
@Autowired
private ISysJobService jobService;
/** /**
* *
*/ */
@ -102,4 +109,32 @@ public class BizOrderTaskController extends BaseController
{ {
return toAjax(bizOrderTaskService.deleteBizOrderTaskByIds(ids)); 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("任务不存在或已过期!");
}
} }

View File

@ -56,6 +56,22 @@ public class SysLoginController
return ajax; 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;
}
/** /**
* *
* *

View File

@ -100,6 +100,52 @@ public class SysLoginService
return tokenService.createToken(loginUser); 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);
}
/** /**
* *
* *

View File

@ -5,6 +5,8 @@ import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cpxt.biz.domain.BizOrderTask; import com.cpxt.biz.domain.BizOrderTask;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
/** /**
* Mapper * Mapper
@ -16,4 +18,6 @@ import org.apache.ibatis.annotations.Mapper;
public interface BizOrderTaskMapper extends BaseMapper<BizOrderTask> 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);
} }

View File

@ -58,4 +58,6 @@ public interface IBizOrderTaskService
* @return * @return
*/ */
public int deleteBizOrderTaskById(Integer id); public int deleteBizOrderTaskById(Integer id);
void updateBizOrderTaskStatus(Long jobId,String status);
} }

View File

@ -141,4 +141,9 @@ public class BizOrderTaskServiceImpl implements IBizOrderTaskService
{ {
return bizOrderTaskMapper.deleteById(id); return bizOrderTaskMapper.deleteById(id);
} }
@Override
public void updateBizOrderTaskStatus(Long jobId,String status) {
bizOrderTaskMapper.updateBizOrderTaskStatus(jobId,status);
}
} }