#
Junjie
2024-08-16 95d317016c4f865851fb327816f49a5329e8d098
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
38
39
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();
        if (currentValue > targetValue) {
            currentValue = startValue;
        }else {
            currentValue += 1;
        }
 
        circleRule.setCurrentValue(currentValue);
        this.updateById(circleRule);
        return currentValue;
    }
}