liusheng
2023-11-01 6892c31200a7ed1b0e60ee5aff794b1fcecc7ef6
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
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.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 String getOnlyCode(String businessType) {
        LocalDate currentDate = LocalDate.now();
        int year = currentDate.getYear();
        int month = currentDate.getMonthValue();
 
        //通过年月日期去查询该月份是否存在
        String data = String.valueOf(year) + String.valueOf(month);
        BaseOnlyvalue baseOnlyvalue = new BaseOnlyvalue();
        baseOnlyvalue.setAppentvalue(data);
 
 
        List<BaseOnlyvalue> baseOnlyvalues = queryList(baseOnlyvalue);
        if (CollectionUtils.isEmpty(baseOnlyvalues)) {
            //如果为空的话,则往表中新增一条,将currentValue设置为1;
            //生成新的编号返回
            baseOnlyvalue.setCurrentvalue(1L);
            baseOnlyvalue.setBusinesstype(businessType);
            save(baseOnlyvalue);
 
            return "OPO-" + data + "1";
        } else {
            //则将currentValue+1,重新赋值
            BaseOnlyvalue baseOnlyvalue1 = baseOnlyvalues.get(0);
            long newCurrentvalue = baseOnlyvalue1.getCurrentvalue() + 1;
            baseOnlyvalue1.setCurrentvalue(newCurrentvalue);
            updateById(baseOnlyvalue1);
 
            return "OPO-" + data + "" + newCurrentvalue;
        }
 
    }
 
}