package com.by4cloud.platformx.device.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.by4cloud.platformx.common.data.mybatis.BaseModel; import com.by4cloud.platformx.common.security.service.PlatformxUser; import com.by4cloud.platformx.common.security.util.SecurityUtils; import com.by4cloud.platformx.device.entity.MaxSize; import com.by4cloud.platformx.device.mapper.JcMaxSizeMapper; import com.by4cloud.platformx.device.service.JcMaxSizeService; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.validation.constraints.Max; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Random; /** * 最大号表 * * @author kdq * @date 2025-03-25 16:24:34 */ @Service @AllArgsConstructor @Transactional public class JcMaxSizeServiceImpl extends ServiceImpl implements JcMaxSizeService { private final JcMaxSizeMapper maxSizeMapper; @Override public String nextNo(String type) { synchronized (this) { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); String format = sdf.format(new Date()); MaxSize maxSize = maxSizeMapper.selectOne(new QueryWrapper().lambda().eq(MaxSize::getSign, type).eq(MaxSize::getType,0)); if (maxSize == null) { return null; }else { MaxSize dayMax = maxSizeMapper.selectOne(new QueryWrapper().lambda() .eq(MaxSize::getSign, type) .eq(MaxSize::getDay,format)); Random random = new Random(); int randomNumber = random.nextInt(99); if(dayMax == null){ MaxSize maxSize1 = new MaxSize(); maxSize1.setSign(type); maxSize1.setDay(format); maxSize1.setType(1); int current = 1; String n = padStart(current, maxSize.getLength()); String pre = (maxSize.getUsePrefix() == 0 ? "" : maxSize.getPrefixName()); String suf = (maxSize.getUseSuffix() == 0 ? "" : maxSize.getSuffixName()); maxSize1.setCurrentNumber(current); save(maxSize1); String s = pre+format+suf+randomNumber+n; return s; }else { Integer currentNumber = dayMax.getCurrentNumber()==null?0:dayMax.getCurrentNumber(); int current = currentNumber+1; String n = padStart(current, maxSize.getLength()); String pre = (maxSize.getUsePrefix() == 0 ? "" : maxSize.getPrefixName()); String suf = (maxSize.getUseSuffix() == 0 ? "" : maxSize.getSuffixName()); dayMax.setCurrentNumber(current); updateById(dayMax); String s = pre+format+suf+randomNumber+n; return s; } } } } private String padStart(int num, int len) { String v = "000000000000000" + num; return v.substring(v.length() - len); } }