skyouc
2024-12-21 c635d78b479510ebe2556a420948effcd30a0731
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.zy.asrs.wms.asrs.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wms.asrs.mapper.CircleRuleMapper;
import com.zy.asrs.wms.asrs.entity.CircleRule;
import com.zy.asrs.wms.asrs.service.CircleRuleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
 
@Service("circleRuleService")
public class CircleRuleServiceImpl extends ServiceImpl<CircleRuleMapper, CircleRule> implements CircleRuleService {
 
    @Override
    public CircleRule getCircleRuleByFlag(String flag) {
        return this.getOne(new LambdaQueryWrapper<CircleRule>().eq(CircleRule::getFlag, flag));
    }
 
    @Override
    public Integer getCurrentValueByFlag(String flag) {
        CircleRule circleRule = this.getOne(new LambdaQueryWrapper<CircleRule>().eq(CircleRule::getFlag, flag));
        if(circleRule == null){
            throw new CoolException("循环策略不存在");
        }
 
        Integer currentValue = circleRule.getCurrentValue();
        Integer startValue = circleRule.getStartValue();
        Integer targetValue = circleRule.getTargetValue();
 
        circleRule.setCurrentValue(currentValue + 1);
        if (circleRule.getCurrentValue() > targetValue) {
            circleRule.setCurrentValue(startValue);
        }
        this.updateById(circleRule);
        return currentValue;
    }
}