package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.whyc.dto.ProcessServerDao;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.ProcessSurveyMapper;
|
import com.whyc.pojo.db_user.ProcessSurvey;
|
import com.whyc.util.ActionUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
|
@Service
|
public class ProcessSurveyService {
|
@Resource
|
private ProcessSurveyMapper mapper;
|
|
public Response getAll(){
|
QueryWrapper<ProcessSurvey> queryWrapper = new QueryWrapper<>();
|
queryWrapper.orderByAsc("num");
|
List<ProcessSurvey> list = mapper.selectList(queryWrapper);
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
for (ProcessSurvey survey:list) {
|
survey.setNote(sdf.format(new Date()));
|
}
|
return new Response().set(1,list,"查询成功");
|
}
|
|
public Response updateById(ProcessSurvey survey){
|
mapper.updateById(survey);
|
return new Response().set(1,true,"更新成功");
|
}
|
|
public Response updateServerFlagOff(ProcessSurvey survey){
|
UpdateWrapper<ProcessSurvey> updateWrapper = new UpdateWrapper<>();
|
updateWrapper.set("serverflag", ProcessServerDao.PROCESS_OFF);
|
updateWrapper.eq("processName",survey.getProcessName());
|
updateWrapper.eq("serverflag",ProcessServerDao.PROCESS_TEMP);
|
mapper.update(survey,updateWrapper);
|
return new Response().set(1,true,"更新成功");
|
}
|
|
public Response updateServerFlagByName(ProcessSurvey survey){
|
UpdateWrapper<ProcessSurvey> updateWrapper = new UpdateWrapper<>();
|
updateWrapper.eq("serverName",survey.getServerName());
|
mapper.update(survey,updateWrapper);
|
return new Response().set(1,true,"更新成功");
|
}
|
|
|
public void setUpThreadRestart() {
|
//主线 --->11001
|
threadRestart(11001);
|
}
|
|
private void threadRestart(int processId) {
|
UpdateWrapper<ProcessSurvey> update = Wrappers.update();
|
update.set("ServerFlag",0).eq("ProcessId",processId).ne("ServerFlag",2);
|
mapper.update((ProcessSurvey) ActionUtil.objeNull,update);
|
}
|
|
}
|