Commit 41f11e9b authored by chicheng's avatar chicheng

报工防重复提交

parent 8337b5cc
...@@ -206,6 +206,7 @@ pro.feedback.error.serialNo.not.bind.workOrder=\u5E8F\u5217\u53F7\u4E0D\u5C5E\u6 ...@@ -206,6 +206,7 @@ pro.feedback.error.serialNo.not.bind.workOrder=\u5E8F\u5217\u53F7\u4E0D\u5C5E\u6
pro.feedback.error.min.quantity=\u62A5\u5DE5\u6570\u91CF\u4E0D\u80FD\u5C0F\u4E8E\u7B49\u4E8E0 pro.feedback.error.min.quantity=\u62A5\u5DE5\u6570\u91CF\u4E0D\u80FD\u5C0F\u4E8E\u7B49\u4E8E0
pro.feedback.error.quantity.lack=\u53EF\u62A5\u5DE5\u6570\u91CF\u4E0D\u8DB3 pro.feedback.error.quantity.lack=\u53EF\u62A5\u5DE5\u6570\u91CF\u4E0D\u8DB3
pro.feedback.error.before.start=\u8BF7\u5148\u8FDB\u884C\u5F00\u59CB\u4F5C\u4E1A\u64CD\u4F5C pro.feedback.error.before.start=\u8BF7\u5148\u8FDB\u884C\u5F00\u59CB\u4F5C\u4E1A\u64CD\u4F5C
pro.feedback.error.repeat.submit=\u62A5\u5DE5\u5904\u7406\u4E2D\uFF0C\u8BF7\u52FF\u91CD\u590D\u63D0\u4EA4
pro.feedback.error.not.find.start=\u6392\u4EA7\u4EFB\u52A1\u6CA1\u6709\u5F00\u5DE5\u8BB0\u5F55 pro.feedback.error.not.find.start=\u6392\u4EA7\u4EFB\u52A1\u6CA1\u6709\u5F00\u5DE5\u8BB0\u5F55
pro.feedback.error.cannot.delete.last.process=\u6700\u540E\u4E00\u9053\u5DE5\u5E8F\u62A5\u5DE5\u65E0\u6CD5\u4FEE\u6539\u6216\u8005\u5220\u9664 pro.feedback.error.cannot.delete.last.process=\u6700\u540E\u4E00\u9053\u5DE5\u5E8F\u62A5\u5DE5\u65E0\u6CD5\u4FEE\u6539\u6216\u8005\u5220\u9664
pro.feedback.error.error1=\u4E0B\u4E00\u9053\u5DE5\u5E8F\u53EF\u64A4\u56DE\u7684\u6570\u91CF\u4E0D\u591F pro.feedback.error.error1=\u4E0B\u4E00\u9053\u5DE5\u5E8F\u53EF\u64A4\u56DE\u7684\u6570\u91CF\u4E0D\u591F
......
...@@ -196,6 +196,7 @@ pro.feedback.error.serialNo.not.bind.workOrder=The serial number does not belong ...@@ -196,6 +196,7 @@ pro.feedback.error.serialNo.not.bind.workOrder=The serial number does not belong
pro.feedback.error.min.quantity=The reported quantity cannot be less than or equal to 0. pro.feedback.error.min.quantity=The reported quantity cannot be less than or equal to 0.
pro.feedback.error.quantity.lack=Insufficient quantity available for reporting. pro.feedback.error.quantity.lack=Insufficient quantity available for reporting.
pro.feedback.error.before.start=Please perform start operation first. pro.feedback.error.before.start=Please perform start operation first.
pro.feedback.error.repeat.submit=Feedback is being processed, please do not submit again.
pro.feedback.error.not.find.start=There is no start record for the production scheduling task. pro.feedback.error.not.find.start=There is no start record for the production scheduling task.
pro.feedback.error.cannot.delete.last.process=The reporting of the last process cannot be modified or deleted. pro.feedback.error.cannot.delete.last.process=The reporting of the last process cannot be modified or deleted.
pro.feedback.error.error1=The quantity that can be withdrawn in the next process is insufficient. pro.feedback.error.error1=The quantity that can be withdrawn in the next process is insufficient.
......
...@@ -203,6 +203,7 @@ pro.feedback.error.serialno.not.bind.workOrder=\u0E2B\u0E21\u0E32\u0E22\u0E40\u0 ...@@ -203,6 +203,7 @@ pro.feedback.error.serialno.not.bind.workOrder=\u0E2B\u0E21\u0E32\u0E22\u0E40\u0
pro.feedback.error.min.quantity=\u0E08\u0E4D\u0E32\u0E19\u0E27\u0E19\u0E07\u0E32\u0E19\u0E15\u0E49\u0E2D\u0E07\u0E44\u0E21\u0E48\u0E19\u0E49\u0E2D\u0E22\u0E01\u0E27\u0E48\u0E32\u0E2B\u0E23\u0E37\u0E2D\u0E40\u0E17\u0E48\u0E32\u0E01\u0E31\u0E1A0 pro.feedback.error.min.quantity=\u0E08\u0E4D\u0E32\u0E19\u0E27\u0E19\u0E07\u0E32\u0E19\u0E15\u0E49\u0E2D\u0E07\u0E44\u0E21\u0E48\u0E19\u0E49\u0E2D\u0E22\u0E01\u0E27\u0E48\u0E32\u0E2B\u0E23\u0E37\u0E2D\u0E40\u0E17\u0E48\u0E32\u0E01\u0E31\u0E1A0
pro.feedback.error.quantity.lack=\u0E08\u0E4D\u0E32\u0E19\u0E27\u0E19\u0E07\u0E32\u0E19\u0E17\u0E35\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E23\u0E32\u0E22\u0E07\u0E32\u0E19\u0E44\u0E14\u0E49\u0E44\u0E21\u0E48\u0E40\u0E1E\u0E35\u0E22\u0E07\u0E1E\u0E2D pro.feedback.error.quantity.lack=\u0E08\u0E4D\u0E32\u0E19\u0E27\u0E19\u0E07\u0E32\u0E19\u0E17\u0E35\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E23\u0E32\u0E22\u0E07\u0E32\u0E19\u0E44\u0E14\u0E49\u0E44\u0E21\u0E48\u0E40\u0E1E\u0E35\u0E22\u0E07\u0E1E\u0E2D
pro.feedback.error.before.start=\u0E42\u0E1B\u0E23\u0E14\u0E40\u0E23\u0E34\u0E48\u0E21\u0E07\u0E32\u0E19\u0E01\u0E48\u0E2D\u0E19 pro.feedback.error.before.start=\u0E42\u0E1B\u0E23\u0E14\u0E40\u0E23\u0E34\u0E48\u0E21\u0E07\u0E32\u0E19\u0E01\u0E48\u0E2D\u0E19
pro.feedback.error.repeat.submit=\u0E01\u0E33\u0E25\u0E31\u0E07\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E41\u0E08\u0E49\u0E07\u0E40\u0E15\u0E37\u0E2D\u0E19 \u0E01\u0E23\u0E38\u0E13\u0E32\u0E2D\u0E22\u0E48\u0E32\u0E2A\u0E48\u0E07\u0E0B\u0E49\u0E33
pro.feedback.error.not.find.start=\u0E44\u0E21\u0E48\u0E21\u0E35\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01\u0E01\u0E32\u0E23\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19\u0E07\u0E32\u0E19 pro.feedback.error.not.find.start=\u0E44\u0E21\u0E48\u0E21\u0E35\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01\u0E01\u0E32\u0E23\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19\u0E07\u0E32\u0E19
pro.feedback.error.canot.delete.last.process=\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E41\u0E01\u0E49\u0E44\u0E02\u0E2B\u0E23\u0E37\u0E2D\u0E25\u0E1A\u0E01\u0E23\u0E30\u0E1A\u0E27\u0E19\u0E01\u0E32\u0E23\u0E2A\u0E38\u0E14\u0E17\u0E49\u0E32\u0E22\u0E44\u0E14\u0E49 pro.feedback.error.canot.delete.last.process=\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E41\u0E01\u0E49\u0E44\u0E02\u0E2B\u0E23\u0E37\u0E2D\u0E25\u0E1A\u0E01\u0E23\u0E30\u0E1A\u0E27\u0E19\u0E01\u0E32\u0E23\u0E2A\u0E38\u0E14\u0E17\u0E49\u0E32\u0E22\u0E44\u0E14\u0E49
pro.feedback.error.error1=\u0E08\u0E4D\u0E32\u0E19\u0E27\u0E19\u0E17\u0E35\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E40\u0E1E\u0E34\u0E01\u0E16\u0E2D\u0E19\u0E44\u0E14\u0E49\u0E43\u0E19\u0E02\u0E31\u0E49\u0E19\u0E15\u0E2D\u0E19\u0E16\u0E31\u0E14\u0E44\u0E1B pro.feedback.error.error1=\u0E08\u0E4D\u0E32\u0E19\u0E27\u0E19\u0E17\u0E35\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E40\u0E1E\u0E34\u0E01\u0E16\u0E2D\u0E19\u0E44\u0E14\u0E49\u0E43\u0E19\u0E02\u0E31\u0E49\u0E19\u0E15\u0E2D\u0E19\u0E16\u0E31\u0E14\u0E44\u0E1B
......
...@@ -199,6 +199,7 @@ pro.feedback.error.serialNo.not.bind.workOrder=\u5E8F\u5217\u53F7\u4E0D\u5C5E\u6 ...@@ -199,6 +199,7 @@ pro.feedback.error.serialNo.not.bind.workOrder=\u5E8F\u5217\u53F7\u4E0D\u5C5E\u6
pro.feedback.error.min.quantity=\u62A5\u5DE5\u6570\u91CF\u4E0D\u80FD\u5C0F\u4E8E\u7B49\u4E8E0 pro.feedback.error.min.quantity=\u62A5\u5DE5\u6570\u91CF\u4E0D\u80FD\u5C0F\u4E8E\u7B49\u4E8E0
pro.feedback.error.quantity.lack=\u53EF\u62A5\u5DE5\u6570\u91CF\u4E0D\u8DB3 pro.feedback.error.quantity.lack=\u53EF\u62A5\u5DE5\u6570\u91CF\u4E0D\u8DB3
pro.feedback.error.before.start=\u8BF7\u5148\u8FDB\u884C\u5F00\u59CB\u4F5C\u4E1A\u64CD\u4F5C pro.feedback.error.before.start=\u8BF7\u5148\u8FDB\u884C\u5F00\u59CB\u4F5C\u4E1A\u64CD\u4F5C
pro.feedback.error.repeat.submit=\u62A5\u5DE5\u5904\u7406\u4E2D\uFF0C\u8BF7\u52FF\u91CD\u590D\u63D0\u4EA4
pro.feedback.error.not.find.start=\u6392\u4EA7\u4EFB\u52A1\u6CA1\u6709\u5F00\u5DE5\u8BB0\u5F55 pro.feedback.error.not.find.start=\u6392\u4EA7\u4EFB\u52A1\u6CA1\u6709\u5F00\u5DE5\u8BB0\u5F55
pro.feedback.error.cannot.delete.last.process=\u6700\u540E\u4E00\u9053\u5DE5\u5E8F\u62A5\u5DE5\u65E0\u6CD5\u4FEE\u6539\u6216\u8005\u5220\u9664 pro.feedback.error.cannot.delete.last.process=\u6700\u540E\u4E00\u9053\u5DE5\u5E8F\u62A5\u5DE5\u65E0\u6CD5\u4FEE\u6539\u6216\u8005\u5220\u9664
pro.feedback.error.error1=\u4E0B\u4E00\u9053\u5DE5\u5E8F\u53EF\u64A4\u56DE\u7684\u6570\u91CF\u4E0D\u591F pro.feedback.error.error1=\u4E0B\u4E00\u9053\u5DE5\u5E8F\u53EF\u64A4\u56DE\u7684\u6570\u91CF\u4E0D\u591F
......
...@@ -71,6 +71,11 @@ public class Constants { ...@@ -71,6 +71,11 @@ public class Constants {
*/ */
public static final String REPEAT_SUBMIT_KEY = "repeat_submit:"; public static final String REPEAT_SUBMIT_KEY = "repeat_submit:";
/**
* 生产报工分布式锁 redis key
*/
public static final String PRO_FEEDBACK_LOCK_KEY = "pro_feedback_lock:";
/** /**
* 限流 redis key * 限流 redis key
*/ */
......
...@@ -7,6 +7,7 @@ import cn.hutool.core.io.unit.DataUnit; ...@@ -7,6 +7,7 @@ import cn.hutool.core.io.unit.DataUnit;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ximai.common.annotation.Log; import com.ximai.common.annotation.Log;
import com.ximai.common.annotation.RepeatSubmit;
import com.ximai.common.core.controller.BaseController; import com.ximai.common.core.controller.BaseController;
import com.ximai.common.core.domain.AjaxResult; import com.ximai.common.core.domain.AjaxResult;
import com.ximai.common.core.page.TableDataInfo; import com.ximai.common.core.page.TableDataInfo;
...@@ -229,6 +230,7 @@ public class ProTaskMobController extends BaseController { ...@@ -229,6 +230,7 @@ public class ProTaskMobController extends BaseController {
@ApiOperation("生产报工") @ApiOperation("生产报工")
@Log(title = "生产报工", businessType = BusinessType.INSERT) @Log(title = "生产报工", businessType = BusinessType.INSERT)
@RepeatSubmit(interval = 5000)
@PostMapping("/feedback") @PostMapping("/feedback")
@ResponseBody @ResponseBody
public AjaxResult<List<ProPackagePrintResult>> feedBack(ProFeedback feedback) { public AjaxResult<List<ProPackagePrintResult>> feedBack(ProFeedback feedback) {
......
...@@ -4,7 +4,9 @@ import cn.hutool.core.bean.BeanUtil; ...@@ -4,7 +4,9 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.StopWatch; import cn.hutool.core.date.StopWatch;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ximai.common.constant.Constants;
import com.ximai.common.constant.UserConstants; import com.ximai.common.constant.UserConstants;
import com.ximai.common.core.redis.RedisCache;
import com.ximai.common.utils.MessageUtils; import com.ximai.common.utils.MessageUtils;
import com.ximai.common.utils.SecurityUtils; import com.ximai.common.utils.SecurityUtils;
import com.ximai.common.utils.data.DataUtil; import com.ximai.common.utils.data.DataUtil;
...@@ -72,12 +74,15 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -72,12 +74,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -143,6 +148,8 @@ public class ProTaskServiceImpl implements IProTaskService { ...@@ -143,6 +148,8 @@ public class ProTaskServiceImpl implements IProTaskService {
@Autowired @Autowired
private IProFeedbackService proFeedbackService; private IProFeedbackService proFeedbackService;
@Autowired @Autowired
private RedisCache redisCache;
@Autowired
private ProFeedbackMapper proFeedbackMapper; private ProFeedbackMapper proFeedbackMapper;
@Resource @Resource
private SysUserMapper sysUserMapper; private SysUserMapper sysUserMapper;
...@@ -783,6 +790,30 @@ public class ProTaskServiceImpl implements IProTaskService { ...@@ -783,6 +790,30 @@ public class ProTaskServiceImpl implements IProTaskService {
@Override @Override
@Transactional @Transactional
public List<ProPackagePrintResult> feedBack(ProFeedback feedback) { public List<ProPackagePrintResult> feedBack(ProFeedback feedback) {
ExceptionUtil.checkTrueThrowException(feedback.getTaskWorkunitId() == null,
MessageUtils.message("pro.feedback.error.before.start"));
String lockKey = Constants.PRO_FEEDBACK_LOCK_KEY + feedback.getTaskWorkunitId();
Boolean acquired = Boolean.TRUE.equals(
redisCache.redisTemplate.opsForValue().setIfAbsent(lockKey, "1", 30, TimeUnit.SECONDS));
ExceptionUtil.checkTrueThrowException(!acquired,
MessageUtils.message("pro.feedback.error.repeat.submit"));
if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCompletion(int status) {
redisCache.deleteObject(lockKey);
}
});
return doFeedBack(feedback);
}
try {
return doFeedBack(feedback);
} finally {
redisCache.deleteObject(lockKey);
}
}
private List<ProPackagePrintResult> doFeedBack(ProFeedback feedback) {
List<ProPackagePrintResult> response = new ArrayList<>(); List<ProPackagePrintResult> response = new ArrayList<>();
BigDecimal feedbackQualifyConst = feedback.getQuantityQualify(); BigDecimal feedbackQualifyConst = feedback.getQuantityQualify();
BigDecimal fuantityUnqualify = feedback.getQuantityUnqualify(); BigDecimal fuantityUnqualify = feedback.getQuantityUnqualify();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment