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; 
 | 
  
 | 
    } 
 | 
} 
 |