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 implements IBaseOnlyvalueService { @Autowired BaseOnlyvalueMapper baseOnlyvalueMapper; /** * 查询业务数据唯一值列表 * * @param baseOnlyvalue 业务数据唯一值 * @return 业务数据唯一值 */ @Override public List queryList(BaseOnlyvalue baseOnlyvalue) { LambdaQueryWrapper 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 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; } } }