|
|
|
|
@ -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<String, String> xuanxiangDetails = new LinkedHashMap<>();
|
|
|
|
|
Map<String, BigDecimal> pingFenDetails = new LinkedHashMap<>();
|
|
|
|
|
BigDecimal num = new BigDecimal("1");//投票人数+1
|
|
|
|
|
List<KhVoteEmp> 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<KhVoteItems> 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();
|
|
|
|
|
}
|
|
|
|
|
|