liusheng
2023-11-10 6f344e6360751574f7e03b21c00cfa3f4b2bc099
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
package com.ruoyi.web.controller.common;
 
import com.ruoyi.common.exception.job.TaskException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.domain.BaseOnlyvalue;
import com.ruoyi.project.service.IBaseOnlyvalueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
 
import java.util.Calendar;
import java.util.List;
 
@Component
public class OnlyValueCommon {
    @Autowired
    private IBaseOnlyvalueService baseOnlyvalueService;
 
    public String addOnlyValue(String businessType) {
        String currentValue = null;
        switch (businessType) {
            case "zj":
                //专家
                currentValue = saveOrUpdateOnlyVal("zj", null);
                break;
 
            case "donationwitness":
                //捐献
                currentValue = saveOrUpdateOnlyVal("donationwitness", String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
                break;
 
            case "organization":
                //机构
                currentValue = saveOrUpdateOnlyVal(" organization", null);
                break;
 
            default:
                break;
        }
 
        return currentValue;
    }
 
 
    private String saveOrUpdateOnlyVal(String businesstype, String year) {
        String currentValue = null;
        //判断该年份的数据是否存在
        BaseOnlyvalue baseOnlyvalue = new BaseOnlyvalue();
        //捐献。需要带年份查询
        if (!StringUtils.isEmpty(year)) {
            baseOnlyvalue.setAppentvalue(year);
        }
        baseOnlyvalue.setBusinesstype(businesstype);
        List<BaseOnlyvalue> baseOnlyvalues = baseOnlyvalueService.queryList(baseOnlyvalue);
        if (!CollectionUtils.isEmpty(baseOnlyvalues)) {
            //说明已经存在,则给currentValue加1即可
            BaseOnlyvalue baseOnlyvalue1 = baseOnlyvalues.get(0);
            baseOnlyvalue1.setCurrentvalue(baseOnlyvalue1.getCurrentvalue() + 1);
            currentValue = String.valueOf(baseOnlyvalue1.getCurrentvalue() + 1);
            baseOnlyvalueService.updateById(baseOnlyvalue1);
        } else {
            //不存在,则需要创建
            baseOnlyvalue.setCurrentvalue(1L);
            baseOnlyvalue.setBusinesstype(businesstype);
            baseOnlyvalue.setAppentvalue(year);
            baseOnlyvalueService.save(baseOnlyvalue);
            currentValue = "1";
        }
        return currentValue;
 
    }
}