sinake
2 天以前 4adfb9ed01bd7a006e83704e61fbf0f00dd74277
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.text.SimpleDateFormat;
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;
        }
 
    }
 
    /**
     * 获取序列号
     *
     * @param businessType
     * @return
     */
    @Override
    public String getSequence(String businessType, String orgId) {
        LocalDate currentDate = LocalDate.now();
        int year = currentDate.getYear();
        String month = currentDate.getMonthValue()+"";
        if(month.length()==1)
            month="0"+month;
        if(ObjectUtils.isEmpty(orgId)){
            orgId="";
        }
        //通过年月日期去查询该月份是否存在
        String data =year + month+orgId;
        BaseOnlyvalue baseOnlyvalue = new BaseOnlyvalue();
        baseOnlyvalue.setBusinesstype(businessType);
 
        List<BaseOnlyvalue> baseOnlyvalues = queryList(baseOnlyvalue);
        if(baseOnlyvalues.size()==0){
            baseOnlyvalue.setAppentvalue(businessType);
            baseOnlyvalue.setCurrentvalue(1L);
            baseOnlyvalue.setBusinesstype(businessType);
            save(baseOnlyvalue);
        }else {
            baseOnlyvalue= baseOnlyvalues.get(0);
            baseOnlyvalue.setCurrentvalue(baseOnlyvalue.getCurrentvalue()+1);
            updateById(baseOnlyvalue);
        }
        return baseOnlyvalue.getAppentvalue() + data + baseOnlyvalue.getCurrentvalue();
    }
 
}