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