diff --git a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java index 775f772..4bd33a1 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.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; /** @@ -11,6 +12,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; * @author ruoyi */ @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) +@EnableAsync @EnableScheduling public class RuoYiApplication { diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java index 350a02e..e1f6ba2 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java @@ -52,7 +52,8 @@ public class ResourcesConfig implements WebMvcConfigurer registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**"); registry.addInterceptor(licenseInterceptor) .addPathPatterns("/**") - .excludePathPatterns("/login", "/license/**"); + .excludePathPatterns("/login", "/license/**","/kaohe/vote_emp/voteSubmit"); + } /** diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhTemplateController.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhTemplateController.java index 51797f8..ea258a0 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhTemplateController.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhTemplateController.java @@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletResponse; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.kaohe.domain.*; +import com.ruoyi.kaohe.service.IKhPingceService; import com.ruoyi.kaohe.service.IKhTemItemService; import com.ruoyi.kaohe.service.IKhVoteService; import org.springframework.security.access.prepost.PreAuthorize; @@ -38,6 +39,8 @@ public class KhTemplateController extends BaseController private IKhTemItemService temItemService; @Autowired private IKhVoteService voteService; + @Autowired + private IKhPingceService pingceService; /** * 查询考核模板列表 @@ -162,6 +165,14 @@ public class KhTemplateController extends BaseController @Transactional public AjaxResult edit(@RequestBody KhTemplate khTemplate) { + //修改,当考核任务再用这个模板时 不允许修改 + KhPingce pingce = new KhPingce(); + pingce.setTemplateId(khTemplate.getId()); + pingce.setState("0"); + List khPingces = pingceService.selectKhUsedPingceList(pingce); + if(khPingces!=null&&khPingces.size()>0){ + return AjaxResult.error("有考核任务已使用模板,不能修改"); + } khTemplateService.updateKhTemplate(khTemplate); List items = khTemplate.getItems(); if(items !=null&& items.size()>0){ @@ -178,6 +189,8 @@ public class KhTemplateController extends BaseController temItem.setTemId(khTemplate.getId()); temItem.setItemName(item.getItemName()); temItem.setKhitemId(item.getId()); + temItem.setType(item.getType()); + temItem.setTypeId(item.getTypeId()); temItemService.insertKhTemItem(temItem); } } @@ -192,6 +205,16 @@ public class KhTemplateController extends BaseController @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { + //修改,当考核任务再用这个模板时 不允许修改 + for(Long id:ids){ + KhPingce pingce = new KhPingce(); + pingce.setTemplateId(id); + pingce.setState("0"); + List khPingces = pingceService.selectKhUsedPingceList(pingce); + if(khPingces!=null&&khPingces.size()>0){ + return AjaxResult.error("有考核任务已使用模板,不能删除"); + } + } return toAjax(khTemplateService.deleteKhTemplateByIds(ids)); } } 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 6484e4f..aa805cc 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 @@ -46,7 +46,7 @@ public class KhVoteController extends BaseController { @Autowired private IKhTemItemService khTemItemService; - @Scheduled(cron = "0 * * * * ?") // 每分钟的第0秒执行一次 监测时间修改评分状态 + /*@Scheduled(cron = "0 * * * * ?") // 每分钟的第0秒执行一次 监测时间修改评分状态 public void performTask() { System.out.println("进入定时任务-------------------------------------------------------------"); //获取所有未完成的评分任务 @@ -97,7 +97,7 @@ public class KhVoteController extends BaseController { } } - } + }*/ /** * 查询投票评测列表 diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhVoteRecardParam.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhVoteRecardParam.java index c2b49b7..e34bc4b 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhVoteRecardParam.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhVoteRecardParam.java @@ -23,7 +23,7 @@ public class KhVoteRecardParam extends BaseEntity /** 评测id */ @Excel(name = "评测id") - private Long pcId; + private Long pingceId; /** 考核类型id */ @Excel(name = "考核类型id") @@ -76,12 +76,12 @@ public class KhVoteRecardParam extends BaseEntity this.khitemTypeid = khitemTypeid; } - public Long getPcId() { - return pcId; + public Long getPingceId() { + return pingceId; } - public void setPcId(Long pcId) { - this.pcId = pcId; + public void setPingceId(Long pingceId) { + this.pingceId = pingceId; } public Long getKhitemId() { diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/mapper/KhPingceMapper.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/mapper/KhPingceMapper.java index cd6c135..2793dc3 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/mapper/KhPingceMapper.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/mapper/KhPingceMapper.java @@ -58,4 +58,6 @@ public interface KhPingceMapper * @return 结果 */ public int deleteKhPingceByIds(Long[] ids); + + List selectKhUsedPingceList(KhPingce pingce); } diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/IKhPingceService.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/IKhPingceService.java index d82cd7e..13fb06d 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/IKhPingceService.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/IKhPingceService.java @@ -60,4 +60,6 @@ public interface IKhPingceService public int deleteKhPingceById(Long id); int deleteKhPingceByIds2(Long[] toArray); + + List selectKhUsedPingceList(KhPingce pingce); } diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhPingceServiceImpl.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhPingceServiceImpl.java index 4de8c2d..2422dd9 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhPingceServiceImpl.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhPingceServiceImpl.java @@ -60,6 +60,11 @@ public class KhPingceServiceImpl implements IKhPingceService return khPingceMapper.selectKhPingceList(khPingce); } + @Override + public List selectKhUsedPingceList(KhPingce pingce) { + return khPingceMapper.selectKhUsedPingceList(pingce); + } + /** * 新增考核评测 * diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhVoteEmpServiceImpl.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhVoteEmpServiceImpl.java index dc0193a..40ee37b 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhVoteEmpServiceImpl.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/service/impl/KhVoteEmpServiceImpl.java @@ -14,6 +14,7 @@ import com.ruoyi.kaohe.domain.KhVoteRecardParam; import com.ruoyi.kaohe.mapper.KhVoteItemsMapper; import com.ruoyi.kaohe.mapper.KhVoteRecardMapper; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import com.ruoyi.kaohe.mapper.KhVoteEmpMapper; import com.ruoyi.kaohe.domain.KhVoteEmp; @@ -113,13 +114,25 @@ public class KhVoteEmpServiceImpl implements IKhVoteEmpService { @Override @Transactional + @Async("threadPoolTaskExecutor") public AjaxResult voteSubmit(KhVoteRecardParam param) { + System.out.println("------------------------开始异步批量处理用户数据,线程:" + Thread.currentThread().getName()); Map xuanxiangDetails = new LinkedHashMap<>(); Map pingFenDetails = new LinkedHashMap<>(); BigDecimal num = new BigDecimal("1");//投票人数+1 List voteEmpList = param.getVoteEmpList(); Date nowDate = DateUtils.getNowDate(); Long typeid = param.getKhitemTypeid(); + + //存储投票记录 + KhVoteRecard recard = new KhVoteRecard(); + recard.setRemark(JSON.toJSONString(voteEmpList)); + recard.setPcId(param.getPingceId()); + recard.setVoteId(param.getVoteId()); + recard.setUserId(param.getUserId()); + recard.setUserName(param.getUserName()); + // recard.setUid(param.getUid()); + //选项评分 if (typeid.equals(1L)) { List voteItems = khVoteItemsMapper.selectKhVoteItemsList(null);//从数据库获取分值 @@ -198,14 +211,16 @@ public class KhVoteEmpServiceImpl implements IKhVoteEmpService { } else { // 更新失败,版本冲突,增加重试计数 retryCount++; - System.out.println("-----------版本冲突," + voteEmp.getId() + "第" + retryCount + "次重试"); - // if (retryCount < MAX_RETRY_COUNT) { + if (retryCount > 3) { + throw new RuntimeException("重试次数过多被中断-------------"); + } + System.out.println("-----------版本冲突," + voteEmp.getBkhdxName() + "第" + retryCount + "次重试"); // 等待一段时间后重试,避免立即重试导致的持续冲突 try { - Thread.sleep(100* retryCount); // 重试间隔递增 + Thread.sleep(500 * retryCount); // 重试间隔递增 } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new RuntimeException("重试过程被中断-------------", e); + throw new RuntimeException("重试过程异常中断-------------", e); } // } } @@ -231,14 +246,16 @@ public class KhVoteEmpServiceImpl implements IKhVoteEmpService { } else { // 更新失败,版本冲突,增加重试计数 retryCount++; - System.out.println("-----------版本冲突," + voteEmp.getId() + "第" + retryCount + "次重试"); - // if (retryCount < MAX_RETRY_COUNT) { + if (retryCount > 3) { + throw new RuntimeException("重试次数过多被中断-------------"); + } + System.out.println("-----------版本冲突," + voteEmp.getBkhdxName() + "第" + retryCount + "次重试"); // 等待一段时间后重试,避免立即重试导致的持续冲突 try { - Thread.sleep(100* retryCount); // 重试间隔递增 + Thread.sleep(500 * retryCount); // 重试间隔递增 } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new RuntimeException("重试过程被中断-------------", e); + throw new RuntimeException("重试过程异常中断-------------", e); } } } @@ -263,14 +280,16 @@ public class KhVoteEmpServiceImpl implements IKhVoteEmpService { } else { // 更新失败,版本冲突,增加重试计数 retryCount++; - System.out.println("-----------版本冲突," + voteEmp.getId() + "第" + retryCount + "次重试"); - // if (retryCount < MAX_RETRY_COUNT) { + if (retryCount > 3) { + throw new RuntimeException("重试次数过多被中断-------------"); + } + System.out.println("-----------版本冲突," + voteEmp.getBkhdxName() + "第" + retryCount + "次重试"); // 等待一段时间后重试,避免立即重试导致的持续冲突 try { - Thread.sleep(100* retryCount); // 重试间隔递增 + Thread.sleep(500 * retryCount); // 重试间隔递增 } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new RuntimeException("重试过程被中断-------------", e); + throw new RuntimeException("重试过程异常中断-------------", e); } } } @@ -278,11 +297,6 @@ public class KhVoteEmpServiceImpl implements IKhVoteEmpService { } //存储投票记录 - KhVoteRecard recard = new KhVoteRecard(); - recard.setVoteId(param.getVoteId()); - recard.setUserId(param.getUserId()); - recard.setUserName(param.getUserName()); - recard.setUid(param.getUid()); recard.setVoteTime(nowDate); if (typeid.equals(1L)) {//选项评分 recard.setVoteDetails(JSON.toJSONString(xuanxiangDetails)); @@ -297,7 +311,6 @@ public class KhVoteEmpServiceImpl implements IKhVoteEmpService { .collect(Collectors.toList()); recard.setVoteDetails(JSON.toJSONString(details));*/ } - recard.setRemark(JSON.toJSONString(voteEmpList)); khVoteRecardMapper.insertKhVoteRecard(recard); return AjaxResult.success(); } diff --git a/ruoyi-kaohe/src/main/resources/mapper/kaohe/KhPingceMapper.xml b/ruoyi-kaohe/src/main/resources/mapper/kaohe/KhPingceMapper.xml index 7bdc068..cd7255f 100644 --- a/ruoyi-kaohe/src/main/resources/mapper/kaohe/KhPingceMapper.xml +++ b/ruoyi-kaohe/src/main/resources/mapper/kaohe/KhPingceMapper.xml @@ -53,6 +53,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ORDER BY id DESC + +