|
|
|
@ -6,7 +6,8 @@ import java.util.concurrent.locks.ReentrantLock; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.hxhq.common.core.utils.DateUtils; |
|
|
|
import com.hxhq.business.enums.SnTypeEnum; |
|
|
|
import com.hxhq.common.core.utils.DateUtils; |
|
|
|
import com.hxhq.common.core.utils.SpringUtils; |
|
|
|
import com.hxhq.common.core.utils.StringUtils; |
|
|
|
import com.hxhq.common.redis.service.RedisService; |
|
|
|
@ -32,25 +33,27 @@ public class SnGenServiceImpl extends ServiceImpl implements |
|
|
|
private final Lock lock = new ReentrantLock(true); |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getNewSn(Integer type, String my) { |
|
|
|
public String getNewSn(String pre, Integer type) { |
|
|
|
lock.lock(); |
|
|
|
try { |
|
|
|
Integer sort = 1; |
|
|
|
String date = StringUtils.isBlank(my)? DateUtils.dateTimeNow("yyMMdd"):my; |
|
|
|
String date = type.equals(SnTypeEnum.date.getValue())? DateUtils.dateTimeNow("yyMMdd"):""; |
|
|
|
QueryWrapper<SnGen> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.eq("pre",pre); |
|
|
|
queryWrapper.eq("date",date); |
|
|
|
queryWrapper.eq("type",type); |
|
|
|
if(count(queryWrapper)==0){ |
|
|
|
SnGen snGen = new SnGen(); |
|
|
|
snGen.setPre(pre); |
|
|
|
snGen.setDate(date); |
|
|
|
snGen.setSn(sort); |
|
|
|
snGen.setType(type); |
|
|
|
snGen.setSn(sort); |
|
|
|
save(snGen); |
|
|
|
}else{ |
|
|
|
baseMapper.addSn(date,type); |
|
|
|
baseMapper.addSn(pre,date,type); |
|
|
|
sort = getOne(queryWrapper,false).getSn(); |
|
|
|
} |
|
|
|
return (StringUtils.isBlank(my)?(date+"-"):"")+String.format("%03d", sort); |
|
|
|
return "-"+ (type.equals(SnTypeEnum.date.getValue())?(date+"-"):"")+String.format("%03d", sort); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("getNewSn执行被中断", e); |
|
|
|
} finally { |
|
|
|
@ -58,9 +61,4 @@ public class SnGenServiceImpl extends ServiceImpl implements |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getNewSn(Integer type) { |
|
|
|
return getNewSn(type,null); |
|
|
|
} |
|
|
|
} |