liusheng
2023-12-19 369d38887176f7737ebdf51d10c76dd2fbe8b5b7
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.ruoyi.project.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.domain.BaseOnlyvalue;
import com.ruoyi.project.mapper.BaseOnlyvalueMapper;
import com.ruoyi.project.service.IBaseOnlyvalueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.time.LocalDate;
import java.util.List;
 
/**
 * 业务数据唯一值Service业务层处理
 *
 * @author ruoyi
 * @date 2023-09-20
 */
@Service
public class BaseOnlyvalueServiceImpl extends ServiceImpl<BaseOnlyvalueMapper, BaseOnlyvalue> implements IBaseOnlyvalueService {
 
    @Autowired
    BaseOnlyvalueMapper baseOnlyvalueMapper;
 
    /**
     * 查询业务数据唯一值列表
     *
     * @param baseOnlyvalue 业务数据唯一值
     * @return 业务数据唯一值
     */
    @Override
    public List<BaseOnlyvalue> queryList(BaseOnlyvalue baseOnlyvalue) {
        LambdaQueryWrapper<BaseOnlyvalue> wrappers = Wrappers.lambdaQuery();
        if (StringUtils.isNotBlank(baseOnlyvalue.getBusinesstype())) {
            wrappers.eq(BaseOnlyvalue::getBusinesstype, baseOnlyvalue.getBusinesstype());
        }
        if (StringUtils.isNotBlank(baseOnlyvalue.getAppentvalue())) {
            wrappers.eq(BaseOnlyvalue::getAppentvalue, baseOnlyvalue.getAppentvalue());
        }
        if (baseOnlyvalue.getCurrentvalue() != null) {
            wrappers.eq(BaseOnlyvalue::getCurrentvalue, baseOnlyvalue.getCurrentvalue());
        }
        return this.list(wrappers);
    }
 
 
    @Override
    public BaseOnlyvalue getOnlyCode(String businessType, Boolean datequery) {
        LocalDate currentDate = LocalDate.now();
        int year = currentDate.getYear();
        int month = currentDate.getMonthValue();
 
        //通过年月日期去查询该月份是否存在
        String data = String.valueOf(year) + String.valueOf(month);
        BaseOnlyvalue baseOnlyvalue = new BaseOnlyvalue();
        if (datequery) {
            baseOnlyvalue.setAppentvalue(data);
        }
        baseOnlyvalue.setBusinesstype(businessType);
 
        List<BaseOnlyvalue> baseOnlyvalues = queryList(baseOnlyvalue);
        if (CollectionUtils.isEmpty(baseOnlyvalues)) {
            //如果为空的话,则往表中新增一条,将currentValue设置为1;
            //生成新的编号返回
            baseOnlyvalue.setCurrentvalue(1L);
            baseOnlyvalue.setBusinesstype(businessType);
            save(baseOnlyvalue);
 
            return baseOnlyvalue;
        } else {
            for (BaseOnlyvalue baseOnlyvalue1 : baseOnlyvalues) {
                if (datequery) {
                    //说明是需要将带日期的加1
                    if (!StringUtils.isEmpty(baseOnlyvalue1.getAppentvalue())) {
                        long newCurrentvalue = baseOnlyvalue1.getCurrentvalue() + 1;
                        baseOnlyvalue1.setCurrentvalue(newCurrentvalue);
                        updateById(baseOnlyvalue1);
                    } else {
                        continue;
                    }
                } else {
                    //说明是需要将不带日期的加1
                    if (StringUtils.isEmpty(baseOnlyvalue1.getAppentvalue())) {
                        long newCurrentvalue = baseOnlyvalue1.getCurrentvalue() + 1;
                        baseOnlyvalue1.setCurrentvalue(newCurrentvalue);
                        updateById(baseOnlyvalue1);
                    } else {
                        continue;
                    }
                }
                baseOnlyvalue = baseOnlyvalue1;
            }
 
            return baseOnlyvalue;
        }
 
    }
 
}