diff --git a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java index 32eb6f1..775f772 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java @@ -3,6 +3,7 @@ package com.ruoyi; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.scheduling.annotation.EnableScheduling; /** * 启动程序 @@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; * @author ruoyi */ @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) +@EnableScheduling public class RuoYiApplication { public static void main(String[] args) diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhVoteController.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhVoteController.java index 63c14c3..3978e4d 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhVoteController.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhVoteController.java @@ -1,14 +1,18 @@ package com.ruoyi.kaohe.controller; +import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletResponse; import com.ruoyi.kaohe.domain.KhPcEmp; +import com.ruoyi.kaohe.domain.KhPingce; import com.ruoyi.kaohe.domain.KhVoteEmp; import com.ruoyi.kaohe.service.IKhPcEmpService; import com.ruoyi.kaohe.service.IKhVoteEmpService; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -29,14 +33,13 @@ import com.ruoyi.common.core.page.TableDataInfo; /** * 投票评测Controller - * + * * @author hs * @date 2025-06-17 */ @RestController @RequestMapping("/kaohe/vote") -public class KhVoteController extends BaseController -{ +public class KhVoteController extends BaseController { @Autowired private IKhVoteService khVoteService; @Autowired @@ -44,24 +47,48 @@ public class KhVoteController extends BaseController @Autowired private IKhVoteEmpService voteEmpService; + /*@Scheduled(cron = "0 * * * * ?") // 每分钟的第0秒执行一次 监测时间修改评分状态 + public void performTask() { + System.out.println("进入定时任务-------------------------------------------------------------"); + //获取所有未完成的评分任务 + List list = khVoteService.selectUnfinishedVote(); + for (KhVote vote : list) { + Date sTime = vote.getsTime(); + Date eTime = vote.geteTime(); + String state = vote.getState(); + // 获取当前日期和时间 + Date now = new Date(); + // 根据当前时间与开始、结束时间关系 修改状态 + if (state.equals("0") && (now.after(sTime) && now.before(eTime))) { + vote.setState("1"); + khVoteService.updateKhVote(vote); + System.out.println("执行定时任务: " + System.currentTimeMillis() + " 修改评分任务: " + vote.getVoteTitle() + " 状态为进行中"); + } + if (now.after(eTime)) { + vote.setState("2"); + khVoteService.updateKhVote(vote); + System.out.println("执行定时任务: " + System.currentTimeMillis() + " 修改评分任务: " + vote.getVoteTitle() + " 状态为已完成"); + } + } + }*/ + /** * 查询投票评测列表 */ @PreAuthorize("@ss.hasPermi('kaohe:vote:list')") @GetMapping("/list") - public TableDataInfo list(KhVote khVote) - { + public TableDataInfo list(KhVote khVote) { startPage(); List list = khVoteService.selectKhVoteList(khVote); return getDataTable(list); } + /** * 首页根据pingceId、itemIds、state查询投票评测列表 */ @PreAuthorize("@ss.hasPermi('kaohe:vote:list')") @GetMapping("/listByConditons") - public TableDataInfo getListByConditons(KhVote khVote) - { + public TableDataInfo getListByConditons(KhVote khVote) { startPage(); List list = khVoteService.getListByPcIdAndItemIds(khVote); return getDataTable(list); @@ -73,8 +100,7 @@ public class KhVoteController extends BaseController @PreAuthorize("@ss.hasPermi('kaohe:vote:export')") @Log(title = "投票评测", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, KhVote khVote) - { + public void export(HttpServletResponse response, KhVote khVote) { List list = khVoteService.selectKhVoteList(khVote); ExcelUtil util = new ExcelUtil(KhVote.class); util.exportExcel(response, list, "投票评测数据"); @@ -85,8 +111,7 @@ public class KhVoteController extends BaseController */ @PreAuthorize("@ss.hasPermi('kaohe:vote:query')") @GetMapping(value = "/{id}") - public AjaxResult getInfo(@PathVariable("id") Long id) - { + public AjaxResult getInfo(@PathVariable("id") Long id) { return success(khVoteService.selectKhVoteById(id)); } @@ -97,14 +122,13 @@ public class KhVoteController extends BaseController @Log(title = "投票评测", businessType = BusinessType.INSERT) @PostMapping @Transactional - public AjaxResult add(@RequestBody KhVote khVote) - { + public AjaxResult add(@RequestBody KhVote khVote) { khVoteService.insertKhVote(khVote); //根据评测id查询职工评测关联 职工 KhPcEmp query = new KhPcEmp(); query.setPcId(khVote.getPingceId()); List pcEmps = pcEmpService.selectKhPcEmpList(query); - for(KhPcEmp pcEmp:pcEmps){ + for (KhPcEmp pcEmp : pcEmps) { //新增投票选项关联表 KhVoteEmp voteEmp = new KhVoteEmp(); voteEmp.setBkhdxId(pcEmp.getBkhdxId()); @@ -123,8 +147,7 @@ public class KhVoteController extends BaseController @PreAuthorize("@ss.hasPermi('kaohe:vote:edit')") @Log(title = "投票评测", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody KhVote khVote) - { + public AjaxResult edit(@RequestBody KhVote khVote) { return toAjax(khVoteService.updateKhVote(khVote)); } @@ -133,9 +156,8 @@ public class KhVoteController extends BaseController */ @PreAuthorize("@ss.hasPermi('kaohe:vote:remove')") @Log(title = "投票评测", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") - public AjaxResult remove(@PathVariable Long[] ids) - { + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(khVoteService.deleteKhVoteByIds(ids)); } } diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/mapper/KhVoteMapper.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/mapper/KhVoteMapper.java index cb3f5bd..18ea116 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/mapper/KhVoteMapper.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/mapper/KhVoteMapper.java @@ -60,4 +60,6 @@ public interface KhVoteMapper public int deleteKhVoteByIds(Long[] ids); List getListByPcIdAndItemIds(KhVote khVote); + + List selectUnfinishedVote(); } diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/IKhVoteService.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/IKhVoteService.java index 9365034..7c413bb 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/IKhVoteService.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/IKhVoteService.java @@ -60,4 +60,6 @@ public interface IKhVoteService public int deleteKhVoteById(Long id); List getListByPcIdAndItemIds(KhVote khVote); + + List selectUnfinishedVote(); } diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhVoteServiceImpl.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhVoteServiceImpl.java index c03c5fa..236ae8e 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhVoteServiceImpl.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhVoteServiceImpl.java @@ -98,4 +98,9 @@ public class KhVoteServiceImpl implements IKhVoteService public List getListByPcIdAndItemIds(KhVote khVote) { return khVoteMapper.getListByPcIdAndItemIds(khVote); } + + @Override + public List selectUnfinishedVote() { + return khVoteMapper.selectUnfinishedVote(); + } } diff --git a/ruoyi-kaohe/src/main/resources/mapper/kaohe/KhVoteMapper.xml b/ruoyi-kaohe/src/main/resources/mapper/kaohe/KhVoteMapper.xml index 0db0542..a7b72e2 100644 --- a/ruoyi-kaohe/src/main/resources/mapper/kaohe/KhVoteMapper.xml +++ b/ruoyi-kaohe/src/main/resources/mapper/kaohe/KhVoteMapper.xml @@ -61,6 +61,10 @@ +